Rule if condition

I would like to combine the following 2 rules. I could have the 2 time triggers to trigger the rule but im unsure of how to make the if condition that if it it between 21:15 - 06:45? see below for how I want to change the rule. any help would be awesome

rule "Switch Water Heating on and set temp to 40" 

when
	Time cron "0 15 21 * * ? *"
then
	Hot_water_Element_1.sendCommand(ON)
	Hot_water_Element_2.sendCommand(ON)
	Spa_Target_Temp.sendCommand(40)
end

rule "Switch Water Heating 0ff and set temp to 33" 

when
	Time cron "0 45 6 * * ? *"
then
	Hot_water_Element_1.sendCommand(OFF)
	Hot_water_Element_2.sendCommand(OFF)
	Spa_Target_Temp.sendCommand(33)
end
rule "Switch Water Heating on and off" 

when
	Time cron "0 15 21 * * ? *" or
	Time cron "0 45 6 * * ? *"
then

	if	(???????)
		{
		Hot_water_Element_1.sendCommand(ON)
		Hot_water_Element_2.sendCommand(ON)
		Spa_Target_Temp.sendCommand(40)
		}

	if	(???????)
		{
		Hot_water_Element_1.sendCommand(OFF)
		Hot_water_Element_2.sendCommand(OFF)
		Spa_Target_Temp.sendCommand(33)
		}
end

if (now.getHourOfDay > 7)

1 Like

I don’t think that will work? the water heater needs to turn on at 915pm and off at 645am. For the on if section it needs to be conditional on the time being between 2115-0645 then turn everything on else if not run the 2nd if section. im just unsure how to code it :joy:

So the rule trigger twice a day you can just

if (now.getHourOfDay > 12)

if (now.getHourOfDay < 12)

You can keep it in 2 rules and it works. Then why change?

There is no cost to having many small rules, and it’s very often a lot easier for us humans to think about.

The cron approach breaks down a bit though, if you might reboot your system. States are indeterminate until your next cron.

Having now got your initial functions working, you might look instead at a time-day-approach, where a rule system can divide your households day into chunks, and separate rules manage just what do during each chunk.