I could use some help with a automation triggering problem I’ve been trying to work out. I’ve seen a couple of threads that seem to point to an answer but I can’t seem to put it together in my head.
I want to trigger an automation when the following exists:
The power reading of sensor.aeotec_smart_switch_6_power_10 is less than 3.3
-AND-
It has been in that state for more than 45 seconds.
I’ve tried a number of approaches and most have ended in syntax errors. It would be so easy if you could add a for statement to a numeric value state but that isn’t valid. I get the feeling I will need to create a template sensor for the power and then check the state of that sensor for the time value. But my mind is hurting from trying to figure out what is probably obvious to someone here so I’m reaching out for help!
Maybe not but it’s good to have another brain working on it. Mine hurts! I’ve been beating against the wall with this for a bit now.
I’m trying something using a boolean_input for the state and then measuring the time elapsed on that state and I’m going to see if that works, but if you come up with anything else - by all means, let me know!
Sadly, this produced the following error and failed the automations load:
Invalid config for [automation]: [condition] is an invalid option for [automation]. Check: automation->trigger->0->condition. (See /home/hass/automation.yaml:136)
Line 136 naturally points to this automation… DAMN! I thought we were on to something.
At the moment, there’s no way to combine numeric_state with the for-statement in any shape or form (hence the feature request). I work around it by making a template sensor for the value I want to test. And then I use that template sensor in a state trigger with the for-statement.
I’ve tried that in various ways but can’t seem to get it right. Any chance you could show an example? I’ve been really stuck here for over two or three weeks trying to get what should be a simple automation done and it’s driving me crazy!
I feel like this has been the missing piece for me. I knew this was the direction I wanted to go but I could never get the value template expression correct. It’s frustrating because I use value templates in other aspects of HASS and I have no problem - they work great. But for some reason I just couldn’t get it right with this one.
I’ll add this in and change my automation trigger as appropriate and let you know. I’ll restart later to see if the automations initialized properly and report that and then tomorrow, I’ll test it out in real life with a wash load.
Thanks so much for your help. Been really at a dead end on this.
So far so good; no errors on my restart and automations are fully loaded. I’ll post tomorrow with the final results as well as the actual code I used for my example (assuming it works).
I want to thank everyone here for their help and participation and patience as I’ve been trying this over a couple of weeks and threads. Thanks for putting up with me, guys.
Still not working as expected but made some progress. Let me recap; the goal was to get a notification when the washer and dryer were done by measuring the power levels on the two Aeotec Smart Switches I have them plugged into. I’m using a combination of template sensors, input booleans and automation scripts. For the dryer, it’s pretty easy - it’s either running or not. For the washer, I get power drops in between the cycles so I needed to put in logic to allow for power to drop for at least one minute, fifteen seconds to prevent the notification from firing prematurely.
Here’s what I know can be ruled out as being an issue:
The switches themselves. They are reporting fine and show the power levels in almost real time. They are both identical and both have the same firmware.
The template sensors. They are showing the correct states during each phase of the washer and dryer cycles. When the power level changes, the associated sensor displayed in the card changes immediately. Here are the template sensors:
#
# Automation Templates
#
# True when washer power level is below 3.4 watts, high threshold of resting state
# Default state is true
washer_pwrdn:
value_template: "{{ states('sensor.aeotec_smart_switch_6_power_10') | int < 3.4 }}"
# True when Dryer power level is above 0.1 watts, showing dryer is in operation
# Default state is false
dryer_pwrup:
value_template: "{{ states('sensor.aeotec_smart_switch_6_power_11') | int > 0.1 }}"
And here’s the code for the boolean_inputs:
washer_switch:
name: Toggle Washer Automation
initial: off
icon: mdi:water
dryer_switch:
name: Toggle Dryer Automation
initial: off
icon: mdi:sync
The only thing that could be left is in the automations themselves and here I have one half of each working. The Washer Start sequence works and toggles the boolean correctly, but the Washer Done sequence never fires. In the Dryer, it’s the exact opposite. The Dryer Start sequence never fires and toggles the boolean, but if I manually toggle it, the Dryer Done sequence works.
So the two problem areas are Washer Done and Dryer Start. There are no syntax errors. No errors in the logs for the automations and they all initialize correctly. Checked for spelling errors three times (but please check again) and found nothing wrong.
Ok don’t change everything. Integers are numbers without decimal points, that is why I think the template needs to change to float. This might not be the complete solution. I also notice that in the Washer code above: 3.30 is misssing the quotes around ‘3.30’
Edit: Is the state of the template sensors really true or false? I believe it should be on or off.