I am trying to use the new assist_satellite.announce action in an existing script. This script is part of an “alert” where the notify section calls the script. This alert is to let me know if one of my garage doors has been left open.
In my alert stanza, I define a variable like so:
data:
door: "inner"
Then, in the script that is called, I have a sequence like this:
sequence:
- action: assist_satellite.announce
metadata: {}
data:
message: >
{% if data.door == 'outer' %}
"The outer garage door has been open for {{ relative_time(states.cover.garage_door_outer.last_changed) }}."
{% else %}
"The inner garage door has been open for {{ relative_time(states.cover.garage_door_inner.last_changed) }}."
{% endif %}
preannounce: true
target:
entity_id: assist_satellite.kitchen_vpe_assist_satellite
It appears that the script is failing as it cannot deal with the data.door. What is the correct way to handle this?
sequence:
- action: assist_satellite.announce
metadata: {}
data:
message: >
{% if variables.door == 'outer' %}
The outer garage door has been open for {{ relative_time(states.cover.garage_door_outer.last_changed) }}.
{% else %}
The inner garage door has been open for {{ relative_time(states.cover.garage_door_inner.last_changed) }}.
{% endif %}
preannounce: true
target:
entity_id: assist_satellite.kitchen_vpe_assist_satellite
If you’re debugging a script, you can temporarily add a logbook.log action or persistent_notification.create step to output the variable
I love the idea of the cleaner approach, however it unfortunately didn’t work. I tried both of the following: "The {{ data.door }} garage door has been open for {{ relative_time('states.cover.garage_door_' ~ door|lower ~ '.last_changed') }}."
and "The {{ data.door }} garage door has been open for {{ relative_time('states.cover.garage_door_' ~ data.door|lower ~ '.last_changed') }}."
In each case, the {{ data.door }} was properly interpreted, but the door/data.door within the ~ ... ~ didn’t work. Any other ideas?
Below is my entire “garage door” notify package. The only thing I have removed are all of the answer sentence equivalents for brevity:
I’m not familiar with Notiscript, but it looks like you may need to defined script fields in the setup for pkg_garage_door_notify_kitchen_voice_assistant_prompt.
I will try that, however I do not think it is necessary as the script is picking up the data.door. My question is more around how do I reference a variable (is this the correct term?) within a variable.
I want the {{ relative_time('states.cover.garage_door_' ~ door|lower ~ '.last_changed') }} to resolve to be states.cover.garage_door_inner.last_changed, where “inner” is taken an input variable. Is this even possible with a Jinga template?