I have a motor gate with a Sonoff RF door sensor and a magnetic contact that I am trying to get working. I currently have MQTT messages from the RF sensor to home assistant via an RF Bridge working fine. When the gate opens the home assistant binary sensor is turned on and remains on until I restart hassio again.
What I want is for the MQTT message to toggle the state of the sensor. Currently my yaml file looks like this but it was wishful thinking to think that the same payload would toggle the switch
I have been reading up on the MQTT sensors and I see that there is an “IF” option that could be added to the value template field. Is there a way of combining this with my current config to cause a toggle action on the sensor when an on payload is received?
I followed the instructions for strategy 1 and played around with the value_template to get to the following result that is working swimmingly for me. When the gate opens, the sensor state is changed to on and when the gate closes it toggles to off. I will look at strategy 2 in the future as that seems interesting as well.