I have created the following flow : dpaste/9PJ1p (JSON)
When a button press event is detected, the flow performs different actions based on the type of press detected (single, double, or long press).
For a single press, the flow sends a Wake-On-LAN (WOL) magic packet to wake up my PC. For a double press, it sends two WOL magic packets, first to wake up the same device and then to wake up my LG TV. Regarding the double press :
the flow checks the state of a media player device (
media_player.webos_tv ). If it is off, the flow turns it on and sets the input source to "PC". If the media player is already on and the current input source is not "PC", the flow changes the input source to "PC". Additionally, the flow controls a Samsung soundbar (
media_player.samsung_soundbar_q950a ) by setting the sound mode to "standard" and the volume to 20%.
The state checks are necessary because the TV requires some time to turn on, and if it hasn't turned on yet, the subsequent commands will not be executed. Additionally, I have a Google Chromecast that automatically switches to its HDMI port when the TV is turned on. Another issue is with the Samsung soundbar, which tends to switch to ARC mode when the TV is turned on. Therefore, the last check is to ensure that the audio is forced to go through HDMI1.
The issue arises in the last check loop, which becomes infinite. I have three 'current state' nodes, where the first two check the 'media_player.webos_tv' entity, while the third one checks the 'media_player.samsung_soundbar_q950a' entity. The problem is that the message payload that comes after the 'current state' node with the 'media_player.samsung_soundbar_q950a' entity passes the payload message of the 'media_player.webos_tv' entity and not the one of 'media_player.samsung_soundbar_q950a' entity, which I expect it to be. I cannot understand why.