(Yet another) ignore previous "unavailable" state

Hmm. Maybe because you are looking at an attribute of the sensor, not the state.

Try this:

condition:
  - "{{ trigger.from_state.attributes.your_attribute_here not in ['unknown', 'unavailable'] }}"
  - "{{ trigger.to_state.attributes.your_attribute_here not in ['unknown', 'unavailable'] }}"
  - "{{ trigger.to_state.attributes.your_attribute_here != trigger.from_state.attributes.your_attribute_here }}"
1 Like

/host/info: agent_version is an endpoint - docs

You could compare the actual sensor to the github sensor.

Hmm, that could be it. You mean triger.from_state obviously.

I mean both. You don’t want it triggering when it goes from or to unavailable. I updated my post.

Sharing your actual trigger would help too.

Yup. That’s the answer. So trigger.from_state.state goes for the whole entity, but trigger.from_state.attributes.your_attribute_here is for a single attribute?
Where is trigger.from_state.attributes.your_attribute_here actually documented? I can’t find it here Automation Trigger Variables - Home Assistant

I cover going to unavailable with another simple “state not unavailable” condition.

1 Like

Yes.

A combination of here: https://www.home-assistant.io/docs/automation/templating/#numeric-state and here: https://www.home-assistant.io/docs/configuration/state_object/

Ok, great I’d missed the second one. Thanks a lot!

I know this must be documented somewhere but final question: Is there a proper way (syntax wise) to add both “unavailable” and “unknown” in a single value template condition (in visual editor)? Or 2 conditions must necessarily be created?
I tried putting:

- "{{ trigger.from_state.attributes.your_attribute_here not in ['unknown', 'unavailable'] }}"
- "{{ trigger.to_state.attributes.your_attribute_here not in ['unknown', 'unavailable'] }}"

in a single condition and the automation is always stopped (but without an error, just stopped).

Each one of those is a full template condition. It is just written in shorthand:

https://www.home-assistant.io/docs/scripts/conditions/#template-condition-shorthand-notation

I’m trying just
{{ trigger.from_state.attributes.tag != "unavailable", "unknown" }}
within visual editor but it does not work.
My syntax is wrong.
I’m trying to have just a single condition instead of 2 (for educational purposes :grinning: )

:man_shrugging: Dunno. I don’t use the automation editor. What does it generate in the yaml view?

condition: template
value_template: "{{ trigger.from_state.attributes.tag != \"unavailable\", \"unknown\" }}"

Seems definitely wrong :grinning:

condition: template
value_template: |-
  - {{ trigger.from_state.attributes.tag != "unavailable" }}
  - {{ trigger.from_state.attributes.tag != "unknown" }}

in yaml does not work either. I feel an “and” or “or” has to be placed somewhere.

Not like that. Like this:

condition:
  - {{ trigger.from_state.attributes.tag != "unavailable" }}
  - {{ trigger.from_state.attributes.tag != "unknown" }}

Or like this:

condition:
  - condition: template
    value_template: "{{ trigger.from_state.attributes.tag != 'unavailable' }}"
  - condition: template
    value_template: "{{ trigger.from_state.attributes.tag != 'unknown' }}"

Or like this:

condition:
  - {{ trigger.from_state.attributes.tag != "unavailable" and trigger.from_state.attributes.tag != "unknown"  }}
1 Like

Ok, how can this you posted:

condition:
  - {{ trigger.from_state.attributes.tag != "unavailable" }}
  - {{ trigger.from_state.attributes.tag != "unknown" }}

be written in a single line? Using for example an “and” expression?

I just edited my post.

Ok, let me try the single line. I felt something like {{ trigger.from_state.attributes.tag != "unavailable", "unknown" }} could bu valid.

Ok just putting
{{ trigger.from_state.attributes.tag != "unavailable" and trigger.from_state.attributes.tag != "unknown" }}
in the visual editor resolves in

condition: template
value_template: >-
  {{ trigger.from_state.attributes.tag != "unavailable" and
  trigger.from_state.attributes.tag != "unknown"  }}

in yaml and seems to work.
So a single condition can be used that way.
Thanks a lot!

1 Like

And just in case someone is interested, the full yaml automation to properly notify in case an Os-Agent update exists is the following:

alias: Os-Agent Update
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.home_assistant_os_agent_latest_release
    attribute: tag
condition:
  - condition: template
    value_template: >-
      {{ trigger.from_state.attributes.tag != "unavailable" and
      trigger.from_state.attributes.tag != "unknown"  }}
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.home_assistant_os_agent_latest_release
        attribute: tag
        state: unavailable
      - condition: state
        entity_id: sensor.home_assistant_os_agent_latest_release
        attribute: tag
        state: unknown
action:
  - service: notify.persistent_notification
    data:
      message: There is an update in Os-Agent!
      title: Update message
mode: single
1 Like