Some automations are triggered each time I edit other automations or restart the device

Hi

I have some automations which are triggered according to my light sensor level. I use a numeric_state trigger, whereas every time the lux level goes above or below a certain threshold, then action is triggered.

Everything’s working fine, except one thing - those automations are triggered every time I edit other automations (following a “save”), restart the device, or turning them on (after they were off). The ladder is really frustrating, because I have some automations in which I turn off the light-triggered automations and then turning them on again. Every time the automations are triggered.

How can I avoid that from happening?

It would be helpful to see the automations.

Here it is:

alias: Close shutters
trigger:
  - platform: numeric_state
    entity_id: sensor.average_light_level
    above: '500'
    for: '00:01:00'
condition: []
action:
  - scene: scene.ywgc6bmhhesddjbw
  - delay: '00:15:00'
mode: single

What is sensor.average_light_level at the time it triggers?

If it’s unavailable then you could probably add that as condition so that it does not trigger when it´s unavailable

Thanks, but I don’t think it’s that issue. It’s always available.
It’s just that once I reboot HA, it checks if the value is above 500, and if it does, it triggers the action.
I want it to trigger the action only when it goes from below 500 to above 500.

I have a hard time believing that. Did you check or did you just reply?

I checked that.

I agree with @Hellis81,
Is the sensor concerned an actual device or is it a construct ? (it looks like a construct)
Does the display of its value (at any point on its way to being used in the automation above) look like states.sensor-somethingelse ?
You may be falling victim to initialisation errors usually fixed by using states(‘sensor-somethingelse’)
Else you may need to put a condition in to ensure the trigger from state was a valid state

Edit, you may wish to look at some of @petro 's availability templates, they can cure many ills.
(just search for the term with Petro as the poster)

What version of HA are you using? The initialization behavior of the numeric state and other triggers changed very recently. Updating to the latest version of HA may solve your problem.

First, note that a numeric state trigger (like many, if not all, of the others) won’t “fire” unless one of the entities it’s monitoring changes state. So at the very least, if the trigger is firing, we know it’s because sensor.average_light_level changed state.

Next, previous behavior of the numeric state trigger would cause it to fire the first time the conditions were “met.” In this case, that would mean the first time the sensor changes state such that it’s numeric value was above 500 (and stayed above 500 for a minute) it would fire. Then, once it fired, it wouldn’t fire again until the conditions were no longer met (i.e., 500 or below, or it had a non-numeric value, such as unknown or unavailable), and then were met again (above 500 for a minute.) However, this behavior would “reset” (i.e., fire the first time the conditions were met) if the automation was disabled and re-enabled, which also happens when automations are reloaded, and when HA restarts.

The recent change “fixes” this inconsistency. Now it should only fire when it goes from the conditions being not met to being met (i.e., 500 or below to above 500.)

As explained by pnbruckner, unless you are using the latest release, that activity will reset a Numeric State Trigger.


FWIW, the practice of automations turning off/on other automations is not optimal. Disabling an automation shouldn’t be considered a normal part of automation logic; reserve it for the exclusive purpose of excluding the automation from normal operations. Use an input_boolean (in the automation’s condition) to control the behavior of its execution (i.e. when it should or should not execute its action).

Thank you guys for your help. I just updated my system to core-2021.3.3 which was only released in recent days, and that solved the issue.

Great tip. Thanks

You’re welcome!

Should you need to specify more modes of operation, you can use an input_select.