tom_l
September 22, 2022, 9:11am
6
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
HasQT
(Has)
September 22, 2022, 9:12am
7
/host/info: agent_version is an endpoint - docs
You could compare the actual sensor to the github sensor.
Tryfos
(Tryfos)
September 22, 2022, 9:12am
8
Hmm, that could be it. You mean triger.from_state obviously.
tom_l
September 22, 2022, 9:14am
9
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.
Tryfos
(Tryfos)
September 22, 2022, 9:19am
10
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
Tryfos
(Tryfos)
September 22, 2022, 9:21am
11
I cover going to unavailable with another simple “state not unavailable” condition.
1 Like
tom_l
September 22, 2022, 9:22am
12
Tryfos
(Tryfos)
September 22, 2022, 9:24am
13
Ok, great I’d missed the second one. Thanks a lot!
Tryfos
(Tryfos)
September 22, 2022, 10:03am
14
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).
tom_l
September 22, 2022, 10:08am
15
Tryfos
(Tryfos)
September 22, 2022, 10:14am
16
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 )
tom_l
September 22, 2022, 10:19am
17
Dunno. I don’t use the automation editor. What does it generate in the yaml view?
Tryfos
(Tryfos)
September 22, 2022, 10:23am
18
condition: template
value_template: "{{ trigger.from_state.attributes.tag != \"unavailable\", \"unknown\" }}"
Seems definitely wrong
Tryfos
(Tryfos)
September 22, 2022, 10:28am
19
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.
tom_l
September 22, 2022, 10:30am
20
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
Tryfos
(Tryfos)
September 22, 2022, 10:32am
21
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?
Tryfos
(Tryfos)
September 22, 2022, 10:34am
23
Ok, let me try the single line. I felt something like {{ trigger.from_state.attributes.tag != "unavailable", "unknown" }}
could bu valid.
Tryfos
(Tryfos)
September 22, 2022, 10:37am
24
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
Tryfos
(Tryfos)
September 22, 2022, 11:05am
25
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