Continuously monitoring power consumption and acting on values, not changes

Hi,

I am currently asking myself how to easily configure an automation which acts on a value of a sensor (in my case: power consumption of a Tasmota device), NOT on a change of that value. I am a bit surprised that this does not seem to be possible easily.

Basically I only want to continuously monitor the power consumption and perform an action on the value - regardless of any other trigger. Could someone please point me in the right direction?

Thanks!

if the value doesn’t change … for example, it stays the same all day… 24hrs. when do you want your automation to start doing something? every hour? every minute? looping constantly?

1 Like

More importantly why do you need “act” on a static value?

Can you explain your actual application for this so that we don’t waste time with an x-y problem?

https://xyproblem.info/

Thanks. More specifically:

  • I have a Tasmota Power Switch which powers my Coffee Machine (or Sonos Device, or Charger, or…)
  • Powering the Switch on does not necessarily mean that the connected device really gets used.
  • In this case I want to power off the Switch again after x minutes
  • However if the device gets used within the x minutes I want to power off the switch y minutes after the use.

Usage indication would be the power consumption of the device. Basically I am searching for an enhanced version of this: Turning of switch when power consumption is below X watt for Y minutes but I think my problem is that the trigger only happen at the point of the value change. Maybe I am on the wrong path, but I am totally stuck here.

Coming from FHEM I have something like this for this usecase which works perfectly well:

define Espressomaschine_Kueche_Check DOIF ([Espressomaschine_Kueche] eq "on" and [Espressomaschine_Kueche_Watt:state]>=7) \
(set Espressomaschine_Kueche_Betrieb on) DOELSEIF ([Espressomaschine_Kueche] eq "on" and [Espressomaschine_Kueche_Watt:state]<=5) \
(set Espressomaschine_Kueche_Betrieb off;; \
set Espressomaschine_Kueche off) DOELSEIF ([Espressomaschine_Kueche] eq "off") \
(set Espressomaschine_Kueche_Betrieb off)
setuuid Espressomaschine_Kueche_Check 6234d94d-f33f-bd54-6d2c-ac5dd127ec77b9be
attr Espressomaschine_Kueche_Check do always
attr Espressomaschine_Kueche_Check event-on-change-reading state
attr Espressomaschine_Kueche_Check wait 30:2700:0

Best would be to have this check starting when a power switch gets (better: IS) powered on.

Something like this:

trigger:
  - platform: state
    entity_id: switch.coffe_pot
    to: 'on'
    for:
      minutes: 5
condition:
  - condition: numeric_state
    entity_id: sensor.coffee_pot_power
    below: 50
action:
  - service: switch.turn_off
    target:
      entity_id: switch.coffe_pot

This will trigger 5 minutes after the coffee pot has been turned on and if the power is low it will turn off the switch. If however the power is high, indicating the coffee pot is in use, it will not switch off. Please adjust the power and time to suit your needs.

Use another automation for this:

trigger:
  - platform: numeric_state
    entity_id: switch.coffe_pot_power
    below: 500
    for:
      minutes: 5
action:
  - service: switch.turn_off
    target:
      entity_id: switch.coffe_pot

This will only trigger after the power has been above 500W and then falls below 500 and stays there for 5 minutes. Again, adjust the power and time for your use case.

Thanks for this, will check. However:

condition:
  - condition: numeric_state
    entity_id: sensor.coffee_pot_power
    below: 50

would only trigger when sensor.coffee_pot_power comes down from a higher value and falls below 50 - no? This would not work for me since after powering on the value will stay at about 0…

It is not a trigger. It is a condition that is only checked after the switch state trigger occurs. If the power is below 50 the condition passes and the actions are run.

meh… ok, thanks. I was blocking myself having in mind that I need to do what I want in one automation for whatever reasons…

Looking at the ruleset now makes it clear to me. Sorry for bothering with this, but sometimes a little “push” helps a lot! Have a nice weekend!

1 Like

No probs. Happy to help.

I tend to resist the urge to put everything in one huge complex automation. Often it is much easier to break what a want down into multiple simple automations based on cause and effect (trigger and action). Easier to write, easier to debug.

Hm. Testing this showed that the second automation will not trigger as I would have wished (but maybe not clearly explained).

My intention is to have the coffee machine on after it was in use for a given amount of time. Given the fact that I set minutes to 30 for both automations and I use the coffee maker 15 minutes after it was powered on, the first automation will kick in 15 minutes later and power it off. However I want to have it on for another 30 minutes after use…

Any hint on this?