The Issue tl;dr
I’m looking for a way to pass in a bunch of buttons (devices) into my script, sort them by model, and based on which model they are, create a set of triggers with trigger IDs for each one.
I want to use this tactic to improve my automations such that they only have to pass buttons to a script, and it can handle how to use those buttons based on the button model.
Extra stuff if you’re curious
I know it seems wonky, but I already have to do this for motion sensors. Once I added presence sensors, my motion sensors never go from “Clear” to “Detected” anymore, so if I turn off lights from a button, the lights don’t come back on when motion sensors are re-enabled because the state hasn’t changed.
To fix that, my script now takes a motion sensor field and controls when to turn on or off lights based on the state of the motion sensors. No more writing separate triggers for these.
In the same way, I’m hoping to do that with buttons. Pass in the buttons, based on the model, I want them to act all the same. Then, using trigger IDs, I can execute my script.
Blueprints?
Ideally, I’d use Blueprints for this as they’re designed for this use case, but Blueprints suck because they have no debugging UI, and they will break often as you’re building one out.
I use Home Assistant for the GUI, so that’s what I wanna use.
Another idea
I tried using Button Groups instead for this, but it doesn’t work anything like I’d intuitively expect.
Isn’t this the real issue?
Are you sure they don’t change? Have a look at the state of the entities in Developer Tools. They’re sensors - it seems unlikely that their behaviour would be different because of the presence of another sensor.
What do you mean by “when motion sensors are re-enabled”?
You’re right, this does sound like a trigger problem: if you turn on the light manually and there is no movement in the room it will never turn off - because the motion sensor has to go to “detected” before it can go to “clear”. It might be better to rethink the logic rather than create a pile of safety nets.
The “today” issue is the Clear to Detected problem, but that’s a symptom of a larger issue.
Being able to pass buttons to my script also solves a long-time issue of “how do I make it easier to add buttons to automations where I can’t screw it up”.
Just last night, I noticed I’d copy-pasted a device trigger wrong and put the wrong device ID for that button. Because I have to do that repeat action over and over when defining an automation and adding a button, it’s hard to make sure it’s perfect. And I have to go into YAML mode and copy-paste stuff.
I also wanna prove this is possible.
The fix for motion
I can fix the motion sensor issue using a “loop until”. Until what? Not sure yet, but if I move all the motion sensor logic to the script, that’ll fix this issue.
Since I’m going to be doing that, why not also pass in the buttons? I’ve been wanting to fix that problem for a while, and it’d be much easier if the script natively handled all of this, so it could be programmatic
Blueprints
Another fix for the multiple button issue is Blueprints, but until Home Assistant makes a GUI editor for Blueprints, I need another solution. I wasted hours trying to get a working Blueprint last time with virtually no debugging tools. Not doing that again.