This is what I use to get my spouse position:
[{"id":"04f6362bd6ddf462","type":"function","z":"c513d12c.45645","name":"Build message to speak json string","func":"if(msg.loc == \"\"){\n msg.zone = \"vid \" + msg.zone;\n msg.payload = {\n data:{\n \"entity_id\": \"media_player.nedervaningen\",\n \"message\": \"Petra är nu \" + msg.zone.replace(\"vid home\",\"hemma\") + \". Ungefär \" + msg.distance + \" meter härifrån.\",\n \"language\": \"sv-SE\"\n }\n }\n}else{\n msg.payload = {\n data:{\n \"entity_id\": \"media_player.nedervaningen\",\n \"message\": \"Petra är nu vid \" + msg.loc + \". Ungefär \" + msg.distance + \" meter härifrån.\",\n \"language\": \"sv-SE\"\n }\n }\n}\nmsg.event_type = \"\";\nmsg.topic = \"\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3260,"y":1820,"wires":[["ca588a429bd5d98b"]]},{"id":"364fea07ae3a5193","type":"api-current-state","z":"c513d12c.45645","name":"","server":"4bbca37b.1700ec","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.distance_away_petra","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"distance","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":2810,"y":1780,"wires":[["04f6362bd6ddf462","f87b48b1335c0de2"]]},{"id":"ca588a429bd5d98b","type":"api-call-service","z":"c513d12c.45645","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"tts","service":"cloud_say","entityId":"media_player.nedervaningen","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":3530,"y":1820,"wires":[[]]},{"id":"8218e39e447c8dac","type":"api-current-state","z":"c513d12c.45645","name":"","server":"4bbca37b.1700ec","version":2,"outputs":2,"halt_if":"not_home","halt_if_type":"str","halt_if_compare":"is_not","entity_id":"person.petra","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"zone","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":2100,"y":1820,"wires":[["364fea07ae3a5193"],["468870aa70b511c6"]]},{"id":"468870aa70b511c6","type":"api-current-state","z":"c513d12c.45645","name":"","server":"4bbca37b.1700ec","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.petra_geocoded_location","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"loc","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":2460,"y":1840,"wires":[["364fea07ae3a5193"]]},{"id":"f87b48b1335c0de2","type":"function","z":"c513d12c.45645","name":"","func":"\nmsg.payload = \"\";\nmsg.event_type = \"\";\nmsg.topic = \"\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3220,"y":1760,"wires":[["1479ab47f69a011d"]]},{"id":"d02755963bf68c3c","type":"switch","z":"c513d12c.45645","name":"","property":"continue","propertyType":"msg","rules":[{"t":"eq","v":"false","vt":"str"},{"t":"eq","v":"stop","vt":"str"},{"t":"eq","v":"true","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1870,"y":1820,"wires":[["a4a2077dfd8e8f93"],[],["8218e39e447c8dac"]]},{"id":"1479ab47f69a011d","type":"api-call-service","z":"c513d12c.45645","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.var_ar_petra","data":"","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":3440,"y":1760,"wires":[[]]},{"id":"ffb2dc7737b9285b","type":"function","z":"c513d12c.45645","name":"","func":"var changed = Date.parse(msg.payload);\nmsg.time = Date.now()-changed;\n//if(Date.now()-changed < 20000){\nif(msg.data.timeSinceChangedMs < 15000){\n msg.continue = \"true\";\n}else{\n msg.continue = \"false\";\n}\nif(isNaN(msg.counter)) msg.counter = 0;\nmsg.counter = msg.counter +1;\nif(msg.counter == 20){\n msg.continue = \"true\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1720,"y":1820,"wires":[["d02755963bf68c3c"]]},{"id":"a4a2077dfd8e8f93","type":"delay","z":"c513d12c.45645","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":1460,"y":1720,"wires":[["2968ee8e9585a431"]]},{"id":"d61c57f0229c435f","type":"api-render-template","z":"c513d12c.45645","name":"Last updated","server":"4bbca37b.1700ec","version":0,"template":"{{ as_timestamp(states.device_tracker.moto_g_8.last_updated) | timestamp_custom('%Y-%m-%d %H:%M', true) }}","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":1570,"y":1820,"wires":[["ffb2dc7737b9285b"]]},{"id":"2968ee8e9585a431","type":"delay","z":"c513d12c.45645","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"7","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"outputs":1,"x":1640,"y":1720,"wires":[["e61bb75bf4abd356"]]},{"id":"e61bb75bf4abd356","type":"api-current-state","z":"c513d12c.45645","name":"","server":"4bbca37b.1700ec","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"device_tracker.moto_g_8","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":1320,"y":1820,"wires":[["d61c57f0229c435f"]]},{"id":"3a21ae0b31da17b7","type":"api-call-service","z":"c513d12c.45645","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"notify","service":"mobile_app_petra","entityId":"","data":"{\"message\":\"request_location_update\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":980,"y":1820,"wires":[["e61bb75bf4abd356"]]},{"id":"33b12558d92a128e","type":"change","z":"c513d12c.45645","name":"","rules":[{"t":"set","p":"loc","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":1820,"wires":[["3a21ae0b31da17b7"]]},{"id":"e505435c7a04cf22","type":"trigger-state","z":"c513d12c.45645","name":"","server":"4bbca37b.1700ec","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_boolean.var_ar_petra","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"i8fdelpqngp","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":480,"y":1820,"wires":[["33b12558d92a128e"],[]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
If you remove the “loop” in the beginning then it will not loop until it gets a new position and it will be faster but perhaps less accurate.
The last function node that creates the TTS message is this:
if(msg.loc == ""){ # if she is in a zone
msg.zone = "vid " + msg.zone; # "at" + zone
msg.payload = {
data:{
"entity_id": "media_player.nedervaningen",
"message": "Petra är nu " + msg.zone.replace("vid home","hemma") + ". Ungefär " + msg.distance + " meter härifrån.",
"language": "sv-SE"
}
}
}else{ # not in zone
msg.payload = {
data:{
"entity_id": "media_player.nedervaningen",
"message": "Petra är nu vid " + msg.loc + ". Ungefär " + msg.distance + " meter härifrån.", #Petra is now at <address>. About <distance> from here.
"language": "sv-SE"
}
}
}
msg.event_type = "";
msg.topic = "";
return msg;