I found an errormessage when openhab2 starts that i don’t understand:
2018-12-15 11:07:39.027 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Haustür': The name 'OFF' cannot be resolved to an item or type; line 104, column 37, length 3
2018-12-15 11:07:39.034 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Flur_Stehlampe': The name 'OFF' cannot be resolved to an item or type; line 90, column 42, length 3
This are the rules:
rule "Flur_Stehlampe"
when
Item Zwave_Flur_Stehlampe_caldav changed or Item DarkOutsite changed
then
if (Zwave_Flur_Stehlampe_caldav.state == ON && DarkOutsite.state == ON ) {
logInfo("caldav", "Stehlampe an")
sendCommand(Zwave_Flur_Stehlampe,ON)
}
else {
logInfo("caldav", "Stehlampe aus")
sendCommand(Zwave_Flur_Stehlampe,OFF) # line 90
}
end
rule "Haustür"
when
Item Garten_Haustuer_caldav changed or Item DarkOutsite changed
then
if (Garten_Haustuer_caldav.state == ON && DarkOutsite.state == ON) {
sendCommand(Garten_Haustuer,ON)
logInfo("caldav", "Haustür on")
}
else {
sendCommand(Garten_Haustuer,OFF) # line 104
logInfo("caldav", "Haustür off")
}
end
Don’t worry about them.
openHAB is trying to run the rules without having loaded all the language vocabulary.
It has to do with the order in which thing are started which can be a little random.
Ignore these errors.
I checked the rules-dsl.html, particularly the section “deeper dive”, but still can’t find an explanation. My workaround is doing well, but I would like to understand the mechanisms that avoid a simpler and more elegant solution.
The following rule does work:
if (a.state==“ON”) {
s.sendCommand(“ON”)
}
else if (a.state==“OFF”) {
s.sendCommand(“OFF”)
}
However, the following does NOT work:
if (a.state==“ON”) {
s.sendCommand(a.state)
}
else if (a.state==“OFF”) {
s.sendCommand(a.state)
}
My final goal is to simplify it with the following, most elegant solution:
s.sendCommand(a.state)
To complete the information, the Items are defined as follows (simplified):
Switch s “bla” {channel=“…”}
String a
Any idea why I cannot use sendCommand with the content of the variable? As I understand the documentation, (almost) all variables are converted to Strings inside sendCommand, but then it should work with the simpler solution.
A String Item state is not the same as a Switch Item state. “ON” not the same as ON.
A state is not quite the same object as a command. Especially confusing with ON/OFF which looks the same!
Try s.sendCommand(a.state.toString)
for lowest common denominator
Thank you very much, @rossko57. Works perfectly now. I had thought about this but rejected because I understood from the documentation that the value is converted anyway to the type the item needs. Seems that doesn’t happen properly in this case.