Original thread: Notify Entering and/or Leaving Zone
Thanks for this blueprint. I ran into a problem where notifications worked for the Home zone but never fired for custom zones, and I think I’ve tracked down why.
The problem
The blueprint sets zone_state to the zone’s friendly name lowercased:
zone_state: '{{ states[zone_entity].name|lower }}'
It then compares that against trigger.from_state.state and trigger.to_state.state as-is. For the Home zone this works, because the person entity’s state is the lowercase string home. For any custom zone, though, the person’s state is the zone’s friendly name with its original capitalization (for example Springville Elementary). The lowercased zone_state (springville elementary) never matches, so both if conditions are always false and no notification is sent. The automation still triggers and the trace shows it finishing, but neither action runs.
This may explain some of the earlier reports here where the new state was a custom zone name but nothing was sent. In my case, the person entity’s history showed the correct zone names, and the traces showed both conditions evaluating to false.
The fix
Lowercase the person’s state in the two conditions, so both sides of the comparison are lowercased:
action:
- if:
- condition: template
value_template: '{{ notify_when_leaving == true and trigger.from_state.state|lower == zone_state and trigger.to_state.state|lower != zone_state }}'
then:
domain: mobile_app
type: notify
device_id: !input notify_device
message: '{{ person_name }} has left {{ zone_name }}'
- if:
- condition: template
value_template: '{{ notify_when_entering == true and trigger.from_state.state|lower != zone_state and trigger.to_state.state|lower == zone_state }}'
then:
domain: mobile_app
type: notify
device_id: !input notify_device
message: '{{ person_name }} has entered {{ zone_name }}'
Nothing else changes. It’s harmless for the Home zone, and custom zones now match regardless of capitalization. After patching, I got enter and leave notifications for custom zones as expected.
@Sjorsa, if you’re still maintaining this, it would be great to see it folded into the blueprint. Happy to share traces if useful.