Hi everyone, I’m really new here, but I’ve tried a few days ago to solve a simple problem but I did not find anything in the forums.
I have a binary sensor that only sends one single signal, I connected it to a slide door in a way that when opening and closing the same signal is sent via mqtt.
How can I create an automation so that I can toggle the On and Off to each opening and closing using the same signal sent.
Well, you can get out of sync if home assistant restarts and the door is open. But make an input boolean to store the state, then make an automation that toggles the state when the sensor is triggered. Then you can make a binary_sensor template that says open/close as a sensor.
input_boolean:
slide_door:
name: Slide door status
initial: off
- alias: toggle door
trigger:
- platform: state
entity_id: binary_sensor.xxxxx
to: 'on'
action:
- service: input_boolean.toggle
entity_id: input_boolean.slide_door
binary_sensor:
- platform: template
sensors:
sliding_door:
friendly_name: Sliding Door
device_class: door
value_template: "{{ is_state('input_boolean.slide_door','on') }}"
thank you for the clarity and quality of the proposed solution. Worked perfectly
I would like to make only one complement, in the sensor declaration it is important that the force_update parameter be enabled, without this the automation will only work once.
To get different state topics for each sensor I use rules on tasmota.
An example of a Rule of this kind in tasmota:
Rule1 ON RfReceived#Data=107C56 DO publish Rfsensor/Puerta_entrada ENDON ON RfReceived#Data=1420C6 DO publish Rfsensor/Sensor_prueba ENDON
Keep in mind Tasmota can only use 3 Rules sets.
Each rule set can contain up to 511 characters so depending on the legth of the state topic you would like to publish, can fit up to 9-10 sensors per rule set.
I was facing the same issue, having a single signal rf sensor, which is supposed to toggle an on/off state. This was my first Jinja template and the hardest part for me was converting the single line example into a multiline template. I kept getting the TemplateSyntaxError: unexpected char ‘\\’ until I finally escaped my troubles by removing the backslashes from the scalar. It took me quite some time to figure it out, but I’ve learned something and I’m happy with my template, so it was worth it and since you guys inspired all of this, I wanted to leave a big thank you here and share my newly acquired wisdom and happiness. I hope you’ll find it useful as well.
To safe yourself some trouble make sure to replace rf-bridge with your device’s topic and xxxxx with your sensor’s data.
I’m not sure if all the hyphens are required or helpful, that’s something I’ll probably figure out when I’ve worked a bit more with Jinja or YAML, but since the example led with it I figured I’d stick to it.
The template seemed to be working fine without the {%-else-%} get_state(entity_id), but I felt bad for letting it hang without any return value. So, as far as I’m concerned, it’s only there for good manners and style, but I’m not sure if it does any good or harm.