Automation to work despite unavailable state

I want my automation to fire even if one of the entities (the list is longer) is not available. Is that indeed the way to do it?

condition:
  - condition: and
    conditions:
    - condition: or
      conditions:
        - condition: numeric_state
          entity_id: number.office_radiator_valve_position
          below: 15
        - condition: state
          entity_id: number.office_radiator_valve_position
          state: 'unavailable'
    - condition: or
      conditions:
        - condition: numeric_state
          entity_id: number.parents_heater_valve_position
          below: 15
        - condition: state
          entity_id: number.parents_heater_valve_position
          state: 'unavailable'
    ...

I am not confident to try a template just yet.

Looks right to me, two AND statements evaluating OR statements.

1 Like

It’s simpler with Template Conditions.

condition:
  - condition: template
    value_template: "{{ states('number.office_radiator_valve_position') | float(0) < 15 }}"
  - condition: template
    value_template: "{{ states('number.parents_heater_valve_position') | float(0) < 15 }}"
    ...

Even simpler if you use shorthand notation.

condition:
  - "{{ states('number.office_radiator_valve_position') | float(0) < 15 }}"
  - "{{ states('number.parents_heater_valve_position') | float(0) < 15 }}"
    ...

If the entity’s state value is unavailable, the float(0) filter will report 0. Given that 0 is less than 15, the template will report true. In other words, the condition passes if the state value is unavailable or a numeric value less than 15.

2 Likes

Yes, I didn’t dare to go into templating land. Thanks for the hint! It will be much more readable that way.

1 Like

Thank you for the tip, my automation looks much better now.

For a trigger, I understand that I can transform the first one below into the second one, correct? There is no shorthand notation here, right?

trigger:
  - platform: numeric_state
    entity_id:
      - number.office_radiator_valve_position
    above: 15
  - platform: template
    value_template: "{{ states('number.office_radiator_valve_position') | float(0) > 15 }}"

Template Condition supports ahorthand notation.