Addresses for Home Assistant automations
Automations that say where someone is need an address, and the usual way to get one sends every position of every phone to a cloud geocoder. A server on your network answers instead.
What you have
A running server on the network, and the integration from the repository: copy integrations/home-assistant/custom_components/gridpin into the custom_components folder of your Home Assistant configuration and restart. Then Settings → Devices & services → Add integration → GridPin, with the server address. To see what the sensor will ask and show, a check with the integration's own code:
# What the GridPin sensor asks and shows, using the integration's own format.py.
import json, urllib.request
from ha_format import reverse_url, state_of
url = reverse_url("http://127.0.0.1:8080", 41.94763, -87.65638) # a phone's position
print(url)
state, attributes = state_of(json.load(urllib.request.urlopen(url)))
print(state)
print(attributes)
Steps
1. Start the server for your country; on another machine, add --host 0.0.0.0:
$ gridpin serve usa.bin --port 8080
2. The request the sensor makes for a position, and the state and attributes it sets:
$ python3 ha_check.py
http://127.0.0.1:8080/v1/reverse?lat=41.947630&lon=-87.656380&k=1
3555 North CLARK Street, 60657 Chicago
{'distance_m': 67.3, 'match_level': 'StreetAddressExt', 'commune': 'Chicago', 'latitude': 41.9470566, 'longitude': -87.6561228}
What you get
A sensor per device tracker whose state is the nearest address, with distance_m, match_level and the town as attributes: use them in an automation's condition, for example only when distance_m is under 50.
Why it works
The sensor asks /v1/reverse of your server with the tracker's position and turns the answer into text; the server answers from the country file, so the position never leaves your network.
Limits
- Installation is by copying the folder: the repository is not set up as a HACS repository, so HACS cannot install it from there.
- The nearest stored address can be the neighbour's: here 67 m from the position; filter on
distance_m. - Home Assistant itself was not run for this page; the check uses the integration's code and a live server.
The function: Home Assistant. The server: a local geocoding server.