[SOLVED] 2 Time periods in Rule

Hi all,

I currently have a rule running for turning my lights on when LUX is bellow

rule "Turn Sidelight On_LUX"
when
    Item WeatherUV2 changed
then
    if(now.getHourOfDay() >5 && now.getHourOfDay() <22){
    if (GroundLights.state == OFF && WeatherUV2.state < 100){
    GroundLights.sendCommand(ON)
    sendBroadcastNotification("Side Lights ON")
    }
    }
end

I want to split the time in to 2 periods, something like;

rule "Turn Sidelight On_LUX"
when
    Item WeatherUV2 changed
then
    if(now.getHourOfDay() >5 && now.getHourOfDay() <7){
    if(now.getHourOfDay() >16 && now.getHourOfDay() <22){
    if (GroundLights.state == OFF && WeatherUV2.state < 100){
    GroundLights.sendCommand(ON)
    sendBroadcastNotification("Side Lights ON")
    }
    }
end

However i cant work out the correct command to use either one time period or the other.

Any help would be appreciated.

Thanks

This tests first whether it is between 5-7 and then tests whether it is between 16-20, which will never be true as the first if statement requires it to be between 5-7

Try this

if(now.getHourOfDay() >5 && now.getHourOfDay() <7) OR (now.getHourOfDay() >16 && now.getHourOfDay() <22) {
if (GroundLights.state == OFF && WeatherUV2.state < 100){
    GroundLights.sendCommand(ON)
    sendBroadcastNotification("Side Lights ON")
    }
}
1 Like

Thanks @lipp_markus