states return states, not entity_id’s. If this is a device tracker that you are refering to, then it will return the friendly name of your zone, not the zone entity_id.
Turn logging on to debug and watch a device tracker when it changes zones. It will have 5 attributes in it, 2 strings and 3 dictionaries. The one string will be the entity_id that sparked the trigger, i.e. your device_tracker. The other string will be the platform, which should be just the word ‘state’. Two of the dictionaries are to_state and from_state. The last should be the ‘for’ dictionary if you have a duration attached to the trigger that fired it.
There should be a ton of info inside the to_state and from_state: entity_id, state, and attributes (all the device_tracker information). It will not contain any zone information accept the zone friendly name as the state.
So, if you want the zone object, what you’ll need to do is search the zones for the zone entity_id via the zone friendly name.
{% set zones = states.zone | selectattr('name','eq', trigger.to_state.state) | list %}
{% if zones | length >= 1 %}
# get the first zone that is equal to the zones in the to_state
{% set triggerzone = zones[0] %}
states.zone are all zones with the prefix zone (check {{states.zone|list}} in the dev-template) and all of their attributes
in my template, I simply take care that the to_state or from_state are in the list of states.zone. If yes, the template checks and the automation continues.
I do not need all the attributes, but simply their state. (entity_id’s) so I filter these out by using
{{states.zone | map(attribute='entity_id')|list}} and compare the trigger.to_state.state and from_state.state to this:
{% set zones = states.zone | map(attribute='entity_id')|list %}
{{trigger.to_state.state in ['home','not_home'] or
trigger.from_state.state in ['home','not_home'] or
trigger.to_state.state in zones or
trigger.from_state.state in zones}}
I cant really understand how what you suggest does the same for me? Should I read it as : if the trigger.to_state.state is in the list, the list length >= 1, so get the first zone equal?