Help connect the PIR sensor to Home assistant.
There is esp12 with tasmota firmware.
The PIR sensor is connected to the esp12 pin, in the tasmota settings it is defined as a “switch”. A relay is connected to the other esp12 pin (in the tasmota defined as “relay1”).
In esp12, the rule is configured - when the PIR sensor is triggered, turn on the relay, turn off when the movement ends.
Rule1
on Switch1#state=1 do BackLog Power1 1; publish stat/%topic%/PIR1 ON endon
on Switch1#state=0 do BackLog Power1 0; Publish stat/%topic%/PIR1 OFF endon
Rule1 1
The Home assistant relay was found, displayed as switch.nodemcu_relay1, and controlled from the lovelace card.
I wanted to see the Home assistant state of the PIR sensor. I added in the configuration.yaml sensor:
The sensor appeared in the Home assistant, but its state is unavailable
What other settings need to be made so that this PIR sensor becomes active and can be used in automation?
No. That doesn’t work either.
I connected the mqtt client from the computer and I see that messages in the topic about sensor operation are coming.
And for some reason, Home Assistant doesn’t understand them.
PIR sensors can trigger repetitively in a short period of time. It might be worth setting up an R-C circuit to keep relay going for set amount of time (capacitor decay) to prevent cycling power on the relay and other sensors. simple 47uH and 500kO provides about 20 seconds before 3.3 voltage drops to 0.6V and transistor gate closes.
For the ‘unavailable’ issue…
Looks like the binary_sensor is expiring causing it to change to unavailable. I believe this is caused because the ESP32 is disconnecting from the MQTT server, making HA not know what is going on… T
I think you have a couple options here…
Consider using retain - set that to true. This will make HA keep the last payload received. Therefore, even if the ESP32 disconnects the last message received maintains its status.
Other options, try adding: off_delay: 60 (this will make HA in the device class: motion change from: “detected motion” - to -> “cleared (no motion detected)”
Or expire_after, but that might start causing ‘unknown’.