need some help getting a cover template working.
I have an athom tech garage door opener with the reed switch configured at the open end of the door. I have a reed switch for when the door is closed connected through my Konnected alarm panel.
I want to combine these two sensors to have a Garage door state Closed, Open, Opening/Closing. I have the code I am using in my binary sensor template configured through the front end below. The state remains as “Closed” even when the sensor states dictate an “open” state. Any thoughts?
{% if is_state('binary_sensor.athom_garage_door_01063c_contact', 'off') and is_state('binary_sensor.konnected_b8334c_zone_3', 'off') %}
Closed
{% elif is_state('binary_sensor.athom_garage_door_01063c_contact', 'on') and is_state('binary_sensor.konnected_b8334c_zone_3', 'on') %}
Open
{% else %}
Opening / Closing
{% endif %}
{% if is_state('binary_sensor.athom_garage_door_01063c_contact', 'off') and is_state('binary_sensor.konnected_b8334c_zone_3', 'off') %}
closed
{% elif is_state('binary_sensor.athom_garage_door_01063c_contact', 'on') and is_state('binary_sensor.konnected_b8334c_zone_3', 'on') %}
open
{% else %}
opening
{% endif %}
Unfortunately you will have to choose between “opening” or “closing” for that last state. You can’t have both - unless you can also detect the direction the door is moving (possibly by checking which binary sensor changed last).
I don’t think the last changed would work, as if you stop it half way and hit the relay again it reverses direction.
Thanks for the help but it still isn’t working. I tried creating a sensor rather than a binary sensor (maybe because theres more than one option?) and It seemed to work. As I haven’t got the alarm reed switch set up so its currently open.
Note that with a trigger-based template, the various properties of the entity (icon, attributes, etc.) are evaluated only when a trigger fires. And, counter-intuitively, at that split second when the icon is being computed, is_state might not get the state to which your entity is about to change to; you might be accessing a stale state, namely the one you’re about to change away from. Often this manifests itself with a “lag” where the icon after the state update is what it should have been before the state update.
In my template entities, I deal with this by avoiding is_state, states, and other current state references in the sensor definition code and instead reference the same state code I use for the entity’s state definition. If that makes sense…