My switch won't update

Hi,

i’m very new to this and i’m start to learn to program.

I have a switch and a dimmer.

When the dimmer changes, the switch needs to turn on
When the dimmer changes to 0, the switch needs to turn off

It works but i need to tick twice on the zero to turn the switch off

//test
rule “SyncLivingSpots”
when
Item LivingSpotsDimmer changed
then

	if (LivingSpotsDimmer.state == "0"){
		LivingSpotsSwitch.sendCommand(OFF) 			
		}
		else {
		LivingSpotsSwitch.sendCommand(ON)
		}

end
//

Thx

Are you 100% that 0 is the right value for the dimmer? I know an old dimmer I had didn’t like 0 as a value, it took values 1-99 for brightness and on / off for 0 and 100…

What the state of an Item can be depends on what type of Item it is.
Here, you are comparing it with a string, “0”
Maybe it’s a Dimmer type Item, with a numeric percent state?
if ( (LivingSpotsDimmer.state as Number) == 0 )

In my paperui it’s 0% and if i click twice it works

image

tried it but it didn’t change a thing…

i think it’s something about the delay

What “it”? There’s a switch and a slider and a tickbox.
Is that one of the Items referenced in your rule? Can’t tell.

Maybe you could look in your events.log, and see what the sequence of events actually is.

Just a switch and a dimmer/slider and i want them to work simultanoas

What kind of Item ? Is it UoM ? If so, try:

if ( (LivingSpotsDimmer.state as Number).floatValue == 0 )

which will remove the Suffix “%”

Thx this was the solution the suffix was the problem.

Finally :wink:

…at the very end, a little rule which shows you how a comparison with UoM-Items can be done.

rule "Rain warning"

when
    Item Dummy changed

then
    if(localHourlyForecast3RainVolume.state<0.1 | "mm") {
       logInfo("RainVolume","RainVolume with Pattern: " + localHourlyForecast3RainVolume)
     } // works
     if( (localHourlyForecast3RainVolume.state as Number).floatValue < 0.01) {
       logInfo("RainVolume","RainVolume as Float for comparison: " + localHourlyForecast3RainVolume)
     } // works
     var vRainVol = (localHourlyForecast3RainVolume.state as Number).floatValue
     if( vRainVol < 4) {
       logInfo("RainVolume","RainVolume with changed Variable: " + vRainVol)
     } // works
end

Have fun with tinkering :wink:

P.S.: Pls. mark the topic as solved, if so !

2 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.