Troubleshooting a simple automation that didn't trigger

In my attempt to learn Home Assistant all it’s different facets I am attempting some very basic automations. Simply put I have an automation that will create a notification in Home Assistant when I enter a specific area. The code I am using is:


- alias: Notify HA when James is at Didcot
  description: ''
  trigger:
  - entity_id: person.james
    event: enter
    platform: zone
    zone: zone.didcot_station
  condition: []
  action:
  - data:
      message: James is at Didcot
    service: persistent_notification.create

Last night, the automation worked fine. This morning when I entered the zone again nothing happened. I could see within the front end that the person was polling as being in the zone but for some reason it didn’t trigger. Is there an easy way for me to troubleshoot why?
I looked in the logbook and I could see the entity entering the zone.
I checked the logs and there were no obvious errors around that time.
So I am a little stumped. Any help would be greatly appreciated.

Open Up Dev Tools, go to States tab.

search for “automation.notify_ha_when_james_is_at_didcot” and check the ‘last triggered’ attribute.

This will be the last time the automation actually fired (trigger happened and all conditions were passed).

If this time matches when it was supposed to happen, the problem was with the action, not the trigger.

You didn’t specify the notifaction_id in the data, so it will not overwrite the notification if one was already there (i.e. it won’t pop up a new one). If you didn’t ever dismiss the first one, this one wont pop up.

To test the actions, open the service tab and call

automation.trigger
entity_id: automation.notify_ha_when_james_is_at_didcot

This will bypass ALL triggers and conditions and skip to the actions. Keep in mind, if you rely on trigger.XXX templates in the actions, this will be undefined.

As for debugging missed triggers…that is kind of tricky. I’m not exactly sure how to do that. I usually test the triggers in the states page by setting entities to states manually. You should be able to set person.james zone attribute from the state page. This ‘might’ trigger a zone enter event…though it is probably more complicated than that honestly.

Thanks. Unfortunately(!) it did fire the next time I entered the zone which was before I saw your message so I couldn’t check the states tab. However, now I know what to do when it doesn’t happen again.

I have had problems before with the zone enter trigger being a bit hit and miss. Somebody here suggested changing it to a trigger on the state of the person entity instead and it has been much more reliable. The main difference is that, you need to use the zone name from your config rather than its entity id.

It would look something like this (assuming that the name of the zone is “Didcot Station”):

- alias: Notify HA when James is at Didcot
  description: ''
  trigger:
  - entity_id: person.james
    platform: state
    to: Didcot Station
  condition: []
  action:
  - data:
      message: James is at Didcot
    service: persistent_notification.create

Thanks, I’m going to give that a go and see how well it works.

So far that has seemed to worked a treat so thanks very much!

As I said in my first post I’m using this to learn HA so I’ve now updated my code to look like this:

- alias: Notify when James enters or leaves a zone.
  description: ''
  trigger:
  - entity_id: person.james
    platform: state
  condition: []
  action:
    data_template:
      message: >
        {{ trigger.entity_id }} just changed from {{ trigger.from_state.state }}
        to {{ trigger.to_state.state }}
    service: persistent_notification.create

The problem is that even if I’m still in the same zone this still gets triggered every now and then. The message even says the state hasn’t changed. What I am trying to do is make the automation a bit smarter and send a message when I either enter or leave a zone instead of creating lots of separate automations.

Also do you know if there is a way of showing the friendly name of the entity?

Not sure if I should be breaking this out into a separate post…

This will trigger on attribute changes as well. So you should put a condition to check that from_state != to_state.

      - condition: template
        value_template: >
          {{ trigger.to_state.state is not none and
             trigger.from_state.state is not none and
             trigger.to_state.state is in ['home','not_home'] and
             trigger.to_state.state != trigger.from_state.state }}

Now it should only trigger on real state changes.

Also, trigger.name should give you the friendly name of the person with the fallback of giving the object_id if no friendly name exiss.