[SOLVED] Design Pattern: Time Of Day - Working with lights

Hi Everyone,

I’ve been using the Time Of Day Design Pattern for some time now, using to switch on and off lights at the right time of day for example.

Now that I’m getting a little more confident in how rules are implemented I’d like to clean up an issue I have at present, from using this design pattern.

In my living room I have four light sources, ceiling, floor lamp, table lamp and some fancy twig lights. The ceiling lights are rarely used so out of the equation for now. Using the design pattern and additional inputs from my TV and Illumination sensor I have a good control over the lights, when the light dims and the TV is on the lights become brighter as it gets darker.

To achieve this I check to see if it currently DAY or EVENING then check that the Lux level is below 100. This works great for when it’s getting darker, however as a consequence I have found that because the same reads true in the morning, my Living Room lights are on first thing in the morning. This is because the time of day is DAY and the Lux level is below 100.

Has anyone else found this sort of problem previously and cleverly resolved it? I’m looking for ideas, as I can’t think of a viable solution that works.

Thanks for your help and advise.

Add a MORNING time of day state that ends after the sun has come up enough for the Lux to not be that low.

That would probably be the simplest.

If this is a single one off case where you do something different in the morning, you can do the old fashioned:

if(now.getHourOfDay < 5 && now.getHourOfDay < 10) return;

There are additional approaches you can do that are more complex and may be worth pursuing, but only if you have or plan to have lots of special cases like this. For example, rather than just having vTimeOfDay represent one state, it can represent multiple states (e.g. both DAY and MORNING).

Thanks for your reply @rlkoshak, I’ll use your example for the time being and keep looking for further ideas.