Hello,
I’m trying to make a rule for a bathroom fan and I’ve got probably a mistake in syntax and I can’t figure it out where is the problem. rule
val maxHumidity = 60
val minHumidity = 40
rule “fanBathroom”
when
Item Humidity changed
then
if(ventilator.state != ON) {
if(Humidity.state as Number > maxHumidity) {
ventilator.sendCommand(ON)
}
}
if(ventilator.state = ON) {
if(Humidity.state as Number < minHumidity) {
ventilator.sendCommand(OFF)
}
}
end
fan
Switch ventilator “ventilator” {qpio=“pin:29 activelow:yes initialValue:high” }
humidity
Number Humidity { channel=“mqtt:topic:58ab282c:Humidity” }
P.S. when the humidity exceeds 60 turns the fan on and when is the humidity below 40 fan shuts down.
Adding logging inside both inner if-statements will help you troubleshoot.
I noticed that the channel for the fan specifies ‘high’ as a value, not ‘ON’.
Also, you may have to specify the humidity limits as Number (not sure about that).
val Number maxHumidity = 60
val Number minHumidity = 40
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
Do you mean that it was already installed? the log file suggests it is missing: "Transformation service CONFIG. “JSONPATH for pattern $. not found!”. In that case try to uninstall and install it again and reboot in between.
If it is still throwing the NullPointerException, please add logging to see where in the rule it stumbles upon an NPE. And add another logging at the start of the rule to show the values/states of the items.
BTW, do you see mqtt messages coming in in events.log?
Remove the “config” and the quotation marks from the transformation pattern.
The state topic looks odd, are you sure that “Humidity” is correct in there?
I think it is a syntax issue in the transform and therefor the humidity item remains null and hence the NPE error.
Why do you prefix the jsonpath with “config” ? And I’m not sure if you should add the quotes around it (I use configuration files instead of Paper UI, so I’m not sure).
If the statetopic is correct with "Humidity " , why is it needed in the transformation pattern again?
Could you post the raw message you are getting.
My assumption would be, if the " humidity " is part of the state topic a transformationPattern might be obsolete.
I apologize for late reply haven’t been home. So far I corrected that typo and my rule looks like this
val Number maxHumidity = 90
val Number minHumidity = 70
rule “fanBathroom”
when
Item Humidity changed
then
if (ventilator.state != ON) {
if (Humidity.state as Number > maxHumidity) {
log.info(“on”, “Humidity {} above threshold of {}”, Humidity.state, max$
ventilator.sendCommand(ON)
}
}
if (ventilator.state == ON) {
if (Humidity.state as Number < minHumidity) {
log.info(“off”, “Humidity {} below threshold of {}”, Humidity.state, mi$
ventilator.sendCommand(OFF)
}
and I've checked the log and found a new error
[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘fan.rules’ has errors, therefore ignoring it: [5,6]: no viable alternative at input ‘“’
is this valid at all? i think you should either change this to logInfo(…) or completely comment out those log.info’s and i guess the rule will magically work