I want to realize a notification based on the current power of a switch.
My working automation which triggers if the current power is below a threshold:
automation dryer:
trigger:
platform: state
entity_id: switch.dryer
condition:
platform: numeric_state
entity_id: switch.dryer
value_template: '{{ states.switch.dryer.attributes.current_power_mwh }}'
below: 100
action:
service: notify.mypushetta
data:
message: "Dryer stopped because current power is {{ states.switch.dryer.attributes.current_power_mwh }}"
But it triggers everytime the state changes and is below 100 mwh. What I really need is that it only triggers once when the old_state was above 100 mwh and the new_state is below 100 mwh. Even after hours of trying I did not find an easy way to do that.
A workaround would be to use a variable within a template - is that necessary or can someone give me a hint for an easy solution?
Thanks for your replies!
I was trying to realize it with the numeric state before, but never got a message out of my rule. Copy paste from my configuration file:
automation dryer:
trigger:
platform: numeric_state
entity_id: switch.dryer
value_template: '{{ states.switch.dryer.attributes.current_power_mwh }}'
below: 100
action:
service: notify.mypushetta
data:
message: "Dryer stopped because current power is {{ states.switch.dryer.attributes.current_power_mwh }}"
One state change from yesterday where it should trigger, but (in contrast to the automation rule with the condition from my first post) did not result in a message using the numeric state:
Sorry, I should have written it more clearly. The snippet in my latest post is from my configuration file and seems to be exactly the same you posted. I tested it yesterday and did not get a message from it.
I do not understand why the numeric_state triggers does not work, but the benefit of the workaround is that as addition to the push message there is now a visual feedback in the frontend visualising that the dryer is running.
Hey
I have similar trouble using the numeric state trigger. I tried to work around with a template sensor, but that didn’t work out jet either. My guess is, that the numeric state trigger doesn’t work, because the return of the value_template is actually a string and not a number. Can this be or is that excluded?
Due to the fact, that the comparision in the value_template of the binary_sensor works (my last post), I conclude that it is a number and not a string.
automation:
- alias: "dryer"
trigger:
platform: state
entity_id: binary_sensor.dryer_running
from: "on"
to: "off"
As far as I see it, the state changes from “on” to “off” and not from 1 to 0.
Edit:
Ah now I see what you mean, you meant the: [quote=“byte-bender, post:11, topic:804”]
value_template: ‘{{ states.switch.dryer.attributes.current_power_mwh > 100}}’
[/quote]
Anyhow I think this are two different situations. Here we have a value_template and the comparison is done within the value_template. This works yep, but what is not working, is
I think, here HA evaluates the value_template first and then in a second step does the comparison. This then does not work, because now it checks if the return of the value_template is above 100 or not, but the return is a string and a string cant be compared to a number.
This might be wrong, its just what I think is happening.