Prevent automation from beeing fired after a restart of HA

Hi

when fiddling around with HA I restart the system many, many times a day. After each restart sun dependent automations (numeric_state) do fire:

- alias: 'Switch on lights at night'
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      value_template: "{{ state.attributes.elevation }}"
      below: 3.0
  action:
    - service: switch.turn_on
      entity_id: group.plugs_auto

According to the documentation numeric_state should fire when numeric value of an entity’s state crosses a given threshold. What they do. But they also fire on a restart of the system. How can I prevent them from being fired after a restart of HA?

Thx

Is that because it takes time to figure out the sun position and it reports 0 as default?
Can you try and restart and see what the number is when it’s fresh restarted?

If it is then maybe you can use the uptime as condition.
Say 5 minutes of uptime?

Interesting thought! Immediately after the restart:

image

So that’s probably not the reason. The automation fires later after a couple of minutes after the restart. But it should not fire in my opinion…

I added a condition to solve the issue but still first this is ugly and second I don’t think the trigger should fire in the first place.

  condition:
    condition: numeric_state
    entity_id: sensor.uptime
    above: 10

It could be a split second of the value being 0.
Perhaps if you remove this condition again and add a action to notify and the message is the sun variable.
That way you can see when it triggers you get a notification with what the state was at that time.

Have you considered a hardware solution? I have a number of Wireless Tags on doors and windows to sense opening, temperature, humidity etc.These can be armed and disarmed via Home Assistant, so I am using a spare one as a Night/Day flag (armed at night, disarmed during the day). The tag retains its value when HA is rebooted, so an automation can have a condition which checks the status of the flag before the rest of it runs.

In fact, each tag has three arming switches which can be on or off, so there’s quite a lot of scope for different uses. You just have to remember to change the batteries every couple of months, or everything grinds to a halt.

It works well enough for me with the sun.sun sensor. And I can work around the reboot issue with the mentioned condition. It’s just that I think that it is not the expected behavior to fire the automation after a reboot. But on the other hand I don’t know if it is a bug worth writing a bug report. Maybe it’s a feature and I missed it… :wink:

The uptime integration changed in 2020.12 and the usage and yaml in this thread are now outdated and don’t work.

Here is a thread on Condition Uptime to see examples of the current syntax and usage.