I have my garage door mostly working in HA (thanks to many helpful people!). Getting there has shown me that I don’t yet really understand how a template is “triggered” when it has no triggers and I’d like to understand that better. My apologies in advance if there’s a topic out there that addresses this but I couldn’t find it.
Here’s the entire contents of my templates_garage.yaml file. Everything before the first “else” seems to be working fine. Following that is a block of commented out code showing things that didn’t work.
- cover:
- name: GarageDoor
unique_id: garage_door
device_class: garage
state: >
{% set garage_door_is_open = is_state( 'binary_sensor.garage_door_control_is_open', 'on') %}
{% set garage_door_is_closed = is_state( 'binary_sensor.garage_door_control_is_closed', 'on') %}
{% if garage_door_is_open and not garage_door_is_closed %}
open
{% elif not garage_door_is_open and garage_door_is_closed %}
closed
{% elif garage_door_is_open and garage_door_is_closed %}
sensor error
{% else %}
{# {{ this }} logs seem to show that "this" bounces between "open" and "unknown" #}
{# {{ this.state }} logs seem to show that "this.state" is always "opening" #}
{# from the logs, "garage_door" is undefined #}
{# garage_door.state #}
{# from the logs, "cover" is undefined #}
{# cover.garage_door #}
{# cover.garage_door.state #}
{# cover.garagedoor #} {# the error logs sure do think this is a valid entity because that's what they use for error messages #}
{# cover.garagedoor.state #}
{# garagedoor from the logs, "garagedoor" is undefined in a slightly different way #}
{# {% if ( this.state == 'open' ) %} {# 1 says opening when it's actually closing #}
{# {% if ( this.state == "open" ) %} {# 2 says opening when it's actually closing #}
{# {% if this.state == "open" %} {# 3 says opening when it's actually closing #}
{# {% if ( garagedoor == 'open' ) %} {# 4 says opening when it's actually closing #}
{# {% if ( garagedoor.state == 'open' ) %} {# 5 says unavailable when closing - I'm guessing this is a coding error #}
{# {% if ( garage_door == 'open' ) %} {# 6 says opening when it's actually closing #}
{# {% if ( cover.garagedoor == 'open' ) %} {# 7 says unavailable when it's actually closing #}
{# {% if is_state( 'this.state', 'open' ) %} {# 8 says opening when it's actually closing #}
{# {% if is_state( this.state, 'open' ) %} {# 9 says opening when it's actually closing #}
{# {% if is_state( 'cover.garagedoor', 'open' ) %} {# 10 this flashes to closing and then reverts to opening #}
{# {% if is_state( 'this.state', 'open' ) or is_state( 'this.state', 'closing' ) %} {# 11 says opening when it's actually closing #}
{% if is_state( 'cover.garagedoor', 'open' ) or is_state( 'cover.garagedoor', 'closing' ) %} {# 12 this works #}
closing
{% else %}
opening
{% endif %}
{% endif %}
open_cover:
action: switch.turn_on
target:
entity_id: switch.plusunigarage_output_0
close_cover:
action: switch.turn_on
target:
entity_id: switch.plusunigarage_output_0
stop_cover:
action: switch.turn_on
target:
entity_id: switch.plusunigarage_output_0
My first question comes from the line with 10 in the comment. With this line active, the template evaluates to “closing” and then immediately changes to “opening”. I think this means the template is firing again immediately after changing to “closing”. My guess is that the template is firing again based on the fact that “cover.garagedoor” is referenced in the state: block. Can someone tell me if that’s correct?
Second question comes from the line with 11 in the comment. I expected this line to do exactly the same thing that the line 12 did but it doesn’t. What am I missing?