Need help with broken automation

I would appreciate some help with an automation that stopped working.

For many years I have had a Fibaro Dimmer 2 where I used button 2 (S2) to use what Fibaro calls scenes (long press, single press, double press, etc) to control devices other than the lamp to which the dimmer unit is connected.

As an example I control other lights, roller blinds, Googe Home Mini’s, etc. I have several rooms with same similar device setups so I made one automation which I then copied and only changed which actions are performed depending on which room and devices apply. Those automations have worked great without making any changes through multiple versions of Home Assistant and even Zwave updates, but when I went from HA 2024.4.4 to 2024.5 all of a sudden the automations in all rooms started behaving super weird.

It appeared that the triggers were working as they should, but the actions would be more or less random. Same for all rooms using these automations. The weirdest thing was that the resulting action to me didn’t appear consistent. The same trigger could result in different actions at different times.

I always check the changelog before upgrading and didn’t see anything in the 2024.5 version that I can see should mess up my setup. I studied the trace logs for my automations but never could make sense of it. In the end I got tired and went back to 2024.4.4 and then everything worked fine again. So something appears to have changed between 2024.4.4 and 2024.5. When 2024.6 came, I tried to update again but got exactly the same behavior, i.e. actions performed inconsistently even though triggers seem to work. Backed up again to 2024.4.4 and then everything worked fine again.

I’m now at a point were I would like to be able to upgrade HA but I realize I need help to solve this. Does anyone have any input to why this could be?

My setup is this:
I use Home Assistant Container running on an Ubuntu 22.04 LTS server.
My Zwave controller is Zwave JS 2 MQTT running docker (version 12.13.0)
Aeotec Zwave Stick gen 5
To make the Fibaro zwave scenes more readable to the human eye I use HACS “event sensor”. I have two sensors that I use as triggers. One for which room (= which Fibaro dimmer 2 has activated the scene) and one for type of button press (= what scene on the Fibaro dimmer 2).

The automation is created in the web-gui but the code looks like this

Code on Pastebin

a little hard to help without more specifics.

can you post the trace where it’s not working right… describe exactly what should have happened, and what you saw happen instead?