Hello All.
I’m using homeassistant now for about a year i guess and Im very happy with the possibilities.
However, as I ad more components and build more automations it’s getting trickier and more complicated to get what I need with the basic coding I can comprehend.
For now I installed along home assistant on my pi3 also an influxdb and grafana and all is working well.
Now there is an plugin (worldmap) that needs geohashes to show on the map. In home assistant I have owntracks and other device trackers who report in GPS coordinates.
There is a python script that converts gps coordinates to geohash :
def encode(latitude, longitude, precision=12):
"""
Encode a position given in float arguments latitude, longitude to
a geohash which will have the character count precision.
"""
lat_interval, lon_interval = (-90.0, 90.0), (-180.0, 180.0)
geohash = []
bits = [ 16, 8, 4, 2, 1 ]
bit = 0
ch = 0
even = True
while len(geohash) < precision:
if even:
mid = (lon_interval[0] + lon_interval[1]) / 2
if longitude > mid:
ch |= bits[bit]
lon_interval = (mid, lon_interval[1])
else:
lon_interval = (lon_interval[0], mid)
else:
mid = (lat_interval[0] + lat_interval[1]) / 2
if latitude > mid:
ch |= bits[bit]
lat_interval = (mid, lat_interval[1])
else:
lat_interval = (lat_interval[0], mid)
even = not even
if bit < 4:
bit += 1
else:
geohash += __base32[ch]
bit = 0
ch = 0
return ''.join(geohash)
I put this is my /python_scripts folder… but then what? How do I “paste” the coordinates from any of the device trackers into my python script, then run it, and then getiing the output back into a variable (geohash in string) into HA so I can use it in grafana. I’ve searched a lot but cannot find the solution.
I tried to search via python, custom components… no luck. appdaemon for me is to far fetched to get started with that right now if that could be the solution
many thanks in advance,
cheers