Stateless rules and passed variables

Hi folks,

So Iā€™m starting to look at some pretty complex functionality in Rule Machine and I was wondering if Iā€™m missing a way of making my life easier.

I come from a programming background and I am used to creating stateless functions, principles of DRY and I find myself violating those rules a lot at the moment.

So, is their a way in Rule Machine to create an untriggered rule, that I can trigger from another rule and then pass some variables into for execution.

As an example, I have a button that toggles through various radio stations on my Sonos, it sets the volume, announces the station via TTS and tunes to the stream. At the moment I am having to replicate the sub rules for each radio station, or create a huge monolithic rule with a lot of Else If sections.

What I would love to be able to do, is have a main rule, that has the main Else If section, that then calls a sub rule and passes in the station name, requested volume, and station URL.

Taking it one step further, I have 4 speakers to write this for, so it would be amazing to nest these rules within another rule that passes down the speaker to target based on some more logic of which button on which room was pressed.

Now, I get the feeling from other peopleā€™s posts that this is kinda possible, but I think Iā€™m missing/not understanding how to implement it?

Apologies for my rambling!

Thanks

Gareth

I'm currently using global variables as a poor replacement of Rule inputs:

This works but the trigger rule needs to use something like Private Boolean as a lock to ensure there isn't concurrent triggering.

I have rules with no triggers. One of them is a lock the garage door but only if the door is closed. I call that rule from other rules. It certainly saves me from recreating the logic every time I have a rule that includes locking the garage door.

1 Like