Automation triggering way too often

Looks like HA is triggering this based on some type of update pattern.

Here is my trigger:

trigger:
   - platform: state
     entity_id: device_tracker.my_phone

I don’t have a to: state condition because I want this to be called whenever there is a state change. Anyone have any idea how to avoid this? I am going to try a condition using an input text to store the last state, but seems like this shouldn’t be happening.

I am on Hassio v0.85.1.

I just implemented this yesterday and it seems to be bogging down my raspberry pi since this automation calls a template loop with 36 iterations and its being called 16 times per minute.

The automation triggers when an attribute changes.

Try this:

   - platform: state
     entity_id: device_tracker.my_phone
     to: 'home'
   - platform: state
     entity_id: device_tracker.my_phone
     to: 'not_home'

this is kinda bad programming. Depending on what device tracker you’re using and the type of phone this is just going to fire all the time. The amount of overhead is going to be insane.

What is your overall goal here? are you using an consider_home or an interval argument in your device tracker setup?

I am attempting an automation to track the path that I am taking on my way home from work. So I have 36 zones. 18 zones from grabbing if I am taking my car route home, and 18 if I am taking my bike route home. The loop checks if my phone’s state hit one of those zones, but my understanding is that the event should only fire if my new state is different from my old state. I can’t use one zone to grab my location, because the travel paths are too close together to use a circle. I need a rectangle to grab my travel path.

@dennis84de, if I use your method, I will need to list 39 triggers… and more if I add more zones in the future.

@forsquirel are you staying that each time my phone updates it’s location this event is firing? Or is this based on HA’s interval for checking device_trackers? I put in a condition that seems to be working. The condition checks that I haven’t already updated a text_input to my current zone.

with what you had originally it will fire anytime there is a state change. If your phone sleeps and loses connection it fires, and when it wakes and regainst connection it fires, etc…

Why are you tracking all the zones? I mean if you need something on when you get close, there’s a way to do that, Templating Closest entity.

Also, if you’re using owntracks you can just publish event data that says what zone you’re in when you enter it to a sensor and just fire an automation when that sensor state changes since it will only change when you change zones.

A state trigger with no to: or from: will fire whenever the entity’s State Object changes. That’s whenever the “state string” (i.e., state.state) changes, or when any attribute changes. For a GPS-based device_tracker like you’re using, this will be (at a minimum) whenever the entity’s GPS coordinates change. Depending on the tracker, that can be quite often.

If you just want the automation to trigger whenever the entity’s “state string” changes, you can add a condition like this:

  condition:
    condition: template
    value_template: >
      {{ trigger.to_state is not none and trigger.from_state is not none and
         trigger.to_state.state != trigger.from_state.state }}
2 Likes