# Day rhythm rule

Hi

I’m trying to make a daylight rythm with tunable white Hue lamps.
I have two dimmer items, one for the color temperature and one for the brightness
The color temperature should change over time, so in the morning the warm color is on, and at 12PM the color is cold. so the color should change a little every 15 minutes.
And again changing slowly to warm, so at afternoon the color should be warm again.

So if i turn on the light on the wall switch it should trigger the my rule and then turn on the light at the right color temperature, and as long as the light is on, the color should change evert 15 minutes.

I did try to make a rule, but I do not know if this is the easiest or best way to do this, I did’t make the rule, but only for an example of how I intended to do,

``````// Dynamisk lys

rule "Dynamic rule"
when
Time cron "0 15/1 0 ? * * *"	or //Run every 15 minute
Item ihc_outlet1 changed	//my test switch

then

var Number minutes = now.getMinuteOfDay
logInfo("Dynamic light", "SayText: {}","It is time to change color temperature, the minutes of the day is now " + minutes)

if (minutes >= 1 && minutes <=14)	// the time is between 00:00 - 00:14
{
logInfo("Dynamic light", "SayText: {}","The time is between 00:15 & 00:30, exactly " + Ntp.state.format("%1\$tR") )
// Save the state to later use when the light turns on by the switch
}

if (minutes >= 15 && minutes <=30)	// the time is between 00:15 - 00:30
{
logInfo("Dynamic light", "SayText: {}","The time is between 00:15 & 00:30, exactly " + Ntp.state.format("%1\$tR") )
// Save the state to later use when the light turns on by the switch
}

if (minutes >= 31 && minutes <=44)	// the time is between 00:31 - 00:44
{
logInfo("Dynamic light", "SayText: {}","The time is between 00:31 & 00:44, exactly " + Ntp.state.format("%1\$tR") )
// Save the state to later use when the light turns on by the switch
}

if (minutes >= 45 && minutes <=59)	// the time is between 00:45 - 00:59
{
logInfo("Dynamic light", "SayText: {}","The time is between 00:45 & 00:59, exactly " + Ntp.state.format("%1\$tR") )
// Save the state to later use when the light turns on by the switch
}

if (minutes >= 60 && minutes <=74)	// the time is between 01:00 - 01:14
{
logInfo("Dynamic light", "SayText: {}","The time is between 01:00 & 00:14, exactly " + Ntp.state.format("%1\$tR") )
// Save the state to later use when the light turns on by the switch
}

if (minutes >= 75 && minutes <=89)	// the time is between 01:15 - 01:29
{
logInfo("Dynamic light", "SayText: {}","The time is between 01:15 & 01:29, exactly " + Ntp.state.format("%1\$tR") )
// Save the state to later use when the light turns on by the switch
}

if (minutes >= 90 && minutes <=105)	// the time is between 01:30 - 01:44
{
logInfo("Dynamic light", "SayText: {}","The time is between 01:30 & 01:44, exactly " + Ntp.state.format("%1\$tR") )
// Save the state to later use when the light turns on by the switch
}

if (minutes >= 106 && minutes <=119)	// the time is between 01:45 - 01:59
{
logInfo("Dynamic light", "SayText: {}","The time is between 01:45 & 01:59, exactly " + Ntp.state.format("%1\$tR") )
// Save the state to later use when the light turns on by the switch
}

if (minutes >= 120 && minutes <=134)	// the time is between 02:00 - 02:14
{
logInfo("Dynamic light", "SayText: {}","The time is between 02:00 & 02:14, exactly " + Ntp.state.format("%1\$tR") )
// Save the state to later use when the light turns on by the switch
}

//and so on......

end

``````

I would separate the calculations of the color temp from the light switch Rule.

Have one Rule that runs every 15 minutes that calculates the right color temp for that time of day and stores it in a going variable or item. Then iterate through all the lights and charge the color temp to the new value for all the lights that are on.

If you can send the new color temp without turning on the lights, send the new color temp to all the lights and you are done.

If you can’t, Then you need a proxy item for each light. Put the proxy on your sitemap and use them in all your rules. When the proxy receives a command on, it triggers a separate rule that sends the item linked to the actual light the currently calculated color temp.

Please be aware that your Time cron is wrong. It should be

``````Time cron "0 0/15 * * * ?"    // every 15 Minutes, beginning at 0
``````

You could also use

``````Time cron "0 0/15 * ? * *"    // every 15 Minutes, beginning at 0
``````

The first one is “At the full minute, every 15 Minutes, beginning with the full hour, every hour, every day in the month, every month in the year, don’t care about day of the week”
The second one is the same, except “don’t care about day in month, every day of the week”

It doesn’t matter in this case, but if you want to use limits on day of week, you must use the question mark instead of day of month. If you want to limit the day of month, you must use the question mark instead of day of week. You have to use exactly one question mark in the Time cron expression, either day or day of week.

Year is optional, so I omitted.