Compare switch state does not work

  • Platform information:
    • Hardware: Raspi3
    • OS: Raspian with openhabian 1.4
    • openHAB version:2.2

I am currently setting up an automated irrigation for my garden.
Therefore i’ve created some rules that e.g. switch on the valves, but only if the sensors which are reporting the soil humidity are online - otherwise the valve won’t be opened.

Here’s my rule

rule "Irrigation Raised Bed"
when
	Time cron "0 0 6,9,12,15,18 ? FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT * *" or		//every three hours between 6am and 6pm (9pm for debugging) during march - oct
	Item TestSwitchIrrigationRaisedBed received command ON
then
	//If the humidity is below or equal the lower value
	if(MoistureRaisedBed.state <= HumidityRaisedBedLow)
	{
		logInfo("Irrigation Raised Bed", "Moisture level below lower value. Opening valve")
		
		//open valve only if sensor and gateway are online - otherwise the valve would open each three hours for two hours
		if((MoistureRaisedBed_SensorState.state == ON) && (Sensor_Gateway_Garden_Ping.state == ON))
		{
			Valve_Garden_RaisedBed.sendCommand(ON)
		}
		else
		{
			logInfo("Irrigation Raised Bed", "Sensor or gateway offline - Irrigation canceled")
			logInfo("Irrigation Raised Bed", MoistureRaisedBed_SensorState.state.toString)
			logInfo("Irrigation Raised Bed", Sensor_Gateway_Garden_Ping.state.toString)
			//make sure that the valve gets closed
			Valve_Garden_RaisedBed.sendCommand(OFF)
		}
	}
end

When I trigger the rule with the item TestSwitchIrrigationRaisedBed the valve is not opening, even if MoistureRaisedBed_SensorState and Sensor_Gateway_Garden_Ping are ON

I see the following log entries:

2018-03-17 23:16:52.319 [INFO ] [e.model.script.Irrigation Raised Bed] - Moisture level below lower value. Opening valve
2018-03-17 23:16:52.324 [INFO ] [e.model.script.Irrigation Raised Bed] - Sensor or gateway offline - Irrigation canceled
2018-03-17 23:16:52.327 [INFO ] [e.model.script.Irrigation Raised Bed] - ON
2018-03-17 23:16:52.330 [INFO ] [e.model.script.Irrigation Raised Bed] - ON

So both item states are on, but the rule jumps to the else part of the IF condition. Even if I compare only one of those items against ON, I get the same behavior.

It has been a while since i’ve coded my last rule, but other rules where I compare item states are working without issues.

Here’s my items definition for those two items:

Switch Sensor_Gateway_Garden_Ping       "Sensorgateway (ESP32) Garten [MAP(network.map):%s]"        <espressif> (gDeviceOnlineState)    {mqtt="<[mosquitto:Home/Garden/SensorGateway/Status:state:default"}
Switch Sonoff4CH_Garden_RaisedBed_Ping  "Sonoff Garten Hochbeet [MAP(network.map):%s]"  <itead>         (gDeviceOnlineState)    {mqtt="<[mosquitto:tele/Home/Garden/Sonoff/RaisedBed/LWT:state:MAP(sonoff.map)]"}

So in the end i’m stuck a bit. Any hints?

Damnit - i found the solution. I was using the wrong item.
One of those items was defined as String instead of switch …

Sorry :roll_eyes: