Closed gobigdave closed 2 years ago
See the iCloud3 docs here for info about only tracking with the iOS app.
I think you misunderstood. I only want to track with an Android app. I have one son that has Android.
For now, I have some Node-Red that updates a few sensors. Unlike the iOS app, Android is pretty good about sending fairly regular updates back to the HA server. I'm thinking whether it would be possible to bypass iCloud code and only use the location from the mobile app. Then we would get all that Waze awesomeness even if we have one crazy child that wants Android. :)
[{"id":"20d86bc4043c4b10","type":"trigger-state","z":"16a105a5.d21b2a","name":"Son Location","server":"aec342f7.5ee34","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"person.son","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","enableInput":false,"x":150,"y":1500,"wires":[["646e8b4dca1b3e87"],[]]},{"id":"bf2a5f05688c8577","type":"ha-entity","z":"16a105a5.d21b2a","name":"Son Calc Distance","server":"aec342f7.5ee34","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"son_phone_calc_distance"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:map-marker-distance"},{"property":"unit_of_measurement","value":"miles"}],"state":"distance_miles","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":690,"y":1440,"wires":[[]]},{"id":"646e8b4dca1b3e87","type":"function","z":"16a105a5.d21b2a","name":"Calculate Son Info","func":"var old_state = msg.data.event.old_state;\nvar new_state = msg.data.event.new_state;\nvar calc_distance = true;\n\nmsg.last_updated = new Date().toISOString();\nmsg.latitude = new_state.attributes[\"latitude\"];\nmsg.longitude = new_state.attributes[\"longitude\"];\n\nif (new_state.state == \"not_home\") {\n msg.last_located = msg.last_updated;\n} else {\n msg.last_located = new_state.last_changed;\n if (new_state.state == \"home\") {\n msg.distance_miles = 0.0;\n msg.distance_km = 0.0;\n calc_distance = false;\n }\n}\n\nif (calc_distance) {\n lon1 = global.get(\"home_longitude\", \"secrets\") * Math.PI / 180;\n lon2 = msg.longitude * Math.PI / 180;\n lat1 = global.get(\"home_latitude\", \"secrets\") * Math.PI / 180;\n lat2 = msg.latitude * Math.PI / 180;\n\n\n // Haversine formula \n let dlon = lon2 - lon1; \n let dlat = lat2 - lat1;\n let a = Math.pow(Math.sin(dlat / 2), 2) + \n Math.cos(lat1) * Math.cos(lat2) *\n Math.pow(Math.sin(dlon / 2),2);\n\n let c = 2 * Math.asin(Math.sqrt(a));\n\n // Radius of earth in kilometers (6371). Use 3956 for miles\n msg.distance_miles = +(c * 3956).toFixed(2);\n msg.distance_km = +(c * 6371).toFixed(2);\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":1500,"wires":[["bf2a5f05688c8577","04687f6e7db15c19","98045b65571635cf"]]},{"id":"04687f6e7db15c19","type":"ha-entity","z":"16a105a5.d21b2a","name":"Son Last Located","server":"aec342f7.5ee34","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"son_phone_last_located"},{"property":"device_class","value":"timestamp"},{"property":"icon","value":"mdi:history"},{"property":"unit_of_measurement","value":""}],"state":"last_located","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":680,"y":1500,"wires":[[]]},{"id":"98045b65571635cf","type":"ha-entity","z":"16a105a5.d21b2a","name":"Son Last Updated","server":"aec342f7.5ee34","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"son_phone_last_updated"},{"property":"device_class","value":"timestamp"},{"property":"icon","value":"mdi:history"},{"property":"unit_of_measurement","value":""}],"state":"last_updated","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":690,"y":1560,"wires":[[]]},{"id":"aec342f7.5ee34","type":"server","name":"Home Assistant","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]
I haven't taken a look at the Android mobile_app, nor have any experience with devices running Android (except my Sony TV). Anyway, I'll take a look at the HA docs and the sensors it creates/updates to see if there is a common thread.
I'm in the process of rewriting iCloud3 and turning it into a full integration. With it, the iOS App data has as much importance as the iCloud data and a check is made on each cycle to determine what data is newer and more accurate. It may have come from the iOS App and it may have come from iCloud. It might be possible to change a few things regarding the Entity I/O routines to get data from either source based on the config.
I'll look at the Android docs and give it some thought with I get a chance.
Based on what I see, you may not need to know much whether it's iOS or Android. I have HA person entities setup with device_trackers for the phone, the app, and Unify Wifi. My person.dave is setup with device_tracker.daves_iphone, device_tracker.unifi_daves_iphone, and device_tracker.daves_iphone_app. For my son on Android, he only has the app and UniFi. With that, person.dave will have updated lat/long always set by whatever HA server thinks is most accurate. The Node-Red posted above gets regular updates to person.son from the mobile app (every few minutes if he's on the move). No specific knowledge of Android needed. Coder me thinks you might be able to just skip the iCloud code and depend on the person or device_tracker updates if there is a family like mine with a rogue Android phone and no iCloud account.
Grabbing at straws a little. I would love to take advantage of the great extra sensors in this integration (travel_time, zone_distance, etc.) However, one of the 5 in my family prefers Android. Before I start wiring up a bunch of NodeRed or python, I'm wondering if there is a way to configure this to only use the location information from the HA app and not try to use iCloud for one device.