Please use code fences:
```
code goes here
```
It is really difficult to read code when it is not properly formatted.
I recommend:
To apply this Design Pattern you would create a Number Item for each Light named in such a way as to easily construct the Number Item’s name given its associated Light Item. Put these number Items into a Group and use the code example to get a reference to the Number Item associated with a given Light.
The only part that is not addressed by the design pattern above is how to bootstrap the Number Items. To do this create a System started rule that populates the Number Items with an initial value. If you are using persistence with restoreOnStartup you can eliminate this rule after it runs the first time.
An advantage with this approach is, should you choose to, you can put the Number Items on your sitemap with a Setpoint or Slider and adjust the times without editing your rules.
This addresses part of your problem. The second part of your problem is determining whether the light is allowed on at night and/or during the day.
You can solve this part of the problem the same way, with associated Items. But I would solve it a different way, with Groups.
Create a Group for each of the time periods you care about. in your example you would have a gNightLights group and a gDayLights group.
Add each light to the appropriate Group or Groups.
I recommend tracking your time of day using the Time of Day Design Pattern and make sure the value of TimeOfDay matches what you use in your Group names.
Now, before turning on a light you just need to:
if(light.groupNames.contains("g"+TimeOfDay.state.toString+"Lights")) {
// its OK to turn on the light
}
Finally, I’ll mention that you should look into the Expire binding for your timers. Those coupled with Associated Items and Working with Groups in Rules can drastically reduce the amount of code required to do things like this.