Improving a Motion-Detecting Light with Shelly & Home Assistant

Cyan Automation
3 min readAug 2, 2020
Photo by Emre Karataş on Unsplash

I have an outdoor (IP44) motion-sensing Dome Light that recently rolled over and died. Turns out that an internal module broke (the one that detects motion) and without this, the light could only be permanently on or switched, neither being ideal. After getting a replacement Motion Sensor Module from Amazon, it was a great opportunity to improve the light and make it smart.

Note: my particular light was designed to work with a microwave radar module, but this works almost exactly the same as a standard PIR sensor

Getting Started

My aim was to insert a Shelly 1 between the motion sensor’s Switched Line Output and the LED driver. To do this, wire the Switched Line into the SWITCH input of the Shelly, where the rest of the inputs as you would expect, and the Shelly OUTPUT connects into the LED driver input.

LED Driver (L), Motion-Detection Module (Center), and Shelly 1 (R); the LED module has been removed to gain access to the wiring.

Next is time to define the Shelly switch in Home Assistant; follow this guide to set it up. Importantly, we need to make a key change in the configuration on the local Shelly device – changing the Button Type to Detached. Otherwise, the motion sensor will be directly switching the LED Light, without any additional smarts.

A Detached switch means the Switch input is disconnected from the operation of the relay, allowing for the input to be processed prior action on the local Shelly, or a different device

Making It Work

Now we can control the light but we aren’t able to know if the PIR/Radar module has detected motion, which is important. To achieve this, we have to code an additional MQTT sensor to track this state. Remember that available MQTT topics can be found at the Shelly API reference site.

To achieve this, we just need to follow the MQTT formatting and track the right topic, as mentioned above. This is what it looks in YAML:

Next up is making a useful automation to act on this new sensor, and turn on the light, wait 5 minutes (delay), then turn_off. The trigger here will be the change in state for our motion sensor. Here is the code in YAML:

The challenge here is that unless you’ve tweaked the PIR/Radar module’s lux threshold, any motion will activate the light throughout the day and night. To further improve this, I’d suggest adding a Condition in Home Assistant to only activate the automation after sunset or when the sun is below the horizon.

Now you have a Smart Motion-Sensing Light, and this is how it looks in Home Assistant:

--

--

Cyan Automation

Marc’s tips on building your Smart Home with Home Assistant, Shelly and ESPHome.