[SOLVED] Multiple if conditions for triggering rules with time based

Thank you for your insights.

My rule looks like this now, but I dont see it working still

rule "Flexion power to ON"
when	
	Time cron "0 0 7 ? *MON-SAT *" or
	Item OnePlus5 changed to ON
then
	if (OnePlus5.state == ON && now.getHourofDay() >=7 && now.getHourofDay() < 17) {	
	mqttActions.publishMQTT("cmnd/sonoff-flexion/POWER", "On")
	sendTelegram("bot1", "Flexion Microscope is switched ON")
	logInfo("Info","Flexion power ON Rule fired")
	}
end

Doesn’t look far wrong to me.
I would move the logInfo to before the if() line, then it will tell the truth about the rule firing.
You can always put another logInfo inside the if-block to see if you pass the conditions.
What does openhab.log tell you about it?

I got this error

2019-02-22 11:20:30.589 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Flexion power to ON': 'getHourofDay' is not a member of 'org.joda.time.DateTime'; line 76, column 33, length 16

Okay, that should cause you to look closely at the use of that in your rule. Why would it fail for you, but work for other people? Compare carefully with other examples of usage, e.g. earlier on in this thread.

.getHourOfDay

Rules are (very) case sensitive.
We all make mistakes like this and they are very easy to overlook, but not that difficult to find using the error reporting.

Thank you Sir. Indeed the capital “O” of .getHourOfDay was the culprit.

If you are not yet using VSCode as a rule editor, I would recommend it. It catches typos like that. It is another thing to set up and something else to learn to use, but will pay off in the long run.

Actually I did install and setup VScode. But I haven’t figured out how to enable write priviledges to the conf files. My OH setup is on a synology docker. So I can’t save anything I change with VScode

I am getting this error with my rule which triggers a fan when temperature goes to 37 or higher

2019-03-11 21:10:43.251 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Rackfan power to ON': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(T,org.eclipse.xtext.xbase.lib.Procedures$Procedure1) on instance: null

This is the rule

val mqttActions = getActions("mqtt", "mqtt:broker:mosquitto")

rule "Rackfan power to ON"
when
	Time cron "0 0 10 ? * MON-SUN *" or
	Item Sonoffps3_Temperature received update
then
	if ((Sonoffps3_Temperature.state => 37) && now.getHourOfDay() >=10 && now.getHourOfDay() <=18) {
    mqttActions.publishMQTT("cmnd/sonoff-rackfan/POWER", "ON")
	sendTelegram("bot1", "Rackfan is switched ON as temperature is above 37°C" )
	logInfo("Info","Rackfan power ON Rule fired")	    
    }
	
    else if ((Sonoffps3_Temperature.state < 38) && now.getHourOfDay() >=10 && now.getHourOfDay() <=18) {
    mqttActions.publishMQTT("cmnd/sonoff-rackfan/POWER", "OFF")
	logInfo("Info","Rackfan power OFF Rule fired")	
    }
    
end	

Compare => with >=, only one can be correct.

Hi,
I was trying to understand that thread to create a rule for my needs, unfortunately it throws this error when saving already:

2022-05-19 21:31:41.494 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'automation.rules' has errors, therefore ignoring it: [136,63]: no viable alternative at input '&&'

This is the rule. A dehumidifier should only work when a certain humidity is reached AND when there is enough PV power (my power meter shows negative values when it provides power to the grid, and positive when drawing from it. Hence the value)

when
	Time cron "0 0/5 * * * ?"
then
	if ((FeuchteNodemcu2.state as DecimalType).floatValue >= 61) && ((DSWirkleistung.state as DecimalType).floatValue <= -1000) {
		ShellyPlug2Output.sendCommand (ON)
		}
	else if ((FeuchteNodemcu2.state as DecimalType).floatValue <= 55) {
		ShellyPlug2Output.sendCommand (OFF)
		}
end

Any ideas what I am doing wong?

Have a look at the ( ) brackets if your if() statement - they exclude the && at the moment.
You can add spaces for clarity.

Thanks rossko, at least the error is gone. Need to see if the script works as intended when the sun is gone today :wink: