Fastest rule for lights (scenes)

Hi

I have a Nodon wall switch wich control one spotlight and one ceiling lamp. Ceiling lamps zwave switch Fibaro builtin wit two switches is set to have Non remote 2+4 as lifeline. For button 1+3 I have scenes running to control q2 of the same fibaro builtin switch.

In my case I just want all this to happen very fast as short latency as possible. My rule looks as follows. I’m trying to be able to insert the state in trigger line so it would be soemthing like this Item z16_scen received update <= 2.0 but can’t get it to work. If I do this I need to have two diffrent rules which would be fine by me.

ule “NODONREMOTE”
when
Item z16_scen received update
then

if (z16_scen.state <= 2.0 && z13_q2.state==OFF ) {
	logInfo("Remote Nodon", "Rule: Spotligt på via scen")
	sendCommand(z13_q2, ON)
}
if (z16_scen.state >= 3.0 && z13_q2.state==ON) {
	logInfo("Remote Nodon", "Rule: Spotligt av via scen")
	sendCommand(z13_q2, OFF)
}
end

/Regards Marcus

Quick tip
Use:

z13_q2.sendCommand(ON)

instead of

sendCommand(z13_q2, ON)

Reasons there: https://www.openhab.org/docs/configuration/rules-dsl.html#myitem-sendcommand-new-state-versus-sendcommand-myitem-new-state

Hi That’s a good point. Scripting as you suggested makes all rules more compatible. But is there no way to get the rule to fire on for instance

received uppdate == 2.0, now it all depends on that state hav been updated and some times rule won’t fire.

I must say I read instrictions but couldn’t find any good way of doing that and still keep one extra condition.

Several people have reported that using the new rule engine with for instance Jython (“Python on JVM”) runs considerable faster than DSL.

However, for a simple rule like this, the bottleneck is not in the rule processing but in the overall event processing within openHAB and of course the system it runs on.
You should probably better off focusing on the use of timers and ‘competing’ rules and the system as a whole for low latency/speed and not so much in this rule.

BTW, make sure not to avoid the use of primitives (int, float, …) but only Java Number type objects. DSL is known for being extra slow wiith that.

I think it works a little bit quicker if you trigger on command instead of update (first happens the command, later the update). That in combination with receivedCommand it will be a little bit faster :wink:

rule “NODONREMOTE”
when
   Item z16_scen received command
then

if ((receivedCommand as Number) <= 2.0 && z13_q2.state==OFF ) {
	logInfo("Remote Nodon", "Rule: Spotligt på via scen")
	z13_q2.sendCommand(ON)
}
if ((receivedCommand as Number) >= 3.0 && z13_q2.state==ON) {
	logInfo("Remote Nodon", "Rule: Spotligt av via scen")
	z13_q2.sendCommand(OFF)
}
end

Hi

I tried the suggestion above but rule wouldn’y fire at all. I think I read somwhere that som or perhaps all wallswitches only send updates and not commands. I’m not shur I’m right.

Mmm, strange, as far as I known only sensors give updates and switches or controllers send commands.
But I can be wrong.