Automation help with location attributes

I have a automation created in the front end that i feel should work but it doesn’t and wondering if anyone can assist.

I live in a RV/caravan so my location changes all the time as i travel the country. My RVWiFi router " used to " report the geo location of my switches using NMAP. but since a recent router firmware update there is no space left on the router to reinstall extra packages.

So… plan b was to create a automation that detected when i drive away from the caravan ( using the switch.ute_power entity). If its unavailable then i’m not near the caravan. But when i return and switch.ute_power shows “off” then i must be near the caravan, so use my phones lat and longitude data to update the lat and long attributes of the router and the caravans location and set.location.

However, the below automation sends me the Telegram message saying its been updated but when i look in the states tab both person.caravan and the RVWiiFi device tracker and set.location still have incorrect coordinates. Any suggestions please ?

oh and if i copy the value templates into the templates tab it returns correct details so assuming they are actually correct.

alias: Update Location
  trigger:
  - entity_id: switch.ute_power
    for: '15'
    from: unavailable
    platform: state
    to: 'off'
  condition:
  - condition: and
    conditions:
    - condition: template
      value_template: 'value_template: "{{ ( states.person.larry.attributes.latitude  )
        != ( states.person.caravan.attributes.latitude ) }}"'
  action:
  - data:
      latitude: '{{ states.person.larry.attributes.latitude }}'
      longitude: '{{ states.person.larry.attributes.longitude }}'
    data_template:
      latitude: '{{ states.device_tracker.rvwifi_lan.attributes.latitude }}'
      longitude: '{{ states.device_tracker.rvwifi_lan.attributes.longitude }}'
    service: homeassistant.set_location
  - data:
      message: The Caravans location has just been updated
    service: notify.larrys_phone
  - data:
      latitude: '{{ states.person.larry.attributes.latitude }}'
      longitude: '{{ states.person.larry.attributes.longitude }}'
    entity_id: person.caravan,  device_tracker.rvwifi_lan
    service: homeassistant.update_entity

Happy to not focus on the Router getting updated as im not concerned about that. But back a few months ago when i had it working using nmap the reasoning was … If “person.caravan” changes location then set.location to person.caravans new coordinates

cheers

On a side note: no where in the automation in the front end have i referred to rvwifi.lan.attributes etc so no idea why this bit of code was in the automation

but removing it didnt help my problem anyway unfortunately

For anyone else playing along… I ended up not using the above automation because it didn’t work anyway. My interpretation now is that “update.entity” will just tell the device_tracker to update its status to home or not_home… Not update its attributes as i was hoping.

Anyway. For me and my requirements i ended up making a node red flow that does the following

  • i used a state node to work out if my vehicle is near the caravan
  • if it is then send the output to a trigger node to delay the message for 15 minutes ( to confirm i’m near the caravan).
  • once the trigger node goes for 15 minutes with out a reset message then it outputs to a “get entity” node
  • The get entity node out puts my phones location ( which would be near the caravan by now as its been 15 minutes) and send the output payload to a function node.
  • The function node then pulls out my phones latitude and longitude coordinates
  • The function node sends the coordinates to a change node where i clean up the payload
  • that then sends to a call service node which uses the set.location call.

So basically. i have no more need for device trackers like NMAP or a fake person like i had person.caravan to worry about. If my Vehicle is next to the caravan it auto updates the home location.

Node red flow is below if it helps anyone else

[{“id”:“d363cf62.dd9388”,“type”:“tab”,“label”:“Flow 1”,“disabled”:false,“info”:“”},{“id”:“e904ce7e.3a493”,“type”:“debug”,“z”:“d363cf62.dd9388”,“name”:“”,“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“x”:1071.5,“y”:142.5,“wires”:},{“id”:“4322ef5c.3476d”,“type”:“inject”,“z”:“d363cf62.dd9388”,“name”:“”,“topic”:“”,“payload”:“test”,“payloadType”:“str”,“repeat”:“”,“crontab”:“”,“once”:false,“onceDelay”:0.1,“x”:377.5,“y”:141.5,“wires”:[[“e3f9e488.082b7”]]},{“id”:“9acbba4a.ec019”,“type”:“trigger-state”,“z”:“d363cf62.dd9388”,“name”:“is Ute near van ?”,“server”:“99a1717a.4a95”,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:“”},{“property”:“icon”,“value”:“”}],“entityid”:“switch.ute_power”,“entityidfiltertype”:“exact”,“debugenabled”:false,“constraints”:,“constraintsmustmatch”:“all”,“outputs”:2,“customoutputs”:,“outputinitially”:true,“state_type”:“str”,“x”:152.5,“y”:193.5,“wires”:[[“dddf212d.cccdb8”,“bc4b15de.644bf8”],[“dddf212d.cccdb8”]]},{“id”:“e3f9e488.082b7”,“type”:“ha-get-entities”,“z”:“d363cf62.dd9388”,“server”:“99a1717a.4a95”,“name”:“”,“rules”:[{“property”:“entity_id”,“logic”:“includes”,“value”:“person.larry”,“valueType”:“str”}],“output_type”:“split”,“output_empty_results”:false,“output_location_type”:“msg”,“output_location”:“payload”,“output_results_count”:1,“x”:535.5,“y”:190.5,“wires”:[[“4bf36061.c166b8”,“79b480c5.a7fb6”]]},{“id”:“4bf36061.c166b8”,“type”:“debug”,“z”:“d363cf62.dd9388”,“name”:“”,“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“x”:565.5,“y”:140.5,“wires”:},{“id”:“bc4b15de.644bf8”,“type”:“debug”,“z”:“d363cf62.dd9388”,“name”:“”,“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“x”:196.5,“y”:146.5,“wires”:},{“id”:“c333bd90.579bc8”,“type”:“api-call-service”,“z”:“d363cf62.dd9388”,“name”:“Set Home Location from Larrys coordinates”,“server”:“99a1717a.4a95”,“version”:1,“debugenabled”:false,“service_domain”:“homeassistant”,“service”:“set_location”,“entityId”:“”,“data”:“”,“dataType”:“json”,“mergecontext”:“”,“output_location”:“”,“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1567.6111450195312,“y”:191.8333282470703,“wires”:[]},{“id”:“17b3e71f.60cac9”,“type”:“debug”,“z”:“d363cf62.dd9388”,“name”:“”,“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“x”:1280.5,“y”:137.5,“wires”:},{“id”:“ac84bbc4.f0e388”,“type”:“change”,“z”:“d363cf62.dd9388”,“name”:“”,“rules”:[{“t”:“delete”,“p”:“topic”,“pt”:“msg”},{“t”:“delete”,“p”:“payload.data.dev_id”,“pt”:“msg”},{“t”:“delete”,“p”:“data.entity_id”,“pt”:“msg”},{“t”:“delete”,“p”:“parts”,“pt”:“msg”},{“t”:“delete”,“p”:“data.event”,“pt”:“msg”},{“t”:“delete”,“p”:“data.event_type”,“pt”:“msg”},{“t”:“set”,“p”:“payload.data.gps”,“pt”:“msg”,“to”:“data.gps”,“tot”:“msg”},{“t”:“delete”,“p”:“payload.dev_id”,“pt”:“msg”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:1065.5,“y”:191.5,“wires”:[[“2d06552.9393faa”,“e904ce7e.3a493”]]},{“id”:“2d06552.9393faa”,“type”:“json”,“z”:“d363cf62.dd9388”,“name”:“Turn to JSON”,“property”:“payload”,“action”:“”,“pretty”:false,“x”:1275.5,“y”:193.5,“wires”:[[“c333bd90.579bc8”,“17b3e71f.60cac9”]]},{“id”:“79b480c5.a7fb6”,“type”:“function”,“z”:“d363cf62.dd9388”,“name”:“Find Larrys Coordinates”,“func”:“lat = msg.payload.attributes.latitude;\nlongi = msg.payload.attributes.longitude;\n\nmsg.payload = {\n "data":{\n "latitude": +lat ,\n "longitude": +longi\n }\n}\nreturn msg;\n”,“outputs”:1,“noerr”:0,“x”:790.5,“y”:190.5,“wires”:[[“ac84bbc4.f0e388”]]},{“id”:“dddf212d.cccdb8”,“type”:“trigger”,“z”:“d363cf62.dd9388”,“op1”:“”,“op2”:“1”,“op1type”:“nul”,“op2type”:“str”,“duration”:“15”,“extend”:false,“units”:“min”,“reset”:“unavailable”,“bytopic”:“all”,“name”:“”,“x”:357.5,“y”:192.5,“wires”:[[“e3f9e488.082b7”]]},{“id”:“99a1717a.4a95”,“type”:“server”,“z”:“”,“name”:“Home Assistant”,“legacy”:false,“hassio”:true,“rejectUnauthorizedCerts”:true,“ha_boolean”:“y|yes|true|on|home|open”,“connectionDelay”:true}]