Im trying too get this rule to work, bu it seems that the If sentense is ignored
Because it only sends Command OFF
rule "Hue seng chr"
when
Item FF_tryk_seng_test changed from OFF to ON
then
if(FF_bedroomHUE_chr.state == OFF) {
FF_bedroomHUE_chr.sendCommand(ON)
}
else
FF_bedroomHUE_chr.sendCommand(OFF)
end
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)
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
6
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.
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"}
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)
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