Automation triggers at 3AM - can´t figure out why

Hi,

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?

thanks!

configuration:

alias: Track Waschmaschine End
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.plugwaschmaschine_energy_power
    below: "2"
    for:
      hours: 0
      minutes: 12
      seconds: 0
condition: []
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.task_waschmaschine
mode: single

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.

1 Like

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.

Example

condition: 
  - condition: template
    value_template: "{{ trigger.from_state.state != 'unavailable'}}"

EDIT

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.

2 Likes

Unavailable to 0 could definitely trigger this.

Look at the automation trace to see why it triggered:

2 Likes

thanks it indeed looks like the state was unavailable:

from_state:
    entity_id: sensor.plugwaschmaschine_energy_power
    state: unavailable

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?

Thanks again for your answer!

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.

Automation Trigger Variables

Here’s what the trigger variable contains for a Numeric State Trigger. For your application, we are interested in the sensor’s previous state so we will be using trigger.from_state.

trigger.from_state contains the sensor’s previous State Object which also has several properties.

The property we want is state so the final form of the variable we will use is trigger.from_state.state.

1 Like