Hello!
I try to use ESP12, which is installed on the nodemsu board, with tasmota firmware.
Task - when the HC-SR501 motion (PIR) sensor is triggered, turn on the relay (set pin GPIO16 or another). When moving again, turn it off. I needed the relay to be controlled in 2 ways:
- switching the PIR sensor led to the switching of the relay and a message was sent to the MQTT. This should work in the absence of a wifi network. It is clear that the message actually will not be sent, but the device will be able to work independently
- By command on MQTT
In the module configuration section, I set the module type generic (18) and configured port:
D7 gpio13 - switch1 (9) (this port connect output PIR sensor)
D0 GPIO16 - relay 1i (29) (this port connect relay) Instead of a relay, I have a LED and a resistor connected in series (for test).
Further in the section “console” I executed the following commands:
SwitchMode1 1
SwitchTopic 0
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
As a result, I see:
- When the sensor is triggered, the LED (relay) turns on. The message “stat / nodemcu / PIR1 ON” appears in the MQTT broker
- after the sensor response time(~2.5minutes), the LED (relay)turns off.The message “stat / nodemcu / PIR1 OFF” appears in the MQTT broker
At Home assistant, I see that the relay switches change their state.
But after a few (2-3) seconds, in the absence of movement, the relay switches on again and the cycle repeats.
Help:
-In MQTT integration, my device is displayed as a relay, but the PIR sensor is not displayed. I tried to connect a temperature sensor instead of the PIR sensor (making the appropriate module settings), then the temperature sensor is displayed for the device. Is it possible to integrate PIR into a home assistant as a motion sensor.
- set up the rules for ESP12 for work my task correctly.