Adding Switch Item

In OH2, in trying to work out a rule, I added to my items file a generic TestSwitch like below

Switch TestSwitch					"Test Switch"

The Switch is not associated with any kind of binding or group.

I add the switch to my sitemap and it shows there. But when I toggle it On and Off, I do not see any kind of entries in the log on it? So I’m sorta stuck in confirming if this rule is working

rule "Testing"

when
	TestSwitch received update
then     
	if (TestSwitch.state==ON) {
		sendCommand(FF_Light_FamilyLeft,ON)
	}
end

Try

Item TestSwitch received command

in the when clause and the built-in variable receivedCommand to access it.

Shouldn’t it read like that?

rule "Testing"
when
Item TestSwitch received command
then
if (TestSwitch.state==ON) {
FF_Light_FamilyLeft.sendCommand(ON)
}
end

Hello!

Since you’re going to use it only when it receives ON, I think it would be much easier to do it this way:

rule "Testing"
when
   Item TestSwitch changed to ON
then
   FF_Light_FamilyLeft.sendCommand(ON)
end

Do you have FF_Light_FamilyLeft item defined in your Items file? And what happens if you change TestSwitch to OFF? Do you just ignore OFF state?

Best regards,
Davor

Edit: @DocFraggle: I forgot it too. Thank you for the correction.

Hi, you forgot the “Item” at the beginning!

rule "abcd"
when
  Item TestSwitch received update
...
1 Like

This implied (to me) that it is being sent a command, so received command would be the more appropriate trigger.