Firstly yes you’ll need to use some form of scripting in order to do the more advanced functionalities.
Ideally you’d want to have one generic “rule” to deal with all the buttons / lights. You do this by using group member triggers.
Set all your buttons that would function the same way (although they’d activate their corresponding lights) into the same group, then trigger on the group member.
Then in your rule, you need a way to associate / link the button that triggered the rule, to the corresponding light that it should control. There are several ways to do this, the simplest way would be to use naming patterns. For example, your buttons are named:
- LivingRoom_Button
- BathRoom_Button
- FrontPorch_Button
and your lights are named:
- LivingRoom_Light
- BathRoom_Light
- FrontPorch_Light
See the pattern?
When LivingRoom_Button triggered your rule, it can deduce that it needs to control LivingRoom_Light, and so on.
So ONE rule, the same piece of code can handle all those buttons instead of writing 3 separate rules. One rule can handle 20, 30, unlimited number of button → light associations.
There are other ways of associating things, my favourite is using the Semantic model but it may be a bit more complicated than just using the naming system above.
Furthermore that same rule can handle single tap, double taps, triple, quad, hold, release, etc.
One piece of advice that I learned much too late in the game, is to use postCommand=true
in your MQTT thing channel setting for the button and use Received command
trigger. This is probably way TMI for you right now though, so we’ll circle back to it later once you’ve come up with a working rule.