Rule IF Then problem

IMHO the missing {} around the intended else statement lets this statement be run in any case!

That didnt do the trick but thanks

You made need to tell us what your Item type is. Or add a logInfo() to your rule before the ‘if’ so that you can find out what state it actually has.

logInfo("myRule" "value is " + FF_bedroomHUE_chr.state)

Hi

I don’t know if this will help you at all, but the rule I’ve posted here has a couple of IF statements in it that work for me.

Now my rule looks like this

rule "Hue seng chr"
when
Item FF_tryk_seng_test changed from OFF to ON
then
logInfo("myRule" "value is " + FF_bedroomHUE_chr.state)
if(FF_bedroomHUE_chr.state == OFF) {
FF_bedroomHUE_chr.sendCommand(ON) 
}
else 
{FF_bedroomHUE_chr.sendCommand(OFF) 
}
end 

But i get this warn

2018-08-11 21:25:13.763 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Hue.rules' has errors, therefore ignoring it: [29,18]: missing ')' at '"value is "'

[29,55]: mismatched input ')' expecting 'end'

When i run the rule i got this from the log


2018-08-11 20:59:35.279 [vent.ItemStateChangedEvent] - FF_tryk_seng_test changed from ON to OFF

2018-08-11 20:59:44.884 [vent.ItemStateChangedEvent] - FF_tryk_seng_test changed from OFF to ON

2018-08-11 20:59:44.901 [ome.event.ItemCommandEvent] - Item 'FF_bedroomHUE_chr' received command OFF

2018-08-11 20:59:45.150 [vent.ItemStateChangedEvent] - FF_tryk_seng_test changed from ON to OFF

2018-08-11 20:59:58.992 [vent.ItemStateChangedEvent] - FF_tryk_seng_test changed from OFF to ON

2018-08-11 20:59:59.021 [ome.event.ItemCommandEvent] - Item 'FF_bedroomHUE_chr' received command OFF

My items is

Switch FF_tryk_seng_test    "Tryk seng test"    <switch> (IHC)
Color  FF_bedroomHUE_chr 	"Sengelampe Chr"   (Hue_bedroom, Lights)  {channel="hue:0200:xxxxxxxxxxxx:4:color"}

Meanwile i found out the value

2018-08-11 21:48:09.156 [INFO ] [rthome.model.script.BedroomHUE value] - 0,100,0

Regards

Thanks MDAR

I cant see what im missing and maybe is different from yours, but i wont work?

Regards

Thanks MDAR

I cant see what im missing and maybe is different from yours, but i wont work?

Regards

@Alexandersen you are missing a comma after “myrule” this is what’s causing the error.

Thanks

Meanwhile i have done this

logInfo("BedroomHUE value", FF_bedroomHUE_chr.state.toString)

This works :slight_smile:

i got this value

2018-08-11 21:48:09.156 [INFO ] [rthome.model.script.BedroomHUE value] - 0,100,0

Is there somewhere we can see what the value x,x,x means?

Your Item is not of Type Switch, so, you would have to use this rule instead:

rule "Hue seng chr"
when
    Item FF_tryk_seng_test changed from OFF to ON
then
    logInfo("myRule", "value is {}", FF_bedroomHUE_chr.state)
    if(FF_bedroomHUE_chr.getStateAs(OnOffType) == OFF) 
        FF_bedroomHUE_chr.sendCommand(ON) 
    else 
        FF_bedroomHUE_chr.sendCommand(OFF) 
end 

You don’t need { } as there is only one command to execute, curly brackets are to build a code block.
Within a String, { } is a wildcard, which is filled with the var after the String.
As the Item FF_bedroomHUE_chr is a Color Item, the state will always be a HSBtype, but luckily there is a method .getStateAs(typeclass) :slight_smile:

1 Like

Thanks

But i get an error :slight_smile:

2018-08-11 23:24:44.541 [vent.ItemStateChangedEvent] - FF_tryk_seng_test changed from OFF to ON

==> /var/log/openhab2/openhab.log <==

2018-08-11 23:24:44.547 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Hue seng chr': The name 'ONOFFType' cannot be resolved to an item or type; line 30, column 37, length 9

2018-08-11 23:24:44.567 [INFO ] [clipse.smarthome.model.script.myRule] - value is 0,100,0

2018-08-11 23:24:44.579 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Hue seng chr': The name 'ONOFFType' cannot be resolved to an item or type; line 30, column 37, length 9


1 Like

Could it be “OnOffType.class”, not “ONOFFType.class”?

Hi John

It removed the error but im back to my rule only wil send the off signal.

Hi again

Problem solved

Only isue is it seems a bit slow from when i push the button to the light turn on

I removed “class” then it worked - Thanks all for help.

if(FF_bedroomHUE_chr.getStateAs(ONOFFType.class) == OFF) 

Now i will play with changing color and scenes in a rule

1 Like

Ah. maybe this was changed… so the correct line would be

if(FF_bedroomHUE_chr.getStateAs(OnOffType) == OFF) 

correct?

Yes and now it works :slight_smile:

Thanks

I’ve changed the original code if someone stumbles upon the code…

Super - Thanks.

Are you familiar with rules for switching color and dimmer by pushing a button?

Regards
Christian

Well, for color, as it’s a HSBType, you have to build the color value as HSB

Maybe this one is working for you:

Super - thanks

I will havea try :slight_smile: