OK everyone who’s been asking. The settings for getting it to talk to HASS are as follows. My PIR sensor is connected to GPIO3, so under the GPIO3 dropdown menu I have selected option 12 which is “Switch 4”. Once you have saved your settings there you must go to the “Console” page from the main menu. Bow that our PIR sensor is considered “Switch 4” we want to set it to Switch Mode 1.
Below is how the Tasmota Firmware Wiki reads:
SwitchMode<x> - 1 - Set switch mode to FOLLOW (0 = Off, 1 = On)
So where <x> is the number of the switch we picked, we type into the console. “SwitchMode4 1” and hit enter. It will respond with something like this this.
23:21:44 MQTT: stat/sonoff7/RESULT = {“SwitchMode4”:1}
So, now when your PIR sensor turns on the Tasmota firmware will send out an MQTT message with the payload “ON”, when it turns off it will send out a message with the payload “OFF” as seen below
23:33:14 MQTT: cmnd/sonoff7/POWER4 = ON
23:33:16 MQTT: cmnd/sonoff7/POWER4 = OFF
The MQTT topic reads: cmnd/(your device name)/POWER(the switch number you picked)
Now, if you add the code below to your config file, you’ll have a binary sensor that tells you when it detects motion.
sensor:
- platform: mqtt
state_topic: "cmnd/sonoff7/POWER4"
name: "Bedroom Motion Detector"
qos: 0
payload_on: "ON"
payload_off: "OFF"
This is a simple dumb sensor, there is absolutely no delay, once the sensor stops detecting motion it sends the OFF command. If motion starts again 10 seconds later it will send the ON command again. If you want to add a delay for something like a light automation you’ll need to add an automation and an input boolean.
input_boolean:
motion_detected:
name: Motion Detected
initial: off
And the automation is below:
- alias: Motion Detected in Bedroom
trigger:
- platform: state
entity_id: binary_sensor.bedroom_motion_detector
to: 'on'
- platform: state
entity_id: binary_sensor.bedroom_motion_detector
to: 'off'
for:
minutes: 5
seconds: 00
action:
service_template: >
{% if trigger.to_state.state == "on" %}
homeassistant.turn_on
{% elif trigger.to_state.state == "off" %}
homeassistant.turn_off
{% endif %}
entity_id: input_boolean.motion_detected
The time you see above “minutes: 5” that’s the number of minutes it must go without motion in order to switch off the input boolean. And you would use that device “input_boolean.motion_detected” to trigger your automation on or off, changing that time to whatever delay you want.
Here is what my modified Sonoff S20 looks like. I have a small PIR and a DHT22 temp/humidity sensor in there. The PIR is off center because that’s where it would fit, same with the DHT22.