Fan rule

Oops the dots between log.info somehow slipt in… make it logInfo indeed.

The Warn message tells where the problem is (line,column), however the number are counted in the file, not only in the rule. Is this the only rule in the file? Did you miss the “end”?
Since you deleted some lines, what does the message say o the actual code?

My guess for the problem: You are using the wrong quotation marks, do not use the tilted ones! Only such ".

I assume the ‘$’ at the end of the (wrong) logInfo lines you showed are due to ‘end of screen’ in the editor?

Anyway, to know what’s going (wr)on(g), you really need those log statements.

Sorry for the confusion, it has been a hectic week at work and I got a little sloppy/fat-fingered, but I corrected the rule in the post above. Please try again. :grin:

1 Like
rule “fanBathroom”

when
Item Humidity changed
then
if(ventilator.state != ON) {
if(Humidity > 60) {
ventilator.sendCommand(ON)
}
}
if(ventilator.state == ON) {
if(Humidity < 40) {
ventilator.sendCommand(OFF)
}
}

end

Try this out !!

nice quotes (“) will definitely not work…

Tried your updated script and it’s still doesn’t work for my switch.
Checked the log and saw one warning could this be the case?

[WARN ] [sitemap.internal.SitemapProviderImpl] - Filename home.sitemap does not match the name myhouse of the sitemap - please fix this as you might see unexpected behavior otherwise.

The name of the .sitemap file has to match the used name of the sitemap in the file!
Can’t say if this relates to the not-working switch.

Fixed the problem, but still no luck with the bathroom fan rule.

Did you put logging in the rule and is there any log entry in the openhab.log file?

used your updated script and there is no log entry in the log viewer

Update: new log entry in the log viewer

[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘fan.rules’ has errors, therefore ignoring it: [18,49]: missing ‘>’ at ‘)’

That warning is telling you that file is ignored because of a false syntax in line 18 character 49. A character “>” was expected but a ")"was found.
Since the line count goes for the whole file you need to look yourself or post the complete file you are actually using.

Here is the complete code:

val Number maxHumidity = 90
val Number minHumidity = 70

rule “fanBathroom”
when
Item Humidity changed
then
logInfo(“FanBathroom”, “Humidity changed to {}, ventilator is {}”, Humidity.state, ventilator.state)
if (ventilator.state != ON) {
if (Humidity.state as Number > maxHumidity) {
logInfo(“FanBathroom”, “Humidity {} above threshold of {}”, Humidity.state, maxHumidity)
ventilator.sendCommand(ON)
}
}
if (ventilator.state == ON) {
if (Humidity.state as Number < minHumidity) {
logInfo(“FanBathroom”, “Humidity {} below threshold of {}”, Humidity.state, minHumidity)
ventilator.sendCommand(OFF)
}
}
end

Copied the code into my VSCode and found the EasteEgg! :rabbit: :egg:

Not really obvious, but VSCode would have told you that it would expect an expression encapsulated by “<” and “>” if you are using the “<” right after “Number”. Using the “>” in same position doesn’t raise this problem. In order to solve it put the Humidity.state as Number into brackets.

When posting code, please use the Icon for"Preformated Text" ("</>"), that way the code keeps its correct quotation marks (only those " work, the tilted ones don’t).

1 Like

Thank you for all the help. Here is the final full code for anyone who is reading this topic.

val Number maxHumidity = 90
val Number minHumidity = 70

rule "fanBathroom"
when

    Item Humidity changed
  then
    logInfo("FanBathroom", "Humidity changed to {}, ventilator is {}", Humidity.state, ventilator.state)
    if (ventilator.state != ON) {
      if ((Humidity.state as Number) > maxHumidity) {
        logInfo("FanBathroom", "Humidity {} above threshold of {}", Humidity.state, maxHumidity)
        ventilator.sendCommand(ON)
      }
    }
    if (ventilator.state == ON) {
      if ((Humidity.state as Number) < minHumidity) {
        logInfo("FanBathroom", "Humidity {} below threshold of {}", Humidity.state, minHumidity)
        ventilator.sendCommand(OFF)
      }
    }
 end
1 Like

Again posting code without formatting. User will copy it and the code won’t run because of the tilted quotation Mark’s! Didn’t you read/understand my last post completely?
[Edit] Now you got it!

1 Like

My bad. Fixed the post.