The Event Trigger that’s been presented to you? That’s how it works. It detects the events produced by the physical device, not the associated entity’s state change.
Multiple triggers are logically ORed and cannot occur at the exact same moment in time (they may be separated by a few microseconds but that still means it’s not happening simultaneously).
So how about saving the previous value in a variable that we compare to in the condition check.
A variable that is set each time as an action when there is a button_pressed event. I don’t know how it works in Home Assistant but maybe someone can help me here.
How about creating a helper such as an input_boolean and always set it to the current state of the wall switch as the action after doing a conditional action that only runs if the input_boolean has the same state as the wall switch?
I prefer not to add an input_boolean. But maybe that is the way to solve the problem?
ON → Turn on speaker if previous state on wall switch was ON. Else OFF
ON → Turn on speaker
OFF → Nothing
OFF → Turn on speaker
ON → Nothing
The wall switch directly control the ceiling lamp in the room over 433Mhz and that is why I have this special requirement. I want to turn on the speaker without affecting the state of the ceiling lamp but using same button.
The speaker is then switched off after 2 hours automatically.
I thought I did in my first post but I can see now that I didn’t. I just had it in my head. I’m sorry it took 30 posts to get all the correct information about what I’m trying to do.
I will update my first post with that information to make this thread clearer.
But now that I think you understand what I’m trying to do. Do you have any suggestions?
Is it possible to do this without input_boolean?
I ask this because my next step is to convert this to a blueprint to be able to use this code in multiple rooms with the same type of setup.
Instead of directly determining the previous state, we should just be able to accurately assume the current state by evaluating how long it has been in the current state. In this example, if it has been that state for at least 4 seconds (you can fine tune the amount of seconds as needed, but I think 4 seconds should be safe. This value just effects how quickly you can sequentially turn on/off the switch and then turn on the music.)
This should perform the following:
When button press “on” occurs && swtich state has been “on” for at least 4 seconds → action passes
When button press “on” occurs && swtich state has just changed to “on” (e.g. has NOT been “on” for at least 4 seconds) → action fails/automation ends
When button press “off” occurs && swtich state has been “off” for at least 4 seconds → action passes
When button press “off” occurs && swtich state has just changed to “off” (e.g. has NOT been “off” for at least 4 seconds) → action fails/automation ends