Skip to content

Instantly share code, notes, and snippets.

@ryan77627
Created January 25, 2023 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryan77627/e39d1d78be54f918b5f9e910485e52b7 to your computer and use it in GitHub Desktop.
Save ryan77627/e39d1d78be54f918b5f9e910485e52b7 to your computer and use it in GitHub Desktop.
OwnTracks Recorder Home assistant app integration
- Download and setup home assistant with mqtt broker, like mosquitto.
- Download HACS and Node-Red into Home Assistant
- Set up home assistant app on device. You will now have a device_tracker entity
- Set up owntracks recorder with the mosquitto mqtt broker
- In Node-Red, make the following nodes:
- trigger: state node set to the device_tracker entity
- Delay node set to rate limiting. Choose something reasonable, like 1 msg/s or something even slower. This won't happen often
- A custom function (described below)
- MQTT out with topic set to owntracks/{person_name}/{device_name}
Custom function is the following:
const globalHomeAssistant = global.get('homeassistant');
var var_tst = Math.floor(Date.now() / 1000); //store epoch timestamp in variable
var var_acc = msg.data.event.new_state.attributes.gps_accuracy; // store gps accuracy reading in variable
var var_alt = msg.data.event.new_state.attributes.altitude; // store altitude reading in variable
var var_batt = globalHomeAssistant.homeAssistant.states["sensor.ryanandroid_battery_level"].state; //entity_id of battery level sensor from mobile app
var var_conn = "w"; //set the data connection. I dont't care about that, so it's fixed.
var var_lat = msg.data.event.new_state.attributes.latitude; //store latitude reading in variable
var var_lon = msg.data.event.new_state.attributes.longitude; //store longitude reading in variable
var var_tid = "1P"; //set two char DeviceID
var var_vac = msg.data.event.new_state.attributes.vertical_accuracy; //store vertical accuracy reading in variable
var var_vel = msg.data.event.new_state.attributes.speed; //store speed reading in variable
msg.payload = {}; //empty the payload, next command will build the new payload. this payload will be written to mosquitto.
msg.payload = '{"_type":"location", "acc":' + var_acc + ', "alt":' + var_alt + ',"batt":' + var_batt + ',"conn":"w", "lat":' + var_lat + ', "lon":' + var_lon + ',"tid":"OO","tst":' + var_tst + ', "vac":' + var_vac + ',"vel":' + var_vel + '}';
return msg;
(Script from u/Saylar @ https://www.reddit.com/r/homeassistant/comments/ijm7lj/psa_you_can_use_the_location_data_send_by_the/ )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment