Skip to content

Instantly share code, notes, and snippets.

@xbmcnut
Last active June 26, 2025 03:37
Show Gist options
  • Save xbmcnut/6d239de9523246d7a831ca55be6564c2 to your computer and use it in GitHub Desktop.
Save xbmcnut/6d239de9523246d7a831ca55be6564c2 to your computer and use it in GitHub Desktop.
Making an outdoor motion sensor smart using a Shelly 1
/**
* I figured out you can fit a Shelly 1 inside the case of many outdoor motion sensors.
* Coupled with that fact that recently, Shelly added a feature to de-couple the switch from the relay
* so they act independently, makes this a great combo! Simply wire the output of the PIR motion sensor
* (the wire that normally goes to your outdoor light) to the switch input of the Shelly and wire
* the lightbulb to the L output of the Shelly. Then, in the Shelly app or directly via the devices webpage,
* select the button type as 'Detached Switch' and use the code below to make it work normally.
* Don't forget to adjust the daylight sensitivity to full daylight if you want the motion detection to work 24/7.
*/
#### AUTOMATIONS ####
automation:
- alias: Shelly PIR Auto
# initial_state: true
# hide_entity: true
trigger:
- platform: state
entity_id: sensor.pir_motion_sensor_status
condition:
condition: or
conditions:
- condition: sun
before: sunrise
- condition: sun
after: sunset
action:
- service_template: "{% if is_state('sensor.pir_motion_sensor_status' , '1')
%} light.turn_on {% else %}
light.turn_off {% endif %}"
entity_id: light.pir_motion_sensor
light:
- platform: mqtt
name: "PIR Motion Sensor"
state_topic: "shellies/shelly1-0x0x0x/relay/0"
command_topic: "shellies/shelly1-0x0x0x/relay/0/command"
availability_topic: shellies/shelly1-0x0x0x/online
payload_available: "true"
payload_not_available: "false"
qos: 2
payload_on: "on"
payload_off: "off"
retain: false
optimistic: false
## SENSORS ##
sensor:
#### Status of Shelly switch input for PIR ###
- platform: mqtt
name: "PIR Motion Sensor Status"
state_topic: "shellies/shelly1-0x0x0x/input/0"
@xbmcnut
Copy link
Author

xbmcnut commented Jun 26, 2025

UPDATE 6/2025

Thought I'd do some testing with the newer Gen3 Shelly mini with this cheap PIR motion sensor from Mitre10. Seems to work flawlessly with the switch input on the Shelly dropping to 0.1vac when the motion sensor is off. Added bonus is the the Shelly mini devices are half the size of the Gen1 Shelly I was using so much easier to fit inside the base of the motion sensor.

Note that the original MQTT code above is no longer required if you use the HA native Shelly integration (recommended)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment