Lights on Rule With Weather Conditions

I am trying to setup a rule that triggers lights when my cloud value is higher than 60. Basically, when it starts getting a little darker outside, I want the lights to come on.

I have it working with a dummy switch now, but I have to hard code the hours. I’d like to use the hours from the astro binding, but I don’t know how to do that.

rule "Lights for Clouds On"
when
	Item weather_clouds changed
then
	if ( now.getHourOfDay > 7 && now.getHourOfDay < 18 ) {
		if  ( weather_clouds.state > 60 ) {
			dummy.sendCommand(ON)
		}
	}
end

Instead of using now.GetHourOfDay compared to a number, I’d like to compare that to the sunrise and sunset events. Basically, if this hour is within the range of sunrise and sunset, then trigger, but if it’s at night time, then don’t trigger.

The items I have right now are:

DateTime        	sunset_time     	"Sunset [%1$tH:%1$tM]"			<sun>			(astro)							{channel="astro:sun:home:set#start"}
DateTime        	sunrise_time    	"Sunrise [%1$tH:%1$tM]"		<sun>		 (astro)         						{channel="astro:sun:home:rise#end"}

Any help is greatly appreciated,

Will

Sounds like you should use Astro to create a daytime or nighttime switch (or both if you want) and include that in the rule so it triggers only when it is day time.

Would the following work?

if ( now.getHourOfDay > sunrise_time.state && now.getHourOfDay < sunset_time.state )

Have a look into the Design Pattern: Time of Day

1 Like

No. .getHourOfDay is of Type Integer, while DateTime Item status is, well… DateTime:wink:

2 Likes