I’m using the Nest integration for my thermostat, and as part of the automations where it is automatically turned down I would like to do a tts.cloud_say notification over my speaker(s). I’m picking a random message from a list (some examples below).
Problem is that the {{ states.climate...temperature }} is actually read out as if it were text, not the parsed value of the attribute.
- service: script.jarvis
data:
message: >-
{{ [
"Temp is set to {{ states.climate.nest.attributes.temperature }} degrees celsius.",
"Setting changed to {{ states.climate.nest.attributes.temperature }} degrees celsius.",
"We'll be heating to {{ states.climate.nest.attributes.temperature }} degrees celsius."
] | random }}
What can be done to parse these nested expressions so the actual value is used?
- service: script.jarvis
data:
message: >
{{ [ "Temp is set to ", "Setting changed to ", "We'll be heating to " ] | random state_attr('climate.nest', 'temperature') }} degrees celsius.
That should work for the example I supplied, so kudos for that.
There’s always a… but; what I’m after is being able to use it inside of a sentence. In the examples I gave it’s pretty simple, but in other automations I’d like to nest it halfway through a sentence that does not always end the same.
- service: script.jarvis
data:
message: >
Any other text you want to start with. {{ [ "Temp is set to ", "Setting changed to ", "We'll be heating to " ] | random state_attr('climate.nest', 'temperature') }} degrees celsius.
Not familiar with that expression, not my maiden language… Also not at all trying to move the goalposts, just trying to figure out how to use a parsed value inside of an existing expression. How would you reform my original question in a better way:
What can be done to parse these nested expressions so the actual value is used?
I hope I used the correct terms here… I’ve been struggling with finding the right words.
I understand now that I made the mistake of ending the sentences with the same words, I guess that made it a bit unclear what my goal is.
Also not looking for a quick fix, just trying to learn and understand how to do stuff like this in YAML.
So if you have an answer, that would be much appreciated. And if not, I hope my goal is a bit more clear for others to chime in.
- service: script.jarvis
data:
message: >-
{{ ["Temp is set to TT degrees celsius.",
"Setting changed to TT degrees celsius.",
"We'll be heating to TT degrees celsius.",
"TT has been reached so it is turned down.",
"Now that the door opened, TT is too high so I turned it down.",
"The thermostat has now been turned down from TT."
] | random | replace('TT', state_attr('climate.nest', 'temperature')) }}