Some template help, please

What have I got wrong below?

I’ve been testing it in Dev Tools and the state( sensor.garage_door_emporia > 100) part is, I think, incorrectly formatted and I can’t figure how to correct it.

{% if is_state('binary_sensor.garage_door_open_sensor_contact', 'on') and 
is_state('binary_sensor.garage_door_closed_sensor_contact', 'on') and state(
sensor.garage_door_emporia > 100) and is_state('input_boolean.garage_door_state', 'on') %}
        Opening
{% elif is_state('binary_sensor.garage_door_open_sensor_contact', 'on') and 
is_state('binary_sensor.garage_door_closed_sensor_contact', 'on') and state(
sensor.garage_door_emporia > 100) and is_state('input_boolean.garage_door_state', 'off') %}
        Closing
{% elif is_state('binary_sensor.garage_door_open_sensor_contact', 'off') and 
is_state('binary_sensor.garage_door_closed_sensor_contact', 'off') %}
        Sensor fault
{% elif is_state('binary_sensor.garage_door_open_sensor_contact', 'on') and 
is_state('binary_sensor.garage_door_closed_sensor_contact', 'off') %}
        Closed
{% elif is_state('binary_sensor.garage_door_open_sensor_contact', 'off') and 
is_state('binary_sensor.garage_door_closed_sensor_contact', 'on') %}
        Open
{% elif is_state('binary_sensor.garage_door_open_sensor_contact', 'on') and 
is_state('binary_sensor.garage_door_closed_sensor_contact', 'on') %}
        Stuck
{% else %}
        Error
{% endif %}

states(‘sensor.garage_door_emporia’) | float > 100

Thank you, but that still generated an error.

Removing the quotes fixed that.

How often should it refresh/update?
Does it need a trigger to do this?

As soon as states(sensor.garage_door_emporia | float > 100) becomes true the sensor becomes unavailable.

Once states(sensor.garage_door_emporia | float > 100) is false, the sensor is available again.

I now have:

- sensor:
    - name: "Garage door"
      state: >
        {% if is_state('binary_sensor.garage_door_open_sensor_contact', 'on') and 
        is_state('binary_sensor.garage_door_closed_sensor_contact', 'on') and states(sensor.garage_door_emporia | float > 100) and is_state('input_boolean.garage_door_state', 'on') %}
                Opening
        {% elif is_state('binary_sensor.garage_door_open_sensor_contact', 'on') and 
        is_state('binary_sensor.garage_door_closed_sensor_contact', 'on') and states(sensor.garage_door_emporia | float > 100) and is_state('input_boolean.garage_door_state', 'off') %}
                Closing
        {% elif is_state('binary_sensor.garage_door_open_sensor_contact', 'off') and 
        is_state('binary_sensor.garage_door_closed_sensor_contact', 'off') %}
                Sensor fault
        {% elif is_state('binary_sensor.garage_door_open_sensor_contact', 'on') and 
        is_state('binary_sensor.garage_door_closed_sensor_contact', 'off') %}
                Closed
        {% elif is_state('binary_sensor.garage_door_open_sensor_contact', 'off') and 
        is_state('binary_sensor.garage_door_closed_sensor_contact', 'on') %}
                Open
        {% elif is_state('binary_sensor.garage_door_open_sensor_contact', 'on') and 
        is_state('binary_sensor.garage_door_closed_sensor_contact', 'on') %}
                Stuck
        {% else %}
                Error
        {% endif %}

No. The example above is correct. Check the position of the ). You have to quote and put the () at the right places.

And you should use a default for float.

help yourself by using variables so you don’t have to guess where the syntax errors are.

- sensor:
    - name: "Garage door"
      state: >
        {% set open_on = is_state('binary_sensor.garage_door_open_sensor_contact', 'on') %}
        {% set open_off = is_state('binary_sensor.garage_door_open_sensor_contact', 'off') %}
        {% set closed_on = is_state('binary_sensor.garage_door_closed_sensor_contact', 'on') %}
        {% set closed_off = is_state('binary_sensor.garage_door_closed_sensor_contact', 'off') %}
        {% set powered = states('sensor.garage_door_emporia') | float(0) > 100 %}
        {% set opening = is_state('input_boolean.garage_door_state', 'on') %}
        {% set closing = is_state('input_boolean.garage_door_state', 'off') %}

        {% if open_on and closed_on %}
          Stuck
        {% elif open_off and closed_off %}
          Sensor Fault
        {% elif open_on and closed_off %}
           {{ iif(powered and opening, 'Opening', 'Open') }}
        {% elif open_off and closed_on %}
           {{ iif(powered and closing, 'Closing', 'Closed') }}
        {% else %}
          Error
        {% endif %}

That looks like a work of genius! Thank you.

However, in template checker I get UndefinedError: 'is_states' is undefined.

To aid my understanding, how is iif different to if?

change those to is_state, typo

or just copy what I wrote again. Updated it.

Direct link to iif infos.

OK, thanks.

Now I get TypeError: AllStates.__call__() takes 2 positional arguments but 3 were given

^^^

1 Like

Thank you so much.

Some of my operational logic is not quite correct but I can sort that.

Your help has been invaluable. I appreciate your time.