Cool glad you looked into it. I had wanted this feature awhile ago just could not implement. Thank you for your contribution.
This was working perfectly yesterday but stopped updating at all this morning and the following error is shown:
Aug 01 09:37:10 hass hass[22958]: ERROR:homeassistant.helpers.entity:Update for sensor.bob fails
Aug 01 09:37:10 hass hass[22958]: Traceback (most recent call last):
Aug 01 09:37:10 hass hass[22958]: File "/srv/hass/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
Aug 01 09:37:10 hass hass[22958]: yield from self.hass.async_add_job(self.update)
Aug 01 09:37:10 hass hass[22958]: File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
Aug 01 09:37:10 hass hass[22958]: yield self # This tells Task to wait for completion.
Aug 01 09:37:10 hass hass[22958]: File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
Aug 01 09:37:10 hass hass[22958]: future.result()
Aug 01 09:37:10 hass hass[22958]: File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
Aug 01 09:37:10 hass hass[22958]: raise self._exception
Aug 01 09:37:10 hass hass[22958]: File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
Aug 01 09:37:10 hass hass[22958]: result = self.fn(*self.args, **self.kwargs)
Aug 01 09:37:10 hass hass[22958]: File "/srv/hass/lib/python3.5/site-packages/homeassistant/util/__init__.py", line 303, in wrapper
Aug 01 09:37:10 hass hass[22958]: result = method(*args, **kwargs)
Aug 01 09:37:10 hass hass[22958]: File "/home/steven/.homeassistant/custom_components/sensor/google_geocode.py", line 187, in update
Aug 01 09:37:10 hass hass[22958]: if 'formatted_address' in decoded['results'][0]:
Aug 01 09:37:10 hass hass[22958]: IndexError: list index out of range
A lot of location updates are sent into my HASS installation, is there some sort of rate limit imposed by Google which could stop it from working or is this error nothing to do with that. I can confirm that HASS is still showing the latest coordinates in the device_tracker sensors.
@stevenhorner Thank you for pointing this issue out. I have looked into it. Any requests up to 100 a day should be fine. Soon as a user goes above this it causes a latency delay created by google of up to 12 seconds for requests up to 350. Then I think they put a stop on your IP address. You can read more information about it here. I have noticed that when Iâm in my home zone the component continues to send requests to google Iâm working on an update to fix this which will reduce requests. When you say that your tracker sends lots of requests how many are you talking about? I could add in the ability to use an api key. This will allow requests up to 2500 a day and a quicker response time. Thanks again for pointing this out itâs a huge help to insure this component is stable for all users before itâs addition to home assistant.
@stevenhorner could you check this for me. Can you check what is returned by your system by running this command wget https://maps.google.com/maps/api/geocode/json?latlng=40.748817,-73.985428
if you are running linux. If not open up a browser on the system that you are using and make the request and view the returning json. I would like to know if it has an error code. It is usually at the bottom of the file. Thanks
pi@raspi1:/home/hass$ wget https://maps.google.com/maps/api/geocode/json?latlng=40.748817,-73.985428
--2017-08-01 14:28:00-- https://maps.google.com/maps/api/geocode/json?latlng=40.748817,-73.985428
Resolving maps.google.com (maps.google.com)... 172.217.11.14, 2607:f8b0:4006:814::200e
Connecting to maps.google.com (maps.google.com)|172.217.11.14|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/json]
json?latlng=40.748817,-73.985428: Permission denied
Cannot write to âjson?latlng=40.748817,-73.985428â (Permission denied).
@rpitera everything looks good on your end. The 200 OK
result is expected if everything is good. Iâm looking for something like 403 OVER_QUERY_LIMIT
. Are you having any issues with the component?
I got this working yesterday, but today i get this on all 4 devices i run it on.
2017-08-02 09:12:36 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.matte_plats 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 "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/sensor/google_geocode.py", line 187, in update
if 'formatted_address' in decoded['results'][0]:
IndexError: list index out of range
@mcfrojd I think you are having the same problem as @stevenhorner. Can you run
wget https://maps.google.com/maps/api/geocode/json?latlng=40.748817,-73.985428
then reply with the results? Iâm expecting a 200 OK
if everything is working or a 403
if there is a problem with usage limits. I would like to know if it is to do with usage limits. If it is Iâm going to add the ability to use an optional api key later on today. This will allow up to 2500 requests to be made per day.
@mcfrojd Can you have a look at the file it has created? Then look at the bottom of the file it should say "status" : "OK"
If not could you show me what it says?
Ok that one says âover_query_limitâ.
I went and created a API key now, so i will be ready when this is added to your component
@mcfrojd Perfect! Its definitely too many requests. Iâm working on a fix for this check out my GitHub dev branch copy. Its not totally finished but you can use a api key with it. add it by adding api_key: xxxxxxxxxxxxx
to your sensor.yaml. Change the xxxxxxxxxxx
to your api key. It should fix your problem. Thank you for your help it is a huge help.
Do i add the api_key like this on each of my sensors?
- platform: google_geocode
name: Matte Plats
origin: device_tracker.matte_location
options: street_number, street, city
display_zone: show
api_key: !secret hass_geocode_api
- platform: google_geocode
name: COD Plats
origin: device_tracker.cod630_location
options: street_number, street, city
display_zone: show
api_key: !secret hass_geocode_api
I did that and updated with your dev code.
But now i get this same error:
2017-08-02 11:18:09 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.asa_plats_g 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 "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/sensor/google_geocode.py", line 195, in update
if 'formatted_address' in decoded['results'][0]:
IndexError: list index out of range
My secrets file have this:
hass_geocode_api: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Does it need âxxxxxxxxxxxxxxxxxxxxxxxxâ or âxxxxxxxxxxxxxxxxxxxxxâ maybe?
@mcfrojd Your api key is fine. I know what the issue is. The api key is getting added but the component is using the same server as before and as you have already hit the limit so it wonât work. There is a different server that I can add that should resolve this issue but I wonât be able to add it until later on today. You can test it by using wget https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY
Then check the file as before. If you could reply with the response code it would be greatly appreciated.
That worked fine.
Will the original server âlet me in againâ after a certain time?
If so i can disable the component for now and enable it again tomorrow.
{
"results" : [
{
"address_components" : [
{
"long_name" : "277",
"short_name" : "277",
"types" : [ "street_number" ]
},
{
"long_name" : "Bedford Avenue",
"short_name" : "Bedford Ave",
"types" : [ "route" ]
},
{
"long_name" : "Williamsburg",
"short_name" : "Williamsburg",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Brooklyn",
"short_name" : "Brooklyn",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "Kings County",
"short_name" : "Kings County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "11211",
"short_name" : "11211",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "277 Bedford Ave, Brooklyn, NY 11211, USA",
"geometry" : {
"location" : {
"lat" : 40.7142205,
"lng" : -73.9612903
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 40.71556948029149,
"lng" : -73.95994131970849
},
"southwest" : {
"lat" : 40.7128715197085,
"lng" : -73.9626392802915
}
}
},
"place_id" : "ChIJd8BlQ2BZwokRAFUEcm_qrcA",
"types" : [ "street_address" ]
},
{
"address_components" : [
{
"long_name" : "Grand St/Bedford Av",
"short_name" : "Grand St/Bedford Av",
"types" : [
"bus_station",
"establishment",
"point_of_interest",
"transit_station"
]
},
{
"long_name" : "Williamsburg",
"short_name" : "Williamsburg",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Brooklyn",
"short_name" : "Brooklyn",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "Kings County",
"short_name" : "Kings County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "11211",
"short_name" : "11211",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Grand St/Bedford Av, Brooklyn, NY 11211, USA",
"geometry" : {
"location" : {
"lat" : 40.714321,
"lng" : -73.961151
},
"location_type" : "GEOMETRIC_CENTER",
"viewport" : {
"northeast" : {
"lat" : 40.71566998029149,
"lng" : -73.95980201970849
},
"southwest" : {
"lat" : 40.7129720197085,
"lng" : -73.96249998029151
}
}
},
"place_id" : "ChIJi27VXGBZwokRM8ErPyB91yk",
"types" : [
"bus_station",
"establishment",
"point_of_interest",
"transit_station"
]
},
{
"address_components" : [
{
"long_name" : "Williamsburg",
"short_name" : "Williamsburg",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Brooklyn",
"short_name" : "Brooklyn",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "New York",
"short_name" : "New York",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Kings County",
"short_name" : "Kings County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Williamsburg, Brooklyn, NY, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 40.7251773,
"lng" : -73.936498
},
"southwest" : {
"lat" : 40.6979329,
"lng" : -73.96984499999999
}
},
"location" : {
"lat" : 40.7081156,
"lng" : -73.9570696
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 40.7251773,
"lng" : -73.936498
},
"southwest" : {
"lat" : 40.6979329,
"lng" : -73.96984499999999
}
}
},
"place_id" : "ChIJQSrBBv1bwokRbNfFHCnyeYI",
"types" : [ "neighborhood", "political" ]
},
{
"address_components" : [
{
"long_name" : "Brooklyn",
"short_name" : "Brooklyn",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "New York",
"short_name" : "New York",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Kings County",
"short_name" : "Kings County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Brooklyn, NY, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 40.739446,
"lng" : -73.83336509999999
},
"southwest" : {
"lat" : 40.551042,
"lng" : -74.05663
}
},
"location" : {
"lat" : 40.6781784,
"lng" : -73.94415789999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 40.739446,
"lng" : -73.83336509999999
},
"southwest" : {
"lat" : 40.551042,
"lng" : -74.05663
}
}
},
"place_id" : "ChIJCSF8lBZEwokRhngABHRcdoI",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"address_components" : [
{
"long_name" : "New York",
"short_name" : "New York",
"types" : [ "locality", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "New York, NY, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 40.9175771,
"lng" : -73.70027209999999
},
"southwest" : {
"lat" : 40.4773991,
"lng" : -74.25908989999999
}
},
"location" : {
"lat" : 40.7127837,
"lng" : -74.0059413
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 40.9152555,
"lng" : -73.70027209999999
},
"southwest" : {
"lat" : 40.4960439,
"lng" : -74.25573489999999
}
}
},
"place_id" : "ChIJOwg_06VPwokRYv534QaPC8g",
"types" : [ "locality", "political" ]
},
{
"address_components" : [
{
"long_name" : "11211",
"short_name" : "11211",
"types" : [ "postal_code" ]
},
{
"long_name" : "Brooklyn",
"short_name" : "Brooklyn",
"types" : [ "political", "sublocality", "sublocality_level_1" ]
},
{
"long_name" : "New York",
"short_name" : "New York",
"types" : [ "locality", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Brooklyn, NY 11211, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 40.7280089,
"lng" : -73.9207299
},
"southwest" : {
"lat" : 40.7008331,
"lng" : -73.9644697
}
},
"location" : {
"lat" : 40.7093358,
"lng" : -73.9565551
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 40.7280089,
"lng" : -73.9207299
},
"southwest" : {
"lat" : 40.7008331,
"lng" : -73.9644697
}
}
},
"place_id" : "ChIJvbEjlVdZwokR4KapM3WCFRw",
"types" : [ "postal_code" ]
},
{
"address_components" : [
{
"long_name" : "Kings County",
"short_name" : "Kings County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Kings County, NY, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 40.739446,
"lng" : -73.83336509999999
},
"southwest" : {
"lat" : 40.551042,
"lng" : -74.05663
}
},
"location" : {
"lat" : 40.6528762,
"lng" : -73.95949399999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 40.7391407,
"lng" : -73.83363179999999
},
"southwest" : {
"lat" : 40.5703742,
"lng" : -74.04195919999999
}
}
},
"place_id" : "ChIJOwE7_GTtwokRs75rhW4_I6M",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"address_components" : [
{
"long_name" : "New York-Northern New Jersey-Long Island, NY-NJ-PA",
"short_name" : "New York-Northern New Jersey-Long Island, NY-NJ-PA",
"types" : [ "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "New York-Northern New Jersey-Long Island, NY-NJ-PA, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 41.6018065,
"lng" : -71.85621399999999
},
"southwest" : {
"lat" : 39.49853299999999,
"lng" : -75.3585939
}
},
"location" : {
"lat" : 40.9590293,
"lng" : -74.0300122
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 41.6018065,
"lng" : -71.85621399999999
},
"southwest" : {
"lat" : 39.49853299999999,
"lng" : -75.3585939
}
}
},
"place_id" : "ChIJ3YJV4PRWwokRFFI21ZrHXtQ",
"types" : [ "political" ]
},
{
"address_components" : [
{
"long_name" : "New York Metropolitan Area",
"short_name" : "New York Metropolitan Area",
"types" : [ "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "New York Metropolitan Area, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.0809059,
"lng" : -71.777491
},
"southwest" : {
"lat" : 39.475198,
"lng" : -75.3587649
}
},
"location" : {
"lat" : 40.7127761,
"lng" : -74.00595439999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 42.0809059,
"lng" : -71.777491
},
"southwest" : {
"lat" : 39.475198,
"lng" : -75.3587649
}
}
},
"place_id" : "ChIJ-5Z24NaGwokRiMh4Rj8FNMo",
"types" : [ "political" ]
},
{
"address_components" : [
{
"long_name" : "New York",
"short_name" : "NY",
"types" : [
"administrative_area_level_1",
"establishment",
"point_of_interest",
"political"
]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "New York, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 45.015865,
"lng" : -71.777491
},
"southwest" : {
"lat" : 40.4773991,
"lng" : -79.7625901
}
},
"location" : {
"lat" : 43.2994285,
"lng" : -74.21793260000001
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 45.0125923,
"lng" : -71.8562029
},
"southwest" : {
"lat" : 40.4961036,
"lng" : -79.761996
}
}
},
"place_id" : "ChIJqaUj8fBLzEwRZ5UY3sHGz90",
"types" : [
"administrative_area_level_1",
"establishment",
"point_of_interest",
"political"
]
}
],
"status" : "OK"
}
Another feature request just because I like to be a pita. Would there be a way to do display zone then formatted_address?
@mcfrojd I have made a change to my dev copy of the component give it a go. It uses the other server. you can keep an eye on how many requests it is making by using google api dashboard. This should fix your problem. Let me know how you get on? Iâll do a full release later on if it is working for you.
Still error with new dev code.
2017-08-02 15:06:41 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.asa_plats_t 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 "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/sensor/google_geocode.py", line 194, in update
if 'formatted_address' in decoded['results'][0]:
IndexError: list index out of range
@mcfrojd Thatâs really strange. Can you try not using secrets and putting your API key directly in the sensor.yaml file and see if that works.
Back to the api key I wasnât sure how hard theyâd let you hit that, now we do. As said I only hit it once a day with Tasker just to track where I laid my head that night.