Whats wrong with my rule

Hi Everyone i have been working on my rules trying to centralise some of my lighting rules
so far i have come up with this rule but it behaves unexpectidly

whats supposed too happe
if item changed to on then check time and do stuff then turn item back off

whats happeneng
sometimes when the item turns too ON it just stays on and doesent c’hange the lights or log a time in the log just stays on and nothing happens

any advice appretiated

rule "Time Based Lighting" // WW = Warm White / W = White / CW = Cool White /
when
Item Timebasedlighting changed to ON
then
    if( now.getHourOfDay <  6 ) { // 12AM <> 6AM
    Lamp1_Brightness.sendCommand("5")   
    BULB6LRMAIN1_Color.sendCommand("39,87,5") // WW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 12AM <> 6AM FINISHED")
    return;
    }
    if( now.getHourOfDay >  6 && now.getHourOfDay < 8 ) { // 6AM <> 8AM
    Lamp1_Brightness.sendCommand("100")
    BULB6LRMAIN1_Color.sendCommand("39,87,75") // WW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 6AM <> 8AM FINISHED")
    return;
    }
    if( now.getHourOfDay >  8 && now.getHourOfDay < 12 ) { // 8AM <> 12AM
    Lamp1_Brightness.sendCommand("100")
    BULB6LRMAIN1_Color.sendCommand("227,30,100") // CW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 8AM <> 12AM FINISHED")
    return;
    }
    if( now.getHourOfDay >  12 && now.getHourOfDay < 16 ) { // 12AM <> 4PM
    Lamp1_Brightness.sendCommand("75")
    BULB6LRMAIN1_Color.sendCommand("227,30,0") // OFF
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 12AM <> 4PM FINISHED")
    return;
    }
    if( now.getHourOfDay >  16 && now.getHourOfDay < 20 ) { // 4PM <> 8PM
    Lamp1_Brightness.sendCommand("60") 
    BULB6LRMAIN1_Color.sendCommand("227,30,60") // CW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 4PM <> 8PM FINISHED")
    return;
    }
    if( now.getHourOfDay >  20 && now.getHourOfDay < 22 ) { // 8PM <> 10PM
    Lamp1_Brightness.sendCommand("30") 
    BULB6LRMAIN1_Color.sendCommand("39,87,30")  // WW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 8PM <> 10PM FINISHED")
    return;
    }
    if( now.getHourOfDay >=  22 ) { // 10PM <> 12PM
    Lamp1_Brightness.sendCommand("15") 
    BULB6LRMAIN1_Color.sendCommand("39,87,15")  // WW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 10PM <> 12PM FINISHED")
    return;
    }        
end
20:23:15.276 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command OFF
20:23:15.277 [INFO ] [smarthome.event.ItemStateChangedEvent] - Timebasedlighting changed from ON to OFF
20:23:15.888 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command ON
20:23:15.889 [INFO ] [smarthome.event.ItemStateChangedEvent] - Timebasedlighting changed from OFF to ON
20:23:16.793 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command OFF
20:23:16.794 [INFO ] [smarthome.event.ItemStateChangedEvent] - Timebasedlighting changed from ON to OFF
20:23:17.396 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command ON
20:23:17.397 [INFO ] [smarthome.event.ItemStateChangedEvent] - Timebasedlighting changed from OFF to ON
20:23:18.051 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command OFF
20:23:18.052 [INFO ] [smarthome.event.ItemStateChangedEvent] - Timebasedlighting changed from ON to OFF
20:23:18.636 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command ON
20:23:18.637 [INFO ] [smarthome.event.ItemStateChangedEvent] - Timebasedlighting changed from OFF to ON
20:23:19.224 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command OFF
20:23:19.225 [INFO ] [smarthome.event.ItemStateChangedEvent] - Timebasedlighting changed from ON to OFF
20:23:19.721 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command ON
20:23:19.722 [INFO ] [smarthome.event.ItemStateChangedEvent] - Timebasedlighting changed from OFF to ON
20:23:19.839 [INFO ] [smarthome.event.ItemStateChangedEvent] - Plug7_Signal changed from -51 to -52
20:23:20.226 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command OFF

Thats me manually trying too trigger the rule turning the item off and on myself it sometimes functions perfectly

You may want to use >= here and there:

rule "Time Based Lighting" // WW = Warm White / W = White / CW = Cool White /
when
Item Timebasedlighting changed to ON
then
    if( now.getHourOfDay <  6 ) { // 12AM <> 6AM
    Lamp1_Brightness.sendCommand("5")   
    BULB6LRMAIN1_Color.sendCommand("39,87,5") // WW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 12AM <> 6AM FINISHED")
    return;
    }
    if( now.getHourOfDay >=  6 && now.getHourOfDay < 8 ) { // 6AM <> 8AM
    Lamp1_Brightness.sendCommand("100")
    BULB6LRMAIN1_Color.sendCommand("39,87,75") // WW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 6AM <> 8AM FINISHED")
    return;
    }
    if( now.getHourOfDay >=  8 && now.getHourOfDay < 12 ) { // 8AM <> 12AM
    Lamp1_Brightness.sendCommand("100")
    BULB6LRMAIN1_Color.sendCommand("227,30,100") // CW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 8AM <> 12AM FINISHED")
    return;
    }
    if( now.getHourOfDay >=  12 && now.getHourOfDay < 16 ) { // 12AM <> 4PM
    Lamp1_Brightness.sendCommand("75")
    BULB6LRMAIN1_Color.sendCommand("227,30,0") // OFF
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 12AM <> 4PM FINISHED")
    return;
    }
    if( now.getHourOfDay >= 16 && now.getHourOfDay < 20 ) { // 4PM <> 8PM
    Lamp1_Brightness.sendCommand("60") 
    BULB6LRMAIN1_Color.sendCommand("227,30,60") // CW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 4PM <> 8PM FINISHED")
    return;
    }
    if( now.getHourOfDay >=  20 && now.getHourOfDay < 22 ) { // 8PM <> 10PM
    Lamp1_Brightness.sendCommand("30") 
    BULB6LRMAIN1_Color.sendCommand("39,87,30")  // WW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 8PM <> 10PM FINISHED")
    return;
    }
    if( now.getHourOfDay >=  22 ) { // 10PM <> 12PM
    Lamp1_Brightness.sendCommand("15") 
    BULB6LRMAIN1_Color.sendCommand("39,87,15")  // WW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 10PM <> 12PM FINISHED")
    return;
    }        
end

That will get rid of time “gaps” when nothing was happening and could be the source of your problem.

how were there time gaps can you explain more pls i thought i had covered it all

i have not been able too get this rule too fire for over 30 mins but others works perfect i can see there might be errors and tiny time gaps bang on the hour ?

Look at these two conditions and imagine it’s 08:05am

now.getHourOfDay = 8 agreed?
None of these two will execute

    if( now.getHourOfDay >  6 && now.getHourOfDay < 8 ) { // 6AM <> 8AM
    Lamp1_Brightness.sendCommand("100")
    BULB6LRMAIN1_Color.sendCommand("39,87,75") // WW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 6AM <> 8AM FINISHED")
    return;
    if( now.getHourOfDay >  8 && now.getHourOfDay < 12 ) { // 8AM <> 12AM
    Lamp1_Brightness.sendCommand("100")
    BULB6LRMAIN1_Color.sendCommand("227,30,100") // CW
    Timebasedlighting.sendCommand ("OFF")
    logInfo("RULE", "Time Based Lighting 8AM <> 12AM FINISHED")
    return;

You have a gap of 1 hour when the hour is 8
So you need to use >= 8 to start from 8am otherwise > 8 starts at 9am

Get it?

i can see it now you have pointed it out

8 is not less than 8 so first one doesen’t run
8 is not bigger than 8 so second one doesen’t run

adding an = will obviously fix this as 8 is the same as 8 but if i changed both too = then they would both run

i realy have problems using the gethour in my rules i have posted about it a few times

Thanks again Vincent Appreciate that although i feel slightly stupid now

running the rule at 9 worked perfect

21:02:03.783 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command ON
21:02:03.785 [INFO ] [g.eclipse.smarthome.model.script.RULE] - Time Based Lighting 8PM <> 10PM FINISHED
21:02:03.786 [INFO ] [smarthome.event.ItemStateChangedEvent] - Timebasedlighting changed from OFF to ON
21:02:03.795 [INFO ] [smarthome.event.ItemStateChangedEvent] - System_Status changed from MOVIE MODE to AMP RULE DISABLED
21:02:03.796 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Lamp1_Brightness' received command 30
21:02:03.798 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'BULB6LRMAIN1_Color' received command 39,87,30
21:02:03.799 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Timebasedlighting' received command OFF
21:02:03.799 [INFO ] [smarthome.event.ItemStateChangedEvent] - Timebasedlighting changed from ON to OFF
21:02:04.442 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'Lightsareon' received command ON

I will look into this more now i can see the problem