Device tracker proximity?

I have a flow that triggers when I’m driving home and I get 1 Kms from home. Only thing is that it also triggers when I’m leaving home. Is there a way to only have it trigger when I’m going home?

image

image

The structure of the Proximity entity give you the answer. :slight_smile:

Attribute dir_of_travel is what you are looking for.

   -  entity_id: proximity.home
      attributes:
          dir_of_travel: arrived
          friendly_name: home
          nearest: <Person>
          unit_of_measurement: ft
      last_changed: '2020-05-03T21:40:25.280039+00:00'
      last_updated: '2020-05-03T21:40:25.280039+00:00'
      state: '0'

The Proximity Integration covers this in the documentation as follows:

dir_of_travel: Direction of the closest device to the monitored zone. Values are:

  • not set
  • arrived
  • towards
  • away_from
  • unknown
  • stationary

With respect to Node Red, I do not know how to use an entity attributes, but there is a way. :slight_smile:

I don’t see that attribute in my current entities. How would I do that?

It is an attribute of your proximity.dave_to_home entity. I’m unsure in NodeRed of how to have conditionals against entity attributes.

Quick search lead me to a reference, hope it helps.

I played around with this off and on for months, there’s something odd about how Proximity works, it only fires at certain times, and doesn’t always update all of its attributes at the same time. I’m unfortunately not able to access to pull the code right now, but I was able to get this to work by creating a simple template sensor out of the dir_of_travel attribute.

1 Like

It works perfectly fine for me in Node Red.
Here is my config including the switch node to filter for the required attribute:

[{"id":"e327797a.739a58","type":"server-state-changed","z":"7af83619.471ce8","name":"Marcus Proximity Home","server":"2fba4297.e4145e","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"proximity.home_marcus","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"200","halt_if_type":"num","halt_if_compare":"lte","outputs":2,"output_only_on_state_change":true,"x":100,"y":1740,"wires":[["fb42ffec.1bb0b"],["9c8be030.b10a9"]]},{"id":"fb42ffec.1bb0b","type":"switch","z":"7af83619.471ce8","name":"","property":"data.new_state.attributes.dir_of_travel","propertyType":"msg","rules":[{"t":"eq","v":"towards","vt":"str"},{"t":"eq","v":"arrived","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":1740,"wires":[["e3fac09f.0551a"],["e3fac09f.0551a"]]},{"id":"7a662ac4.8cda84","type":"change","z":"7af83619.471ce8","name":"Message","rules":[{"t":"set","p":"message","pt":"msg","to":"Home","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1740,"wires":[["a6f4204f.fa77b","7d0afbd0.3c8064"]]},{"id":"a6f4204f.fa77b","type":"function","z":"7af83619.471ce8","name":"Message","func":"newmsg = {}\n\nnewmsg.payload = { data: {\"title\":\"*Location*\", \"message\":msg.message} }\n\nreturn newmsg;\n","outputs":1,"noerr":0,"x":1020,"y":1780,"wires":[["3bc9807e.8ae2"]]},{"id":"7d0afbd0.3c8064","type":"function","z":"7af83619.471ce8","name":"Set already sent on","func":"flow.set(\"location\", 1, \"storeInFile\");\n\n","outputs":1,"noerr":0,"x":1050,"y":1740,"wires":[[]]},{"id":"e3fac09f.0551a","type":"function","z":"7af83619.471ce8","name":"Location sent already?","func":"var newmsg = {}\nvar locationflow = flow.get('location',\"storeInFile\");\nif (locationflow == 0)\n   newmsg.payload = \"True\";\nelse (newmsg = null)\n\nreturn newmsg;\n","outputs":1,"noerr":0,"x":500,"y":1740,"wires":[["7a662ac4.8cda84"]]},{"id":"6c22cbe6.395d14","type":"function","z":"7af83619.471ce8","name":"Set already sent off","func":"flow.set(\"location\", 0, \"storeInFile\");\n\n","outputs":1,"noerr":0,"x":1050,"y":1820,"wires":[[]]},{"id":"9c8be030.b10a9","type":"switch","z":"7af83619.471ce8","name":"","property":"data.new_state.attributes.dir_of_travel","propertyType":"msg","rules":[{"t":"eq","v":"away_from","vt":"str"},{"t":"eq","v":"stationary","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":1820,"wires":[["ad832b41.9286e8"],[]]},{"id":"ad832b41.9286e8","type":"function","z":"7af83619.471ce8","name":"Location sent already?","func":"var newmsg = {}\nvar locationflow = flow.get('location',\"storeInFile\");\nif (locationflow == 1)\n   newmsg.payload = \"True\";\nelse (newmsg = null)\n\nreturn newmsg;\n","outputs":1,"noerr":0,"x":500,"y":1820,"wires":[["eda76c27.efdc8"]]},{"id":"dea4f061.6f2aa","type":"trigger-state","z":"7af83619.471ce8","name":"Home -> Not Home","server":"2fba4297.e4145e","entityid":"person.marcus","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"764wg0zttim","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"home"},{"id":"6ljfddisqd5","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"home"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":110,"y":1820,"wires":[["eda76c27.efdc8"],[]]},{"id":"eda76c27.efdc8","type":"change","z":"7af83619.471ce8","name":"Message","rules":[{"t":"set","p":"message","pt":"msg","to":"Away","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1820,"wires":[["a6f4204f.fa77b","6c22cbe6.395d14"]]},{"id":"2fba4297.e4145e","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Please note that all you probably need is the switch node to easily filter for the attribute. Its in the msg.data.new_state.attributes.dir_of_travel if you use the trigger state node.
The rest i setup as i have specific other requirements that may not apply to you as well.

2 Likes

hi… I would like to open door when a I come back home…so…you can help me? thanks!!