After upgrading from .102 to .106, some of my templated TTS messages stopped working.
I looked through the breaking changes and found this issue, possibly the reason why it broke. But I don’t know how to fix it.
For example, this one used to work:
- service: notify.alexa_media
data_template:
target: '{{ states.sensor.last_alexa.state }}'
data:
type: tts
message: >
{% if trigger.entity_id == "input_boolean.alexa_tide_report" %}
It is
{% if states('sensor.waterstand') | float < -40 %}
Low
{% elif states('sensor.waterstand') | float > 50 %}
High
{% else %}
Medium
{% endif %}
tide.
{% endif %}
When I remove the second and second-last line inside the tts message (“It is”, “tide.”) it works again. So I’m guessing there’s something with nested IF statements, and parts of the message not allowed inside them.
Anybody has an idea how to recreate the original message that doesn’t break templating rules? I could include the second line later, but sometimes I need to make these kind of ‘composed’ tts messages - this is just one of the simpler examples.
– edit: changed It’s to It is, just to make the code formatting look better here –
The first if template is wrong for at least 2 reasons at first glance
1 - it should be trigger.to_state.entity_id
2 - You don’t have an else - what is to be said other than “It’s” if the trigger wasn’t input_boolean.alexa_tide_report ?
Thanks Marc. I used trigger.entity_id from the documentation but I now see there’s also a trigger.to_state.domain. Both seem to work. The ‘else’ is actually in the complete automation at the bottom (this is only the ‘tide report’) and including it in the example doesn’t do much unfortunately. It really seems to have something to do with the inclusion of “It is” and “tide” in between the if’s.
In other words, this returns a tts message:
{% if trigger.entity_id == "input_boolean.alexa_tide_report" %}
{% if states('sensor.waterstand_tov_nap') | float < -40 %}
Low
{% elif states('sensor.waterstand_tov_nap') | float > 50 %}
High
{% else %}
Medium
{% endif %}
{% endif %}
And this one doesn’t:
{% if trigger.to_state.entity_id == "input_boolean.alexa_tide_report" %}
It is
{% if states('sensor.waterstand_tov_nap') | float < -40 %}
Low
{% elif states('sensor.waterstand_tov_nap') | float > 50 %}
High
{% else %}
Medium
{% endif %}
tide.
{% else %} There is nothing to report on.
{% endif %}
I’m a bit stuck then tbh, I’m on my phone at the moment so I can’t test anything and am just trying to do it by sight, but I can’t spot what would be causing the problem right now.
I’ll have a head scratch, but hopefully in the meantime someone else will either spot it or test it and work it out