Need help with rules

I have made some rules, for some broadlink, but some is for dumb devices, so same button do the same when on and off. My question is, is there a way to simplefy this in one rule, and not in two?
example:

rule “Enciende la tele”
when
Item Scene_TV_AOC_POWER received command ON
then
sendCommand(TV_AOC,“TV_AOC_POWER”)
end

//
rule “Apaga la tele”
when
Item Scene_TV_AOC_POWER received command OFF
then
sendCommand(TV_AOC,“TV_AOC_POWER”)
end

Thanks in advance :slight_smile:

Hi Fernando,

Please use code fences when posting code snippets

From what I can tell you want to differentiate between ON and OFF for the item Scene_TV_AOC_POWER, which I assume is a Switch :wink:

rule "Enciende la tele"
when
	Item Scene_TV_AOC_POWER received command
then
	switch (receivedCommand) {
		case ON : {
			TV_AOC.sendCommand(ON)
		}
		case OFF : {
			TV_AOC.sendCommand(OFF)
		}
	}
end

sendCommand(TV_AOC,“TV_AOC_POWER”) would send the actual string “TV_AOC_POWER”, which is not really what you want, I suppose.

To simplify even more you can just send on the receivedCommand to your TV_AOC

rule "Enciende la tele"
when
	Item Scene_TV_AOC_POWER received command
then
	TV_AOC.sendCommand(receivedCommand)
end

Also notice the different syntax to your example - more info about it here

thanks for the answer, i would try to explain better.

I have codes with broadlink to turn on and off my tv, since is a dumb tv use the same button to do both actions.

So if you actually need to send the string “TV_AOC_POWER” to your TV to turn it ON or OFF you can use the second example, just with

rule "Enciende la tele"
when
	Item Scene_TV_AOC_POWER received command
then
	TV_AOC.sendCommand(“TV_AOC_POWER”)
end

to send the string in both cases when Scene_TV_AOC_POWER recives either ON or OFF.

The only issues here is that you might want to catch multiple consecutive ONs or OFFs for Scene_TV_AOC_POWER, it these are a possibility.

Thanks for the answer help me to found the right one:

This work for me :slight_smile:

rule "Enciende la tele"
when
    Item Scene_TV_AOC_POWER received command
then
    sendCommand(TV_AOC,"TV_AOC_POWER")
end