I’ve always liked that ‘fail-safe’ behavior because it works exactly the same way in Premise; when I first encountered it (many years ago) it struck me as being a simple but thoughtful touch.
I believe the format in the OP would have worked but there is a misunderstanding…I think…
You are using the “is_state” method but the trigger doesn’t use that (not sure exactly the terminology but I think that the trigger isn’t a “state object” so you can’t use the is_state() method on it).
trigger.to_state.state returns a string.
try this as a test to see if it works (I think it should):
message: "{{ trigger.from_state.attributes.friendly_name }} is now {% if trigger.to_state.state == 'on') %}Open{% else %}Closed{% endif %}!"
@123’s is a bit more compact but you were on the right track except for that tweak.
In fact it was easier than that, OP just needed to remove the single quotes from around trigger.to_state.state in the template as trigger is a variable.
That said, it is messy so I’m glad they asked and @123 cleaned it up.
Yeah, now that I think about it a bit more I guess that the trigger is a state object since it actually does contain the “state” and all of the other data contained inside.
I just never picked up on that being considered a variable that could be used (without the quotes) in the state() or its variations.
Hey everyone,
Thank you for all the answers, glad I picked your mind and created some constructing conversation
I wish i could try out all the options and tell you what’s up but right now it seems the whole notify.lg_tv thingy service is down. It doesnt work at all.
So ill troubleshoot this first and come back with results.
message: "{{ trigger.from_state.attributes.friendly_name }} is now {% if trigger.to_state.state == 'on') %}Open{% else %}Closed{% endif %}!"
Does not work at all, no notification appears.
@123 is giving closed in both states "{{ trigger.from_state.name }} is now {{ 'Open' if is_state(trigger.to_state.state, 'on') else 'Closed' }}!"
@tom_l’s worked: message: "{{ trigger.from_state.attributes.friendly_name }} is now {{ 'Open' if trigger.to_state.state == 'on' else 'Closed' }}."