How to prevent automation from running after restart?

I have an automation that is triggered once my energy consumption goes to 0. The problem is: whenever I restart the pod this automation is triggered once more.

I found some old posts about using home assistant uptime however soon I realized that this happens also when I restart mosquitto so I need a better way to do that.

After playing around with the configuration I found a way that seems to be working:

  • Create an Boolean input
  • Create an automation that set input to true once the energy consumption goes above 0
  • Add condition to my automation where input should be true and add an action to set it to false in the end of the automation

IMO this looks like a massive work for a typical use case so I wonder if there’s anything better. Does anyone have a better way to prevent the automation from running after restart?

1 Like
  trigger:
    - platform: state
      entity_id: sensor.my_sensor
      not_from:
        - "unknown"
        - "unavailable"
      to: "0"
5 Likes

@Edwin_D thanks!!! You are the best

1 Like

This no longer works. Results in a “Message malformed: extra keys not allowed @ data[‘not_from’]” error

Can you post more of the code where you put it in? Because it should still work in a trigger. Won’t work in a condition though.