Humidity rule not working well

Hi my rule is kinda working my problem is when the humidity value is not 90% or above or 80% and lower, if the humidity is above 90% or under 80% it works, but when it is between the 80% and 90% it doesnt send the on command to High85.

rule "Room humidity 90% loop"
when
	Item FHum90 changed to ON
then if (Room_Humidity.state >=90) {
		createTimer(now.plusSeconds(3)) [
		High90.sendCommand(ON)]}
else if (Room_Humidity.state <=80) {
		createTimer(now.plusSeconds(3)) [
	    Low90.sendCommand(ON)]}
else if (Room_Humidity.state >=81) {
		createTimer(now.plusSeconds(3)) [
	    High85.sendCommand(ON)]}	
end

You need to think about the order of your testing.

If x > 3 then blah
else if x > 4 then bleh.

If x is 5 then blah always gets done and not bleh

EDIT oh wait, is your Item a quantity type? Comparing 85% with 90 doesn’t work the way you think.

1 Like

Ok but i dont think that is the problem, my rule is first checking if the value is 90 or above, and then if the value is 80 or lower, so if my value is 85 it shouldnt trigger any of the rules and go to the last one that is checking if the value is 81 or above, and 85 is higher than 81 so it should work.

Perhaps it’s possible that the humidity is not a whole number. For example a humidity of 80.1 would fall through without sending any command. Are the Low90 and High85 items in the correct place in the rule? The way it is coded if the humidity is <=80 Low90 is set ON and if the humidity is between 81 and 90 High85 is turned on.

I believe this should work:

rule "Room humidity 90% loop"
when
	Item FHum90 changed to ON
then if (Room_Humidity.state >=90) {
		createTimer(now.plusSeconds(3)) [
		High90.sendCommand(ON)]}
else if (Room_Humidity.state >=81) {
		createTimer(now.plusSeconds(3)) [
	    Low90.sendCommand(ON)]}	
else  {createTimer(now.plusSeconds(3)) [
	  High85.sendCommand(ON)]}	
end

I’m assuming the items are being turned off somewhere else.

I tried but it doesnt work i really dont understand what the problem is, the humidity is at 88% and it didnt send any command.

rule "Room humidity 90% loop"
when
	Item FHum90 changed to ON
then if (Room_Humidity.state >=87) {
		createTimer(now.plusSeconds(3)) [
		High90.sendCommand(ON)]}
else if (Room_Humidity.state <87) {
		createTimer(now.plusSeconds(3)) [
	    Low90.sendCommand(ON)]}

Now if i have it like this it works no problem other than i dont have the hability to turn High85 on but i can manage not having it.
The way the rule is set now the humidity is always between 87% to 92% and with the way i wanted it to work it would go between 78% and 92% but as is doesnt detect anything when the value is between 80% and 90% the loop stops.
And yes the items are being turned off by other rules this one just decides where to go according to the humidity levels.

Once again, is this a quantity type? i.e. really 88% and not 88

Blockquote

The sensor doesnt measure as %
: tele/room/SENSOR = {“Time”:“2021-05-08T00:37:05”,“SI7021”:{“Temperature”:16.9,“Humidity”:85.7,“DewPoint”:14.5},“TempUnit”:“C”}

Rule doesn’t care about the sensor or channel, it’s the Item type and its state of interest.

So guessing the Item is a Number type, this works for me -

testNum.postUpdate(95)
Thread::sleep(5000)
logInfo("test", "state " + testNum.state)
if (testNum.state >=90) {
	createTimer(now.plusSeconds(3)) [
		logInfo("test", "High90 ON")]}
else if (testNum.state <=80) {
		createTimer(now.plusSeconds(3)) [
		logInfo("test", "Low90 ON")]}
else if (testNum.state >=81) {
		createTimer(now.plusSeconds(3)) [
		logInfo("test", "High85 ON")]}
else {logInfo("test", "Fell out")}

testNum.postUpdate(75)
Thread::sleep(5000)
logInfo("test", "state " + testNum.state)
if (testNum.state >=90) {
	createTimer(now.plusSeconds(3)) [
		logInfo("test", "High90 ON")]}
else if (testNum.state <=80) {
		createTimer(now.plusSeconds(3)) [
		logInfo("test", "Low90 ON")]}
else if (testNum.state >=81) {
		createTimer(now.plusSeconds(3)) [
		logInfo("test", "High85 ON")]}
else {logInfo("test", "Fell out")}


testNum.postUpdate(85)
Thread::sleep(5000)
logInfo("test", "state " + testNum.state)
if (testNum.state >=90) {
	createTimer(now.plusSeconds(3)) [
		logInfo("test", "High90 ON")]}
else if (testNum.state <=80) {
		createTimer(now.plusSeconds(3)) [
		logInfo("test", "Low90 ON")]}
else if (testNum.state >=81) {
		createTimer(now.plusSeconds(3)) [
		logInfo("test", "High85 ON")]}
else {logInfo("test", "Fell out")}
2021-05-08 01:12:56.297 [INFO ] [.eclipse.smarthome.model.script.test] - state 95
2021-05-08 01:12:59.301 [INFO ] [.eclipse.smarthome.model.script.test] - High90 ON
2021-05-08 01:13:01.306 [INFO ] [.eclipse.smarthome.model.script.test] - state 75
2021-05-08 01:13:04.309 [INFO ] [.eclipse.smarthome.model.script.test] - Low90 ON
2021-05-08 01:13:06.312 [INFO ] [.eclipse.smarthome.model.script.test] - state 85
2021-05-08 01:13:09.315 [INFO ] [.eclipse.smarthome.model.script.test] - High85 ON

EDIT - postscript, this is interesting.
I’ve only just noticed that the compactly written code like

createTimer(now.plusSeconds(3)) [
		logInfo("test", "High90 ON")]}

omits the usual | character after the [.
I’d always thought it was mandatory, but copy-paste of your code did not produce any complaints from code validator about it. And as you can see, the same omission works in my version, giving the delay.
This “closure” stuff with [ ] is weird :crazy_face: