I’ve got a TV. I turn it on using a switch (Broadlink RM mini 3) and then I check a z-wave wall plug, and if the power draw is more than 100W I assume the TV is on. This is the config:
My problem is this: because there is a delay between the switch turning the TV on and the wall plug reporting the power usage, first the switch indicator turns on when I click it, then it turns back off because the reported power usage doesn’t indicate that it is on, then a second later it goes back on because the power usage is updated. Is there a way to increase the delay before the switch indicates that it didn’t turn on?
I browsed the code a bit and, honestly, I didn’t try to fully understand it. But I have an idea that may or may not work. Try adding a delay to the turn_on and turn_off actions:
My theory is, the template switch’s state will update whenever the entity referenced in the value_template changes. But, it must also update in response to the switch.turn_on and switch.turn_off service calls (i.e., changing to ‘on’ after turn_on finishes, and to ‘off’ when turn_off finishes.) So, I’m guessing (hoping ) that by adding the delays will cause that state change in response to the service calls to be delayed. If it delays long enough for the value_template to agree with it, then that will hopefully solve your problem.
I got around this by using a template binary sensor and a script to do the control.
I’m using it to turn off my computer - when I turn it off though it sends a shutdown command first to gracefully shutdown before turning off the power to the smart plug. The way I’ve got round it is having the value_template linked to the binary sensor.
the binary sensor is on whenever the smart plug is on and the shutdown script isn’t running. so when I press the switch in the UI this runs the script resulting in it turning off in the UI and not coming back on. The script has the delay in it which prevents any false positives.
I know I am digging up and old thread but I cannot really follow the solution provided.
I am having a similar issue to the one in this post. I use a broadlink RM mini 3 to turn on and off my A/C from HA and a Wyse sensor as a binary sensor to determine the current state (as it may already be turned on/off from the original IR remote). I am using a template switch but when I turn it on in HA the switch immediate returns to the off position until the binary sensor triggers and it then displays as on again. Is there any way to add a delay to the trigger from the binary sensor so it doesn’t go ON -> OFF -> ON everytime I turn it on?
I don’t think my understanding of how the template switch works was very good a year and a half ago, so I’d take what I said back then with a huge grain of salt.
After re-reading the code, as far as I can tell, the state of the template switch will only change in response to the value_template rendering a new result (which only happens when the referenced entity or entities change.)
So, in your case, if the template switch changes to on, then off, then back to on, when you turn it on, then it would seem that must be what your binary sensor is doing.
Can you post your template switch and binary sensor configurations?
Any help would be appreciated. This is not a big problem because every still works OK - it is just annoying to see the toggle switch in HA flick back to OFF and then a few seconds later back to ON every time I turn the aircon on.
Look at the history of binary_sensor.wyzesense_bed_ac. Does it go on and off and then back on when this happens? Or look at it in the Logbook. Again, the state of switch.bed_ac_heat_22_templated will only go on then off then on if binary_sensor.wyzesense_bed_ac does.