How to iterate over a timezone list in (python) to find country(code)

let me compare that with this:

At any rate, this is how you can identify the countries that use a given timezone, like this:

{country for country, timezones in country_timezones.items()
if timezone in timezones}

If you need to do lots of these lookups, you can of course build your own dict to make it faster and simpler:

timezone_countries = {}
for country, timezones in country_timezones.items():
for timezone in timezones:
timezone_countries.setdefault(timezone, set()).add(country)

And now it’s just:

timezone_countries[timezone]

which I posted earlier…

the TZ_INFO should in my original post be populated with the complete list of course, possibly loaded from file
TZ_MATCH would be the attribute.time_zone of the device_tracker listed in some config for the script

the print should the be replaced with has.states.set…

Yeah…

And that would not be that easy, hence my suggestion to use a custom_component/AppDaemon :slight_smile:

though I would still love to be able to do that, if only for educational purposes, this AD app using the geopy package is so much more precise, it is a bit scary really… many more details than the on the list, and dynamic at that.
Hope this is secure and no eavesdropping is possible.

Anything using a external webserver for any kind of data can theoretically be tracked.
This is the documentation for that lib https://geopy.readthedocs.io/en/latest/#

thanks! I will thoroughly read that :wink:

final question for now:
How can I comment in the configuration file? apparently AD doenst like the # I used, but since I do that all the time in my python scripts, I thought I could here also. Apparently not.

You can comment :thinking:

---
# Add stuff to device_tracker entities
address:
  module: address
  class: Address
  entity:
    - device_tracker.my_entity1
    - device_tracker.my_entity2

hi, getting back to the App please.
All of a sudden, I see incorrect time_zones popping up. May very well be they were incorrect before and I simply hadn’t noticed, but still.

On 2 of my devices, I see an incorrect time_zone, while the lat/lon are correct, and the address and country etc which is added by the App are all fine and perfect.

Does this App replace the time_zone? Or could it be the life360 has an incorrect time_zone.
it can’t be that when the lat/lon are correct, an incorrect time_zone is displayed (stating another city with a completely different lat/lon set…)

As far as I can tell that info is not added/replaced with that app.

update:
Have a look at the sample image in the repo, no TZ there :slight_smile:

thanks for confirming, Ill check life360 again for erroneous time_zones…
and indeed, my second system, still without the App has the life360 device with the identical erroneous time_zone. Never noticed that before!

so much the better we use the geopy component to check on lat/lon, and not have it do what I originally wanted, check for the time_zones… :wink:

update
to be in line with the discussion at the Life360 CC thread: above, read ‘time zone name’ where I wrote ‘time zone’…

@ludeeus
checking the sure code at Geocode would it be possible to also display a distance? its mentioned on the docs. Would be nice to have in the attributes.

seocndly, about the time_zone_names: would the timezone.py in the Geopy GitHub be any good in producing a correct time zone name. If so, could an attribute time_zone_name be added to the App (don’t want to overwrite the existing ‘time zone’ attribute of the device_tracker.

so the App could then add/append the currently added attributes for Address, and add Distance and Time zone name to that?

thanks for having a look!

quite, but it displays … indicating there’s more than displayed in the image… Tried to read through the code, but couldn’t find a list of attributes it creates for ‘address’

Here you can see a list of address info it returns https://nominatim.org/release-docs/develop/api/Output/#json

I don’t think TZ or distance calculations have a place in a app designed for address information.

Now would be a great time for you to take the next step in your AD venture, by creating two new apps, one to get TZ info, and one to calculate distance :+1:

Hi @ludeeus

I left an issue on the github, maybe you didn’t notice or it is offline:
would you please check whats up with the app address? I can’t get it to work after updating to Appdaemon 4.0.

discussed about that update here, though even that change from self.get_state(entity=entity) to self.get_state(entity_id=entity) or even self.get_state(entity) doesn’t solve the issue.

could it be the final set_state should be changed also?

thanks for having a look, if you can find a moment.

need to add a state. You’re setting the state attributes but not the actual state.

change

        attributes = self.get_state(entity_id=entity, attribute="all")["attributes"]

to

        stateobj = self.get_state(entity_id=entity, attribute="all")
        state = stateobj['state']
        attributes = stateobj["attributes"]

and change

        self.set_state(entity, attributes=attributes)

to


        self.set_state(entity, state=state, attributes=attributes)

thanks Petro, figured the bottom-line myself, and added the other change now too. I don’t see any errors logged anymore, but nothing I happening either…

could this then be important after all?

WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

no, add log lines and debug it.