Best practice for minimising number of conditions / actions for similar

Hi

I am just getting used to using this powerful plugin and am trying to get my head around how to most efficiently use it. I can make things happen (mostly) the way I want them to, but I am not sure I am doing in the most efficient way. I will give an example. I have a set of conditions like the following, which use the s2 scene control features of Fibaro dimmers via device property inputs in PLEG. Each of these then has an associated action. Thing is, I want the same behaviour to be assigned to multiple switches through the house (basically they all control Sonos systems in the room), with the only difference being the target Sonos device. Is there a way of doing this without having a separate set of conditions and actions for each? For example, can I have a condition that tests which room the double click was from and determines the correct Sonos device to execute a common action on (eg play Radio 6 on sonos device )?

Conditions
Name Repeat Expression
KeSpotDblClick No (SceneActivatedkeSpots;LastSceneTimekeSpots) AND (LastSceneIDkeSpots == 24)
KeSpotSglClick No (SceneActivatedkeSpots;LastSceneTimekeSpots) AND (LastSceneIDkeSpots == 26)
KeSpotTplClick No (SceneActivatedkeSpots;LastSceneTimekeSpots) AND (LastSceneIDkeSpots == 25)
KeSpotHold No (SceneActivatedkeSpots;LastSceneTimekeSpots) AND (LastSceneIDkeSpots == 22)
LrSpotDblClick No (SceneActivatedlrSpots;LastSceneTimelrSpots) AND (LastSceneIDlrSpots == 24)
LrSpotSglClick No (SceneActivatedlrSpots;LastSceneTimelrSpots) AND (LastSceneIDlrSpots == 26)
LrSpotTplClick No (SceneActivatedlrSpots;LastSceneTimelrSpots) AND (LastSceneIDlrSpots == 25)
LrSpotHold No (SceneActivatedlrSpots;LastSceneTimelrSpots) AND (LastSceneIDlrSpots == 22)

Thanks again.

You should be able to code a condition so that its value depends on the source of the trigger. Something like:

SpotClick yes (SceneActivatedkeSpots;LastSceneTimekeSpots) ? 1 : ((SceneActivatedlrSpots;LastSceneTimelrSpots) ? 2 : SpotClick)

This should only change value when one of the triggers occurs and should then have the value 1 or 2 depending on the source. In your Action for this condition, you can have some Lua code that runs whatever operations you need on the basis of the values of SPOTCLICK.state and LASTSCENEIDKESPOTS.state or LASTSCENEIDLRSPOTS.state.

Ok, so I don’t have to specify LASTSCENEIDKESPOTS.state etc in the condition to use them in the action?

In terms of the LUA code, I am a bit of a noob on this as well though I do have some scripting skill so it won’t take me long to pick up… Can I call the .state values directly in the LUA code, or do I have to use luup.variable_get to pull these in?

Thanks

Lua code in a PLEG Action can reference any Input or Condition directly. The name must be specified fully upper-case and the .state suffix gets you the current value. I recommend you treat the variables as read-only. Changing the values could have unpredictable effects on PLEG logic.