Sun (raised / set) indicator

Hi Graig,
Even though I do not live in an area that suffers much from power outages, outages sometimes occur.
Besides that, I am very much in favor of making a fault tolerant system. And because the Raspberry PIs are reasonably cheap, I also consider making a redundant system with two RPi’s power and Li-Ion battery backup.
(Noticed there are others who are also working on HA/Redundancy.)

So, i am very much interested if your rule with initialization and wonder if you had the time to test it further?

Hi @deltabert,

Apologies for my late response.

To give you an update, my lighting and startup rules are working very reliably. It’s been working very well for months now on my SD card (I’ll be migrating to SSD soon). Only once did my sunrise rule not trigger for some reason, so my wife unplugged the Pi and plugged it back in and the startup rule set the lights accordingly.

I don’t have access to y setup as I am away but I’ll post it when I’m back.

It looks similar to my dummy setup on my laptop which is as follows:

Light.items

/* -----------------Groups---------------- */
Group:Dimmer:OR(ON,OFF) Lights_All			"All Lights [%d]"			<light>
Group:Dimmer:OR(ON,OFF) Lights_Outdoor		"Outdoor Lights [%d]"		<light>		(Lights_All)
Group:Dimmer:OR(ON,OFF) Lights_Indoor		"Indoor Lights [%d]"		<light>		(Lights_All)

/* -----------------Lights----------------- */
// Outdoor
Dimmer Light_Front_Door_1		"Front Door 1 [%d %%]"		   	<light>		                 {channel=""}
Dimmer Light_Front_Door_2		"Front Door 2 [%d %%]"		   	<light>		                 {channel=""}   
Dimmer Light_Front_Door			"Front Door [%d %%]"			<light>		(Lights_Outdoor)
Dimmer Light_Patio_1			"Patio 1 [%d %%]"		   		<light>		                 {channel=""}
Dimmer Light_Patio_2			"Patio 2 [%d %%]"		   		<light>		                 {channel=""}
Dimmer Light_Patio				"Patio [%d %%]"			    	<light>		(Lights_Outdoor)
Dimmer Light_Braai 				"Braai [%d %%]"				    <light>		(Lights_Outdoor) {channel=""}
Dimmer Light_Kitchen_Porch		"Kitchen Entrance [%d %%]"		<light>		(Lights_Outdoor) {channel=""}
Dimmer Light_Backyard 			"Back yard [%d %%]"			    <light>		(Lights_Outdoor) {channel=""}
Dimmer Light_Adi_Deck			"Adi's deck [%d %%]"		    <light>		(Lights_Outdoor) {channel=""} 	

// Indoor
Dimmer Light_Study 				"Study [%d %%]"				    <light>		(Lights_Indoor)  {channel=" "}

Virtual.items (for proxy switches)

/* -----------------General---------------- */

Switch NightState         	"Night"
Switch LateNightState     	"Late at Night"
Dimmer Dummy_Slider		  	"Dummy slider"
Dimmer Dummy_Switch		  	"Dummy switch"
DateTime Current_Time	  	"Date [%1$tA, %1$tm/%1$td/%1$tY %1$tT]"		<calendar>		{channel="ntp:ntp:local:dateTime"}

// Create string items for panel names to link dashboards 

Astro.items:

/* -----------------Groups---------------- */
Group gAstro "Astronomical Data"

/* -----------------Astro---------------- */
// Sun
DateTime	Sunrise_Start	"Sunrise Start [%1$tH:%1$tM]"	(gAstro)	{channel="astro:sun:f0276b48:rise#start"}
DateTime	Sunset_Start	"Sunset Start [%1$tH:%1$tM]"	(gAstro)	{channel="astro:sun:f0276b48:set#start"}

And my rules…

Startup.rules:

rule "OpenHAB system started - Astro"
when
    System started
then
    logInfo("System started rule trigerred", "--> System started")
	val LateAtNight = now.withTimeAtStartOfDay.plusHours(22).millis // 10 PM
    createTimer(now.plusSeconds(60)) [ |
        if (now.isAfter((Sunset_Start.state as DateTimeType).calendar.timeInMillis) ||
            now.isBefore((Sunrise_Start.state as DateTimeType).calendar.timeInMillis))
        {
        	logInfo("NightState updated", "--> NightState set to ON")
            postUpdate(NightState, ON)
        } else {
        	logInfo("NightState updated", "--> NightState set to OFF")
            postUpdate(NightState, OFF)
        }
        if (now.isAfter(LateAtNight) || now.isBefore((Sunrise_Start.state as DateTimeType).calendar.timeInMillis)){
        	logInfo("LateNightState updated", "--> LateNightState set to ON")
        	postUpdate(LateNightState, ON)	
        } else {
        	logInfo("LateNightState updated", "--> LateNightState set to OFF")
        	postUpdate(LateNightState, OFF)
        }
        val Craig_Presence = Presence_Craig.state
        postUpdate(Presence_Craig, Craig_Presence)
    ]
end

DayNight.rules:

rule "Switch NightState to ON at sunset"
when
    Channel 'astro:sun:f3c3056b:set#start' triggered START
then
	postUpdate(NightState, ON)
    logInfo("NightState updated", "--> NightState set to " + NightState.state)
end

rule "Switch NightState and LateNightState to OFF at sunrise"
when
    Channel 'astro:sun:f3c3056b:rise#start' triggered START
then
	postUpdate(NightState, OFF)
    postUpdate(LateNightState, OFF)
    logInfo("NightState updated", "--> NightState set to OFF")
    logInfo("LateNightState updated", "--> LateNightState set to OFF")
end

rule "Switch LateNightState to ON at 22h00"
when
    Time cron "0 0 22 1/1 * ? *"
then
	postUpdate(LateNightState, ON)
    logInfo("LateNightState updated", "--> LateNightState set to " + LateNightState.state)
end

Lighting.rules:

rule "Switch lights on at night"
when
	Item NightState changed 
then
	if (NightState.state == OFF) {
		logInfo("Daytime", "--> Lights " + NightState.state)
		sendCommand(Lights_All, OFF)
	} else {
		sendCommand(Lights_Outdoor, 40)
		logInfo("Night time", "--> Lights on")
		sendCommand(Light_Study, 40)
	}	
end

rule "Adjust lights late at night"
when
	Item LateNightState changed to ON
then
	logInfo("Late at night", "--> Outside lights on full")
	sendCommand(Lights_Outdoor, 100)
	sendCommand(Light_Study, OFF)	
end

rule "Update patio lights"
when 
	Item Light_Patio changed
then
	val SliderValue = Light_Patio.state as Number 
	sendCommand(Light_Patio_1, SliderValue)
	sendCommand(Light_Patio_2, SliderValue)
end

rule "Update front door lights"
when 
	Item Light_Front_Door changed
then
	val SliderValue = Light_Front_Door.state as Number 
	sendCommand(Light_Front_Door_1, SliderValue)
	sendCommand(Light_Front_Door_2, SliderValue)
end

Please note my design goal was to have as few rule components as possible and so I use proxy switched (virtual items) for monitoring events and triggers.

Any comments / criticism welcome.

I hope that helps,

Craig

1 Like

Nice, I have to steal some of those ideas :slight_smile:

The main difference in my setup is that I try to merge outside light levels into the decision whether my rollershutters should go up or down…

I was thinking about doing a similar thing with light levels. For instance, if you have a room that is particularly dark, such as a cellar, and you have a motion sensor in it, when you walk in the lights should come on at the same level as the current ambient light in another room filled with natural light. This would probably need a lux sensor in the brighter room to provide the reference level. The effect would be that the person entering the room would not even notice that it is lit. Has anyone achieved this?

1 Like

Hi Creg,

Thank you very much for sharing your configs. My vacation came in between, but now i am again working on my oh system and using your example. I am working on switching lights some time after sunset, and would like to vary this time daily, to simulate normal habitation.

It is late, but again, thank you.
Regards, Bert

rule “Switch NightState to ON at sunset”
when
Channel ‘astro:sun:f3c3056b:set#start’ triggered START
then
postUpdate(NightState, ON)
logInfo(“NightState updated”, "–> NightState set to " + NightState.state)
end

Hi Craig,

Is it possible to add offset to the rule event?
For instance I want turn the lights on 30 minutes before sunrise…
I know you can add offset to the event in the Paper UI, but is it also possible to do this in the rules file?

Greetings
Jonathan

Not directly, but why not using the things configuration, see the docs examples:

http://docs.openhab.org/addons/bindings/astro/readme.html#full-example