As I’m creating a set of rules to control my LED Strips (creating JSON strings to pass via MQTT), I find myself wishing there was a way to use one rule (with event triggers called out for each of my 10+ strips), rather than having to create a new rule for EVERY strip.
E.g.
rule "LED Strip 1 Intensity"
when
Item LEDStrip_1_Intensity received update
then
LEDStrip_1_String.sendCommand("{\"brightness\":" + LEDStrip_1_Intensity.state + "}")
end
rule "LED Strip 2 Intensity"
when
Item LEDStrip_2_Intensity received update
then
LEDStrip_2_String.sendCommand("{\"brightness\":" + LEDStrip_2_Intensity.state + "}")
end
…and so on, could be replaced by:
rule "LED Strip Intensity"
when
Item LEDStrip_1_Intensity received update or
Item LEDStrip_2_Intensity received update
then
if (updateObject == LEDStrip_1_Intensity) {
LEDStrip_1.sendCommand("{\"brightness\":" + updateObject.state + "}")
}
else if (updateObject == LEDStrip_2_Intensity) {
LEDStrip_2.sendCommand("{\"brightness\":" + updateObject.state + "}")
}
end
I realize I could simply use a single rule with triggers for all my strips, and send the current state of every strip’s Intensity slider any time either of them is updated, but that’s a wasteful hack (puts extra unnecessary MQTT traffic on the broker).
Is anything like this possible in the rule engine/language? I know receivedCommand and previousState already exist as implicit variables in rules, so it seems like adding a variable that stores a reference to the actual object that triggered the rule should be possible, right?