This is the ymal code of my proximity automation but I keep getting errors in traces
This is the error Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'
description: ""
trigger:
- platform: numeric_state
entity_id:
- proximity.joe_home
- proximity.jane_home
- proximity.smith_home
below: 5
condition:
- condition: and
conditions:
- condition: template
value_template: "{{ trigger.to_state.attributes.dir_of_travel == "towards" }}"
action:
- service: notify.joe
data:
message: >-
{{trigger.to_state.object_id[:-5] | capitalize}} is 5 miles away
and heading home!
mode: single
If you are attempting to test this using the “Run” button or automation.trigger service, it will not work. Those methods do not generate a trigger variable for your templates to extract data from.
To test an automation that uses the trigger variable, you need to manually alter the state of one of your triggering entities using the States tool in Developer Tools.
I think those are all technically “normal”, but I vaguely remember some other threads where the escaping \" that is created by using the template condition UI editor caused issues for other users… try editing the yaml ( 3 dots/kebab menu > edit in yaml ), but using both single and double quotes like what you posted from vs code.
If that doesn’t work, I think you’ll need to post you trace’s json.
I have tested the automation and it works on my end. But, your trace doesn’t have a trigger… the only way I can recreate that and the error message you showed previously is by manually running the automation.
Can you explain, in detail, how you are testing this automation?
As I said in my first post, you cannot use the “Run” button to test automations that use the trigger variable…
What you need to do is to manually set the state and attribute in the State tool then press the blue “Set State” button. Remember, for your automation to trigger, the state must change from above 5 to below 5 (with the correct direction), so you may need to first set the state above 5, press the blue button, then set it below 5 and press the blue button again.
the state must change from above 5 to below 5 (with the correct direction), so you may need to first set the state above 5, press the blue button, then set it below 5 and press the blue button again.