I’m getting mqtt-results from a soil moisture sensor and want to trigger a rule to activate a water pump based on the sensor readings. Now I’m trying to figure out how to compare these readings to a given threshold.
Error in Log:
Rule 'Irrigation': Could not cast 2079 to java.lang.Number
Rule:
rule "Irrigation"
when
Item Feuchtigkeit changed
then
if ((Feuchtigkeit.state as Number).intValue > 1000) {
if (Pumpe_Timer.state == OFF) {
Pumpe.sendCommand(ON)
Thread::sleep(2000)
Pumpe.sendCommand(OFF)
Pumpe_Timer.sendCommand(ON) //puts pump in refractory state for 10 min
}
}
end
Any idea why the result “2079” can not be cast to java.lang.Number or how I could compare that number to i.e. 1000 so the rule gets triggered?
rule "Irrigation"
when
Item Feuchtigkeit changed
then
if ((Feuchtigkeit.state as Number) > 1000) {
if (Pumpe_Timer.state == OFF) {
Pumpe.sendCommand(ON)
createTimer(now.plusSeconds(2), [ |
Pumpe.sendCommand(OFF)
Pumpe_Timer.sendCommand(ON) //puts pump in refractory state for 10 min
])
}
}
end