Using HASS.Agent and a VPN, I’m exposing a location sensor work my work laptop that holds GPS coordinates. I’d like to create a MQTT Device Tracker from that to use in automations, but I can’t seem to figure out for the life of me what I am doing wrong.
The sensor, sensor.latitude_e5470_geolocation
, has the following state: 51.908242362241235,5.534193299322271,0
so I think thought publishing to a MQTT topic like this should do it:
service: mqtt.publish
data:
topic: homeassistant/location/work_laptop
retain: true
payload: |-
{
"latitude": "{{ states('sensor.latitude_e5470_geolocation').split(',')[0] |replace("'", '')|replace("[", '')}}",
"longitude": "{{ states('sensor.latitude_e5470_geolocation').split(',')[1] |replace("'", '')|replace("[", '')}}",
"battery_level": {{states('sensor.latitude_e5470_battery_charge_remaining_percentage')|int}},
"gps_accuracy": {{1}}
}
and creating a configuration.yaml
entry like this would sort it:
mqtt:
device_tracker:
- name: "laptop_tracker"
state_topic: "homeassistant/location/work_laptop"
json_attributes_template: >
{"other_data":"{{ states('sensor.latitude_e5470_geolocation').split(',')[0] |replace("'", '')|replace("[", '')}}","other_data2":"{{ states('sensor.latitude_e5470_geolocation').split(',')[1] |replace("'", '')|replace("[", '')}}"}
payload_home: "home"
payload_not_home: "not_home"
I am doing something really wrong here, but can’t figure out what I should change. Does anyone have any suggestions? I don’t seem to be able to put the GPS attributes in any correct place…