I have a automation in which I track the current of a smart plug.
If the smart plug has a current of < 2 (watts) for 12 minutes I set a input boolean to true.
This works fine means I can correctly track when the device is done (in that case a washing mashine).
However: somehow, in the middle of the night, this automation kicks and sets the input boolean to true and I can not figure out why this happens.
If I look on the historical graph for the plug voltage current it was constantly at zero a long time before and after the automation was triggered.
any ideas what causes the automation to trigger for no reason?
You may want to create conditions that check that it is not unavailable or unknown, it could be that something is causing it to lose connectivity with HA and makes it think it just fell below 2. You could also put in some conditions that only allow it to run between certain times as well.
Check the automation’s trace when it executed at 03:00. The trace’s triggering information will report the sensor’s state-change (from and to) that caused the Numeric State Trigger to trigger.
If it shows the sensor’s state was briefly unavailable, follow CO_4X4’s advice and use a Template Condition to exclude unavailable as a previous value.
If the sensor is regularly reporting unavailable at 03:00, you may want to investigate what is scheduled to occur at that time. For example, perhaps your wireless router is set to reboot at 03:00 thereby causing the smart plug to temporarily lose connection to Home Assistant.
I have applied the template condition like in your example.
Follow up question:
If I understand this correctly trigger.from_state.state is a temporary variable accessable in the automation which references the state of the time the trigger ran?
Means e.g. if the state of a sensor was unavailable on trigger but 12 minutes later it would be back available it will check the state the sensor had on triggered time correct?
When an automation trigger is triggered, a trigger variable is created. The trigger variable has properties and they can vary depending on the kind of trigger.
Here’s what the trigger variable contains for a Numeric State Trigger. For your application, we are interested in the sensor’s previousstate so we will be using trigger.from_state.