Sunrise - Sunset to switch on lights with variables

Hi,

I have the ASTRO binding online and created items for sunset and sunrise. In Basic UI is show the time the sun rises and when it sets.

In a rule I have defined a static time to switch on the lights in the garden and off.

I have read that using sunrise and sunset events triggered is not that easy.

What is was thinking.

Can I use the time of sunrise and sunset in the astro binding as a variable in my rule? So instead of a fixed time I could use the astro time (which I already display) as a variable. Would this work? And since I am a scripting noob, how would one create that rule?

What excatly do you want to achieve?

Turn on the lights at sunset:

rule "Sunset Rule"
when
    Channel 'astro:sun:local:set#event' triggered START
then
    // Do what you want to do at start of sunset
end
2 Likes

That’s it? I thought it would only switch it on and immediately back off… That’s what I read

The channel generates 2 events START and END
That’s because the sun is a disc not a point so the sunset will START when the sunset starts to disappear below the horizon and END when the sun disappears completely below the horizon.

These events can be used to trigger a rule.

So how would I use the sunrise event then?

so the lights needs to come on at sunset,and switch off at sunrise

that also with a send.command right?

rule "Sunset Rule"
when
    Channel 'astro:sun:local:set#event' triggered START
then
    // Do what you want to do at start of sunset for example:
    // Outside_Lights.sendCommand(ON)
end

rule "Sunrise Rule"
when
    Channel 'astro:sun:local:rise#event' triggered START
then
    // Do what you want to do at start of sunset
    // Outside_Lights.sendCommand(OFF)
end

I recommend using civildawn to turn off the lights in the morning. It’s normally 1 to 2 hours before sunrise and bright enough for cameras and human vision.
It will save you a significant amout of electricity over the year.

astro:sun:local:civilDawn#event triggered START

1 Like

Like this? Do I need to create a item or just use the channel? I didn’t crreate a item for this channel.

Is that ok?

rule "Sunset Rule"

when
Channel ‘astro:sun:local:astroDusk#event’ triggered START
then
GF_Backyard.sendCommand(ON)
end

rule “Sunrise Rule”
when
Channel ‘astro:sun:local:civilDawn#event’ triggered START
then
GF_Backyard.sendCommand(OFF)
end

Just the channel as long as you created the sun:local thing

I will test tonight. The thing is create since I am using the time in my BasicUI

Just make sure that the name of the thing and channels match

Doesn’t seem to work.

rule "Sunset Rule"
when
	Channel "astro:sun:local:civilDusk#event" triggered START
then
			GF_Tuinhuis_Light.sendCommand(ON)
			GF_Voordeur_Light.sendCommand(ON)
			GF_Achterdeur_Light.sendCommand(ON)
end


rule "Sunrise Rule"
when
	Channel "astro:sun:local:civilDawn#event" triggered START
then
		GF_Tuinhuis_Light.sendCommand(OFF)
		GF_Voordeur_Light.sendCommand(OFF)
		GF_Achterdeur_Light.sendCommand(OFF)
end

I don’t see anything in the logs. I see the triggered START but nothing else

Show the log, please

There is nothing there really.

2018-06-22 21:28:03.993 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.875 °C to 22.9375 °C

2018-06-22 21:29:03.208 [vent.ItemStateChangedEvent] - Sonos_State_diningroom changed from PAUSED_PLAYBACK to STOPPED

2018-06-22 21:29:55.262 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.9375 °C to 22.875 °C

2018-06-22 21:30:17.463 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.875 °C to 22.9375 °C

2018-06-22 21:30:50.770 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.9375 °C to 22.875 °C

2018-06-22 21:31:01.860 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.875 °C to 22.9375 °C

2018-06-22 21:33:02.149 [vent.ItemStateChangedEvent] - Zon_straling_dif changed from 20.40 to 0.00

2018-06-22 21:33:02.155 [vent.ItemStateChangedEvent] - Zon_straling_tot changed from 20.44 to 0.00

2018-06-22 21:33:04.436 [vent.ItemStateChangedEvent] - GF_Kitchen_Temperature changed from 22.5625 °C to 22.5 °C

2018-06-22 21:48:04.444 [vent.ItemStateChangedEvent] - GF_Kitchen_Temperature changed from 22.5 °C to 21.9375 °C

2018-06-22 21:57:00.008 [vent.ChannelTriggeredEvent] - astro:sun:local:daylight#event triggered END

2018-06-22 21:57:00.021 [vent.ChannelTriggeredEvent] - astro:sun:local:set#event triggered START

2018-06-22 22:01:00.006 [vent.ChannelTriggeredEvent] - astro:sun:local:civilDusk#event triggered START

2018-06-22 22:01:00.014 [vent.ChannelTriggeredEvent] - astro:sun:local:set#event triggered END

2018-06-22 22:08:04.462 [vent.ItemStateChangedEvent] - GF_Kitchen_Temperature changed from 21.9375 °C to 21.875 °C

2018-06-22 22:18:04.449 [vent.ItemStateChangedEvent] - GF_Kitchen_Temperature changed from 21.875 °C to 21.9375 °C

2018-06-22 22:23:04.466 [vent.ItemStateChangedEvent] - GF_Kitchen_Temperature changed from 21.9375 °C to 22.5 °C

2018-06-22 22:36:46.281 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.9375 °C to 22.875 °C

2018-06-22 22:37:08.489 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.875 °C to 22.9375 °C

2018-06-22 22:38:04.455 [vent.ItemStateChangedEvent] - GF_Kitchen_Temperature changed from 22.5 °C to 22.5625 °C

2018-06-22 22:38:15.364 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.9375 °C to 22.875 °C

2018-06-22 22:38:26.461 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.875 °C to 22.9375 °C

2018-06-22 22:38:48.668 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.9375 °C to 22.875 °C

2018-06-22 22:38:59.771 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.875 °C to 22.9375 °C

2018-06-22 22:39:10.863 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.9375 °C to 22.875 °C

2018-06-22 22:39:21.964 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.875 °C to 22.9375 °C

2018-06-22 22:39:33.074 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.9375 °C to 22.875 °C

2018-06-22 22:41:12.983 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.875 °C to 22.9375 °C

2018-06-22 22:41:24.097 [vent.ItemStateChangedEvent] - GF_Jornt_Temperature changed from 22.937

2018-06-23 00:23:35.095 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'gardenlights.rules'

Is there another log where I can see the rules execution?

What OH version are you running, please?

Try single quotes instead of double ones in the rules condition.
Insert a logDebug line, too, to see if the rule is triggered.

The problem was actually that it needed double quotes. So this was solved now… thanks

The astro event channels are not triggering the following rules, and I don’t know why.

// Do not operate the roller shutters if the outside temperature is lower than MIN_TEMP
val MIN_TEMP = 3.0|°C

rule "sunrise shutter rule"
when
  Channel 'astro:sun:home:rise#event' triggered START //* DEBUG: */ or Item AT_GuestRoom_Light_Toggle changed to ON
then
  if (Weather_OWM_Current_Temperature.state > MIN_TEMP) {
    logInfo("SunRiseShutterRule", "Roller shutters will open automatically at sunrise, temperature (" + Weather_OWM_Current_Temperature.state + ") above " + MIN_TEMP)
    gShutter.members.forEach[ s | s.sendCommand(UP) ]
  } else {
    logWarn("SunRiseShutterRule", "Roller shutters will NOT open automatically at sunrise, temperature (" + Weather_OWM_Current_Temperature.state + ") below " + MIN_TEMP)
  }
end

rule "sunset shutter rule"
when
  Channel 'astro:sun:home:set#event' triggered START //* DEBUG: */ or Item AT_GuestRoom_Light_Toggle changed to OFF
then
  if (Weather_OWM_Current_Temperature.state > MIN_TEMP) {
    logInfo("SunSetShutterRule", "Roller shutters will close automatically at sunset, temperature (" + Weather_OWM_Current_Temperature.state + ") above " + MIN_TEMP)
    gShutter.members.forEach[ s | s.sendCommand(DOWN) ]
  } else {
    logWarn("SunSetShutterRule", "Roller shutters will NOT close automatically at sunset, temperature (" + Weather_OWM_Current_Temperature.state + ") below " + MIN_TEMP)
  }
end

I’m running OpenHAB 2.4.0 with the astro bindings from 2.4.0. I can pick sunrise and sunset times in my sitemap so the astro bindings are active.

What I see in the openhab.log file, is a set of off-by-one-minute NTP messages in the vicinity of astro events:

2019-02-13 07:59:16.584 [vent.ItemStateChangedEvent] - ntp_ntp_local_dateTime changed from 2019-02-13T07:58:16.577+0100 to 2019-02-13T07:59:16.578+0100
2019-02-13 07:59:16.584 [vent.ItemStateChangedEvent] - ntp_ntp_local_string changed from 2019-02-13 07:58:16 CET to 2019-02-13 07:59:16 CET
2019-02-13 08:00:16.584 [vent.ItemStateChangedEvent] - ntp_ntp_local_dateTime changed from 2019-02-13T07:59:16.578+0100 to 2019-02-13T08:00:16.579+0100
2019-02-13 08:00:16.585 [vent.ItemStateChangedEvent] - ntp_ntp_local_string changed from 2019-02-13 07:59:16 CET to 2019-02-13 08:00:16 CET
2019-02-13 08:01:00.011 [vent.ItemStateChangedEvent] - astro_sun_local_phase_name changed from CIVIL_DAWN to SUN_RISE
2019-02-13 08:01:00.011 [vent.ChannelTriggeredEvent] - astro:sun:local:civilDawn#event triggered END
2019-02-13 08:01:00.011 [vent.ChannelTriggeredEvent] - astro:sun:local:rise#event triggered START
2019-02-13 08:01:16.587 [vent.ItemStateChangedEvent] - ntp_ntp_local_dateTime changed from 2019-02-13T08:00:16.579+0100 to 2019-02-13T08:01:16.580+0100
2019-02-13 08:01:16.588 [vent.ItemStateChangedEvent] - ntp_ntp_local_string changed from 2019-02-13 08:00:16 CET to 2019-02-13 08:01:16 CET
2019-02-13 08:02:16.587 [vent.ItemStateChangedEvent] - ntp_ntp_local_dateTime changed from 2019-02-13T08:01:16.580+0100 to 2019-02-13T08:02:16.581+0100
2019-02-13 08:02:16.588 [vent.ItemStateChangedEvent] - ntp_ntp_local_string changed from 2019-02-13 08:01:16 CET to 2019-02-13 08:02:16 CET
2019-02-13 08:03:16.588 [vent.ItemStateChangedEvent] - ntp_ntp_local_dateTime changed from 2019-02-13T08:02:16.581+0100 to 2019-02-13T08:03:16.582+0100
2019-02-13 08:03:16.589 [vent.ItemStateChangedEvent] - ntp_ntp_local_string changed from 2019-02-13 08:02:16 CET to 2019-02-13 08:03:16 CET
2019-02-13 08:04:06.775 [vent.ItemStateChangedEvent] - astro_moon_local_phase_ageDegree changed from 101.65688965034964 ° to 101.6988476923077 °
2019-02-13 08:04:06.776 [vent.ItemStateChangedEvent] - astro_moon_local_phase_agePercent changed from 28.2380249028749 % to 28.249679914529914 %
2019-02-13 08:04:06.777 [vent.ItemStateChangedEvent] - astro_moon_local_phase_illumination changed from 53.77601701689767 % to 53.81298729142882 %
2019-02-13 08:04:06.779 [vent.ItemStateChangedEvent] - astro_moon_local_distance_date changed from 2019-02-13T07:59:06.761+0100 to 2019-02-13T08:04:06.761+0100
2019-02-13 08:04:06.780 [vent.ItemStateChangedEvent] - astro_moon_local_distance_distance changed from 382934.87215741887 km to 382914.4390588954 km
2019-02-13 08:04:06.780 [vent.ItemStateChangedEvent] - astro_moon_local_position_azimuth changed from 15.36651222933914 ° to 16.596196739669047 °
2019-02-13 08:04:06.781 [vent.ItemStateChangedEvent] - astro_moon_local_position_elevation changed from -22.826291216574464 ° to -22.607248377443078 °
2019-02-13 08:04:07.825 [vent.ItemStateChangedEvent] - astro_sun_local_position_azimuth changed from 110.49255670054949 ° to 111.46158749511538 °
2019-02-13 08:04:07.826 [vent.ItemStateChangedEvent] - astro_sun_local_position_elevation changed from -1.0661384855205718 ° to -0.3326363437178504 °
2019-02-13 08:04:07.826 [vent.ItemStateChangedEvent] - astro_sun_local_position_shadeLength changed from -53.74 to -172.25
2019-02-13 08:04:07.826 [vent.ItemStateChangedEvent] - astro_sun_local_phase_name changed from SUN_RISE to UNDEF
2019-02-13 08:04:16.636 [vent.ItemStateChangedEvent] - ntp_ntp_local_dateTime changed from 2019-02-13T08:03:16.582+0100 to 2019-02-13T08:04:16.632+0100
2019-02-13 08:04:16.637 [vent.ItemStateChangedEvent] - ntp_ntp_local_string changed from 2019-02-13 08:03:16 CET to 2019-02-13 08:04:16 CET
2019-02-13 08:05:00.007 [vent.ChannelTriggeredEvent] - astro:sun:local:daylight#event triggered START
2019-02-13 08:05:00.013 [vent.ChannelTriggeredEvent] - astro:sun:local:rise#event triggered END
2019-02-13 08:05:00.014 [vent.ItemStateChangedEvent] - astro_sun_local_phase_name changed from UNDEF to DAYLIGHT
2019-02-13 08:05:16.638 [vent.ItemStateChangedEvent] - ntp_ntp_local_dateTime changed from 2019-02-13T08:04:16.632+0100 to 2019-02-13T08:05:16.633+0100
2019-02-13 08:05:16.639 [vent.ItemStateChangedEvent] - ntp_ntp_local_string changed from 2019-02-13 08:04:16 CET to 2019-02-13 08:05:16 CET
2019-02-13 08:06:16.640 [vent.ItemStateChangedEvent] - ntp_ntp_local_dateTime changed from 2019-02-13T08:05:16.633+0100 to 2019-02-13T08:06:16.634+0100
2019-02-13 08:06:16.641 [vent.ItemStateChangedEvent] - ntp_ntp_local_string changed from 2019-02-13 08:05:16 CET to 2019-02-13 08:06:16 CET
2019-02-13 08:07:16.640 [vent.ItemStateChangedEvent] - ntp_ntp_local_dateTime changed from 2019-02-13T08:06:16.634+0100 to 2019-02-13T08:07:16.635+0100
2019-02-13 08:07:16.641 [vent.ItemStateChangedEvent] - ntp_ntp_local_string changed from 2019-02-13 08:06:16 CET to 2019-02-13 08:07:16 CET
2019-02-13 08:08:16.641 [vent.ItemStateChangedEvent] - ntp_ntp_local_dateTime changed from 2019-02-13T08:07:16.635+0100 to 2019-02-13T08:08:16.637+0100
2019-02-13 08:08:16.642 [vent.ItemStateChangedEvent] - ntp_ntp_local_string changed from 2019-02-13 08:07:16 CET to 2019-02-13 08:08:16 CET

The openhab.log file remains empty, though:

2019-02-13 00:00:30.113 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:moon:local
2019-02-13 00:00:30.151 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:local

Any clues?