This one is driving me nuts… I’m trying to set up an automation that sends a notification whenever the state of a person
changes. I want to avoid using from:
or to:
conditions because I am using zones and there are multiple possible states the person
can take. I’ve tried the following:
- alias: 'Nick changed zone'
trigger:
platform: state
entity_id: person.nick
condition:
condition: template
value_template: "{{ trigger.from_state.state != trigger.to_state.state }}"
action:
service: notify.mobile_app_nicks_iphone
data_template:
message: "Nick is now {{ states.person.nick.state }}. (Previously: {{ trigger.from_state.state }})"
data:
push:
sound: default
and variants like it, but I consistently get an error reporting
ERROR (MainThread) [homeassistant.helpers.service] Error rendering data template: UndefinedError: 'trigger' is undefined
The error message seems to suggest that I shouldn’t use the trigger
object in a value_template
condition.
The automation works if I leave out the condition, but then I get notifications even when not moving, because the person
object receives attribute updates from time to time.
Hoping someone can help!
Thanks,
Nick