Tweaking Automation using Energy monitoring plugs

I use TPLink HS110 smart plugs with energy monitoring to send notifications when my dishwasher is done with a cleaning and drying cycle. The issue I’m having is that the plug goes offline temporarily and somehow triggers the automation to run. I have it set to only run the automation once the watts goes under three for more than two minutes. any ideas for how to ignore when the device temporarily drops its connection?

  1. When it’s offline is its state value reported as unavailable?
  2. Post the automation.

yes. the value is unavailable. here is the automation

alias: Tell me when the washing machine is done
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.washer_current_consumption
    below: '10'
    for: '00:03:00'
condition: []
action:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.kitchen_display
      message: The washing machine is done
mode: single

I’m surprised that automation is triggered when the plug’s state is unavailable. How is sensor.washer_current_consumption related to the plug? Is it a Template Sensor or is it directly related to the plug’s integration?

I suggest adding an id to the automation with a unique value. For example:

alias: Tell me when the washing machine is done
description: ''
id: tell_me_when_washing_done
trigger:

It permits Home Assistant to create a trace every time the automation is triggered. The trace will show you why the automation was triggered.

The next time it gets triggered, when you believe it should not be triggered, the trace will reveal the details. For more information about traces, refer to Troubleshooting Automations.

sorry, the automation is triggered once the state is “turned on” and after the three minute wait period I set. the sensor.washer_current_consumption tells me what the current wattage is on the plug and is part of the integration. Here is what i see from another entity called switch.

Capture

No one is turning the plug off.

And i will add the id as well

When switch.washer becomes unavailable, what is the value of sensor.washer_current_consumption?

Does it also report unavailable or unknown or maybe 0?

I can pinpoint the exact time as you see in the screenshot i provided but i cant really get an exact measurement from the wattage based on the graph that home assistant provides from just clicking on the entity from overview, unless there is a better way. From what i can tell though, the wattage does not go to zero.

I tried to add the id and after i save and go back in, the id element is removed. Am I doing something wrong?

If you have created the automation using the Automation Editor, it automatically includes id but doesn’t show it. You can confirm it by simply checking if the automation produced a trace when it was triggered recently.

should i paste the trace here?

The trace is for you to analyze. When the automation is triggered when you claim it shouldn’t, that’s when you want to examine the trace and see what’s the sensor’s value that caused it to trigger.

Your Numeric State Trigger is configured to trigger only when the sensor’s value decreases below 10 and stays that way for at least 3 minutes. You claim it triggers even when the sensor’s value is unavailable. You will want to check the trace to see what is the actual value when this happens.

ok. thank you for you help. its much appreciated

one thing I wanted to run by you, see if this could make sense because I don’t see anywhere in the event where it says anything about the state. It might be that the plug once it was initially plugged in was seen as below the 10W threshold for more than three minutes and triggered the automation. after that, it waits until the next time it goes above 10W and then back down to trigger the automation. The plug’s state once it comes online again might be seen as resetting it’s below 10W status and therefore after three minutes triggers the automation. Does that make sense at all? I wonder if putting an above value in there will solve it. the only issue is that it doesnt sit above 1.7 W for too long before it drops below when the washer is not in use. Is it possible to do nested if then statements?

EDIT: I added a condition to the automation that hopefully deals with this issue. here it is:

alias: Tell me when the washing machine is done
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.washer_current_consumption
    below: '10'
    for: '00:03:00'
condition:
  - condition: numeric_state
    entity_id: sensor.dishwasher_current_consumption
    above: '3'
action:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.kitchen_display
      message: The washing machine is done
mode: single

That seems plausible but your Numeric State Trigger monitors the sensor’s state value, not the plug’s. The plug’s offline status has to reflect in the sensor’s state in order to affect the trigger’s behavior.

After the Numeric State Trigger has triggered, the sensor’s state value must first rise above 10 before it can be re-triggered when it decreases below 10 (and remains below 10 for at least 3 minutes). The rise above 10 is what “resets” the Numeric State Trigger. However, it is also reset when Home Assistant restarts and, unless I’m mistaken, by Reload Automations. Changing from unavailable to below 10 might also reset it but I have not tested it. However, in your case, we have yet to confirm it ever changes to unavailable and that’s why I suggested you examine the trace which reveals this information.

BTW, in the revised example you posted, the condition refers to a different entity (dishwasher vs washer).

Thank you for catching that.

looking at the unavailable to turned on state time stamps and the automation time stamps it looks like that state cycle is the issue. I will monitor and see what comes of the addition of the condition.

If the transition from unavailable to a value less than 10 causes it to trigger, you can add a Template Condition to block if trigger.from_state was unavailable.

condition:
  - condition: template
    value_template: "{{ trigger.from_state.state not in ['unavailable', 'unknown'] }}"

However your Numeric State Condition might work as well (as long as the state-change isn’t from unavailable to a value less than 3).