Need help with proximity automation

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.

as a matter of fact I did but still running into errors at the action side of things

I see the issue now… You need to fix your " in the condition. You have double quotes both inside and outside the template.

In UI , I see this

if I go to the 3 dots on the far top right > edit in yaml I see this:


and if I go to automotion file in vs code editor I see this:

Is this normal?!

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.

1 Like

ok, will report back.

Update:

Still giving me the escaping \" issue.
here is my trace 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?

I set my proximity.person_home to the appropriate attribute under developer tools, in this case,

state: 4
dir_of_travel: towards
nearest: Tarik
unit_of_measurement: km
friendly_name: tarik_home

then I click run from the top hamburger menu like so

I removed the other 2 persons just to make sure they weren’t bugging things

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.

1 Like

Thank you!

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.

this is what it was indeed.