you said you have 2 sensors. reporting the power of the tv and the stereo. it sounds like you have a smart tv with a direct integration connection to it. is that right?
if so, that integration is reliable in turning on/off the tv and also reporting whether the tv is on or off. is that right?
if that’s right, is the power sensor on the tv necessary and useful?
i definitely would not have a 5 second timer always checking.
if i understand your problem right, here’s what i would do:
-
create a helper switch (this ends up creating an input_boolean. let’s call it input_boolean.stereo) - this will represent the power state that we want the stereo to have.
-
how long does it take for the stereo to power on such that it’s ok to hit the toggle again? it sounds like if you hit the momentary toggle button too quickly, the second press fails. so how long of a wait is ok? for the below, let’s assume that’s 4 seconds… you can replace all the 4’s with whatever is right.
my first approach just to make sure things work is to put a damper on input_boolean.stereo. meaning that if it changes state, it needs to change states and stay in that changed state for 4 seconds. (trigger becomes state change for 4 seconds). that will prevent the issue you said about fast switching back and forth.
if it does trigger (new state for 4 seconds), then you synchronize the stereo to the input_boolean.stereo desired state. you do this by checking if sensor.stereo_power == input_boolean.stereo. ie if they are both on, or if they are both off. if they are the same (which may happen if you hit on/off quickly then wait) then do nothing. if they are not the same, then press you momentary button… which, presuming it works will then make the states the same.
i think that takes care of the fast bounce issue.
you said you wanted the tv and stereo to stay in sync. if you turn on the tv or stereo, the other turns on. you may be able to use this blueprint:
i would use this to sync your tv entity and the input_boolean.stereo entity. you didn’t say much about the tv entity so i don’t know what you’re using and if this blueprint will work for you. if it’s a media_player entity, it might not work since this is presuming the entities have “on” and “off” as its states, whereas the “on” state for a media_player is not always “on”. however if this blueprint doesn’t work, you can do it by hand easily enough.
caveats:
this approach would require that turning on/off the stereo is done via this input_boolean (which you can easily wrap a template switch around or just use it as an input_boolean). what i described above would not work to detect a manual ‘on’ of the stereo that then pumps the power sensor up then turns the input_boolean on. this can be addressed, but requires a bit more work.
this approach also introduces a bit of a delay (4 seconds) between when you ask the stereo to turn on / off before it actually turns on/off. this can be addressed with more work, but i haven’t gone into that. first wanted to run this approach by you and see if i understand the problem right and get your perspective on this solution…