Rule for switch status based on dimmer

Hi Guys,

I want to create a rule to switch on a light bulb whenever a dimmer value > zero and swich it off when the dimmer value = 0

openHAB version: 2.5.4-1

items:

Switch WK2Licht_1   "Licht WK2_1" <light> {channel="zwave:device:xXXxXXXX:nodeX:switch_binary"}
Dimmer DimmerNHC_WK2 "NHC Dimmer WK2" <Light> {channel="nikohomecontrol:dimmer:xXXxXXXX:xx:brightness", channel="zwave:device:xXXxXXXX:nodeX:switch_dimmer" [profile="follow"]}

i’ve been struggling to get this to work, it throws an error in the log (" no viable alternative at input ‘item’ ") at the 3rd line of code below:

Rule file:

rule “NHC-ZWAVE Rule”
when
item DimmerNHC_WK2 received command
then
if (receivedCommand = 0) WK2Licht_1.sendCommand(OFF)
else WK2Licht_1.sendCommand(ON)
end

can anyone point me in the right direction?

thanks!!

Just a typo, needs Item here with capital I

wow, thanks! Syntax and I have never been friends :slight_smile:

for some reason i also needed to change receivedCommand = 0 to receivedCommand == 0 and it works!

1 Like

just for reference: this is the code that finally got it to work:

rule “NHC-ZWAVE Rule”
when
Item DimmerNHC_WK2 changed
then
if (DimmerNHC_WK2.state == 0) WK2Licht_1.sendCommand(OFF)
else WK2Licht_1.sendCommand(ON)
end