@nick_12 Keep the new features coming a lot of the features on this have came from your ideas. What you are asking can be done by a template sensor. Here is the template:
Apologies @michaelmcarthur only just got back to this discussion and looks like you have already found the problem. I have 4 devices updating their location, not sure how often your component checks the coordinate. My phones if in a vehicle and plugged in will be sending the location up to every 5 seconds to HA. I’m guessing this doesn’t check it every time a new coordinate is set but only every minute or 2, which is what it appears to do.
My limit must have reset, its now updating again but for how long I’m not sure.
Any talks about bringing the device_tracker icon to the sensor without having to manually define it? I use gravatar so that it can update dynamically so it would be neat if we could use the same logic (or use what’s defined on the device_tracker).
I have added some changes to the component on my dev branch on my GitHub. It will tell you if you have exceeded your daily requests and ask you to create a api key. The component can still be run with out the api key.
To add a api key you can do the following.
You need to register for an API key by following the instructions [here](https://github.com/googlemaps/google-maps-services-python#api-keys). You only need to turn on the Geocoding API
A free API Key allows 2500 requests per day. The sensor will update the address each time the device tracker location changes.
The update also reduces requests made when in a zone and only does multiple requests when not home. This should cut down on requests to the point there is still no need to add the api key.
I’m going to run it for the next 24 hours and see how I get on. If anyone else could help by running it as well and reporting back it would be appreciated.
@kylerw I have never used gravatar before but had a quick look into it. I should be able to add it to the component fairly easily. I’ll add it to the feature request list.
@mcfrojd I’m at a bit of a loss now because the update should stop the error appearing all together and give you a message in the sensor state and on the log. The log one should read You have exceeded your daily requests please create an api key.
can you try and delete your cashe for the component and then restart home assistant. The cashe is in this folder: home assistant\custom_components\sensor\__pycache__
Let me know how you get on.
Can it be a problem if any of the returned data contain swedish specific letters?
We have a lot of streetnames with åäö ÅÄÖ in them as you can se here:
I removed all swedish letters, spaces and special charters"()" in the “name:” part of the component. - no luck…
running the wget https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY
with my own lat & long home adress gives me the correct data in the created file.
Disabled 3 of my 4 geocode sensors and rebooted. - no luck…
The following errors have been logged this session:
2017-08-03 12:19:03 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.wilfred fails
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
yield from self.hass.async_add_job(self.update)
File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
value = future.result()
File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
raise self._exception
File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
result = self.fn(*self.args, **self.kwargs)
File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/util/__init__.py", line 303, in wrapper
result = method(*args, **kwargs)
File "/home/homeassistant/.homeassistant/custom_components/sensor/google_geocode.py", line 209, in update
if 'formatted_address' in decoded['results'][0]:
IndexError: list index out of range
@doubleUS That error is the result of one of two errors. The first being incorrect api key. Even if you have a api key for a service you need to enable it to work with googles geolocation api. The other being that you are over your requests limit. I’m working on a error message that will display in the log that will let the user know what the error is.
@mcfrojd I’m glad you fixed your problem. The bug you pointed out is displayed like that by design. The code checks for each of the options the displays them in a set way. This helps with dealing with errors. I’ll see if there is a way to do it in any format.
Thank you for all the feedback. I have updated the sensor and readme on GitHub. No breaking changes this time.
New Features
API Key
The API key is back but as an optional attribute. Some users were finding they were hitting rate limits with the free tier of google geolocation api. This will give users the option to use both free and api key versions. The bonus of the api key version is 2500 requests a day and quicker response times from queries. The free tier has around 300 requests and slows the response time down at around 100 requests to about 10 seconds. Thank you to @stevenhorner and @mcfrojd for identifying this issue and helping to resolve it.
Request Handling
I have reduced the amount of api requests made when in a zone. The sensor was sending requests when in a zone. I have changed the code so it will send a request when it gets in the zone then stop until it changes zone or to not_home.
Error Handling
The sensor will now show the user what the response error is. This tends to be errors from reaching request quotas or and incorrect api key. This makes debugging a whole lot easier for the user. @doubleUS This should help you identify the issue you are having. Let me know how you get on.
There is only three things on the to do list at the moment. That is add gravatar, user defined format of address components and prepare for component for submission to home assistant. If anyone else whats any other features added please let me know. If feels like the component is nearly complete but I’m still open to ideas.
2017-08-09 13:52:26 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.xxx fails
Traceback (most recent call last):
File “/usr/local/lib/python3.4/site-packages/homeassistant/helpers/entity.py”, line 225, in async_update_ha_state
yield from self.hass.async_add_job(self.update)
File “/usr/local/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/local/lib/python3.4/asyncio/tasks.py”, line 285, in _wakeup
value = future.result()
File “/usr/local/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/local/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.4/site-packages/homeassistant/util/init.py”, line 306, in wrapper
result = method(*args, **kwargs)
File “/home/pi/.homeassistant/custom_components/sensor/google_geocode.py”, line 108, in update
url2 = “https://maps.googleapis.com/maps/api/geocode/json?latlng=” + lat + “&result_type=street_address” + “&key=” + api TypeError: Can’t convert ‘NoneType’ object to str implicitly
@frelev it looks like you are using an old version of the component. You can get the latest version here. Have a read of the readme. Let me know how you get on.
@michaelmcarthur Hey, thanks for the development on this. It had been working really well until I upgraded to 0.51.2 where I’m now receiving for following errors in the logs and the location never updates. Is anyone else experiencing this? I’m running hassio on a RPi3.
2017-08-14 20:48:39 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.jacobtracker fails
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
yield from self.hass.async_add_job(self.update)
File "/usr/lib/python3.6/asyncio/futures.py", line 331, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
future.result()
File "/usr/lib/python3.6/asyncio/futures.py", line 244, in result
raise self._exception
File "/usr/lib/python3.6/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.6/site-packages/homeassistant/util/__init__.py", line 306, in wrapper
result = method(*args, **kwargs)
File "/config/custom_components/sensor/google_geocode.py", line 187, in update
if 'formatted_address' in decoded['results'][0]:
IndexError: list index out of range