Hello all,
I am having issues with rules, you can call me a complete noob.
I constantly get the error “no viable alternative at input ‘Thing’” or "no viable alternative at input ‘Item’"
I am running an RPi using openhabian 2.2 also tried against 2.1
Some example rules I have tried:
rule "UFH"
when
Thing "Heating" received update
then
if ((Heating_HeatPower > 0)) {
sendCommand(UnderFloorHeatingSW2, ON)
}
if ((Heating_HeatPower == 0)) {
sendCommand(UnderFloorHeatingSW2, OFF)
}
end
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
rule "GuestRoom Light OnOff"
when
Item "GuestRoomLightScene" received command
then
"ZWaveNode4FGS223DoubleSwitch2_Switch".sendCommand(if("ZWaveNode4FGS223DoubleSwitch2_Switch".state == OFF) ON else OFF)
if (("ZWaveNode4FGS223DoubleSwitch2_Switch" == OFF)) {
"ZWaveNode4FGS223DoubleSwitch2_Switch".sendCommand(ON)
}
else {
"ZWaveNode4FGS223DoubleSwitch2_Switch".sendCommand(ON)
}
end
No Rule will load with the errors being along the lines of
2018-02-10 17:27:34.212 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'UFH.rules'
2018-02-10 17:27:34.228 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'UFH.rules' is either empty or cannot be parsed correctly!
2018-02-10 17:27:34.321 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'UFH.rules' has errors, therefore ignoring it: [3,2]: no viable alternative at input '"Heating_HeatPower"'
Any pointers or help you can give will be much appreciated
Thx,
Col
Thnaks @rossko57 yes this is a number item, and adding state was already tried but…
It seems adding state works in this case
rule "UFH"
when
Thing "Heating" received update
then
if ((Heating_HeatPower.state > 0)) {
sendCommand(UnderFloorHeatingSW2, ON)
}
if ((Heating_HeatPower.state == 0)) {
sendCommand(UnderFloorHeatingSW2, OFF)
}
end
but my rule did not trigger, due to the “when” case not being correct.
So I changed it to:
rule "UFH"
when
Item "Heating_HeatPower" changed
then
if ((Heating_HeatPower.state > 0)) {
sendCommand(UnderFloorHeatingSW2, ON)
}
if ((Heating_HeatPower.state == 0)) {
sendCommand(UnderFloorHeatingSW2, OFF)
}
end
and now I get:
2018-02-10 18:06:28.047 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'UFH.rules' is either empty or cannot be parsed correctly!
2018-02-10 18:06:28.184 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'UFH.rules' has errors, therefore ignoring it: [3,2]: no viable alternative at input '"Heating_HeatingPower"'
Do I assume I cannot use items, only things as my trigger?
Also here, a few things are unclear; see if this does what you want:
rule "GuestRoom Light OnOff"
when
Item "GuestRoomLightScene" received command
then
if (ZWaveNode4FGS223DoubleSwitch2_Switch.state == OFF) {
ZWaveNode4FGS223DoubleSwitch2_Switch.sendCommand(ON)
}
else {
ZWaveNode4FGS223DoubleSwitch2_Switch.sendCommand(ON)
}
end
Here some explanations: "ZWaveNode4FGS223DoubleSwitch2_Switch".sendCommand(if("ZWaveNode4FGS223DoubleSwitch2_Switch".state == OFF) ON else OFF)
This does not work, as in parenthesis after sendCommand there should only be a command and no code. You see above that all item names should not be in hyphens.
But the logic means that your rule does only one thing, when it is triggered it will always switch your item on; and if this is the behavior you wanted you could just rewrite it to:
Item "GuestRoomLightScene" received command
then
ZWaveNode4FGS223DoubleSwitch2_Switch.sendCommand(ON)
end
@lipp_markus Thank you for the pointers, I have read much of the documentation, although between the OH1 and OH2 syntax changes and the slightly outdated manuals I think I have crossed things over, I do try to trawl the docs and forums before posting, but I have gotten quite lost. Your support in my learning is much appreciated.
I tried without the quotes and had some improvement in the logs, although still no trigger.
Openhab.log shows this:
2018-02-10 18:34:27.005 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'UFH.rules'
2018-02-10 18:34:27.017 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'UFH.rules' is either empty or cannot be parsed correctly!
2018-02-10 18:34:27.522 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'UFH.rules'
The trigger event I want to use looks like this, although trigger value is anywhere between 1 and 100
2018-02-10 18:37:49.641 [vent.ItemStateChangedEvent] - Heating_HeatingPower changed from 0.00 to 100.00
Would I see the rule being triggered in a log anywhere?
I will try the other scene rule you have suggested soon, but the button is not to hand right now.
Many thanks,
Configuration model ‘UFH.rules’ is either empty or cannot be parsed correctly!
That’s normal during edit, especially when you use the Samba file share - during write of the file, OpenHAB cannot access the file for some milliseconds. Next line in log tells you that the rules file was loaded successfully so this one shouldn’t bother you.
Don’t think so, although if all works well it should log an event of the item state you changed.
My lifesafer for figuring out rules are loginfo statements, they takes two strings as arguments, make the first one your rule name and the second a helpful message, for example: logInfo("UFH rule", "Rule triggered. Heating_HeatPower is now: " + Heating_HeatPower.state.toString) and put this immediately after the then statement; this way you can see in your logs when your rules triggers and what value your item has.
more here: https://docs.openhab.org/administration/logging.html#create-log-entries-in-rules
Also, try to rewrite sendCommand(UnderFloorHeatingSW2, ON) into UnderFloorHeatingSW2.sendCommand(ON)
Can save you a lot of headache in certain circumstances (see the link posted earlier).
You can also try to trigger your rule on received update and see whether this makes a difference.
Thanks to all of you,
It is now working (UFH rule), I think I had a series of errors, from putting items in quotes, to conflicts in the items file.
Weeding out all of the rules errors helped me identify the items misconfiguration.