Simple sunrise and sunset script

Im trying to create a simple sunrise / sunset rule to turn on/off garage lights. After hours of looking at examples, I came up with the basic rule(s) pasted below. The only issue, is it doesnt work. Also, is there a way to test this script without waiting for sunrise / sunset?

Thanks for any help!

logfile:
2017-12-10 17:23:32.409 [ChannelTriggeredEvent ] - astro:sun:local:set#event triggered START
2017-12-10 17:23:32.438 [ChannelTriggeredEvent ] - astro:sun:local:daylight#event triggered END

items:
Switch Outside_garage_lights {channel=“zwave:device:f70f9c12:node3:switch_binary”}

sitemap
Frame label=“Outside Lights” {
Switch item=Outside_garage_lights label=“Outside Garage Lights”
}

rule:
//SUNRISE AND SUNSET

rule "turn outside lighting on"
when
Channel ‘astro:sun:local:set#event’ triggered START
then
Outside_garage_lights.sendcommand(ON)

rule "turn outside lighting off"
when
Channel ‘astro:sun:local:rise#event’ triggered START
then
Outside_garage_lights.sendcommand(off)
end

end

Well, I see one error, both of my "end"s are at the bottom of the file. Sure that does not help.

u can always test rules with TimeCRON

you have 2x “end” at the end of your rule - you need to close each rule with “end” before you start with the next rule

also you have (on) and (OFF) - its case sensitive :wink:

rule "turn outside lighting on"
when
     // Channel ‘astro:sun:local:set#event’ triggered START or
     Time cron "0/5 * * * * ?"        // every 5 Seconds   0:05 / 0:10 / 0:15
then
     Outside_garage_lights.sendcommand(ON)
end

rule "turn outside lighting off"
when
     // Channel ‘astro:sun:local:set#event’ triggered START or
     Time cron "0/10 * * * * ?"        // every 10 Seconds   0:10 / 0:20 / 0:30
then
     Outside_garage_lights.sendcommand(OFF)
end

but maybe you are looking for a “NIGHT STATE” Switch - check this out:

Here’s a simple ASTRO based sunrise/sunset rule I use…

Please notice the cAsE of your ON/off commands…they should both be UPPER CASE.

rule "turn landscape lighting off"
when
    Channel 'astro:sun:home:rise#event' triggered START 
then
    FntLandscapeLights.sendCommand(OFF)
    BckLandscapeLights.sendCommand(OFF)
end

rule "turn landscape lighting on"
when
    Channel 'astro:sun:home:set#event' triggered START 
then
    FntLandscapeLights.sendCommand(ON)
    BckLandscapeLights.sendCommand(ON)
end

As others have pointed out as well you need to place the end statement after each rule.

This might work. I setup the files, changed the “geolocation” and added my lights. I also added a night switch to my sitemap. I all works manually, waiting on night time…

Thanks!

Please be aware that you used smart quotes (but maybe this was only in the posting, as Discourse changes quotes to smart quotes if the text is not set in code fences. Please use
```

'Your Code' goes here with "Quotes"

```
to post Code.

Without Code fences this will be changed, even if later changing the text to Code:

‘Your Code’ goes here with “Smart Quotes”

As the quotes look nearly the same in standard font, this is a common error. So please ensure you didn’t use smart quotes at all as openHAB does not work correctly with smart quotes.

Thanks everyone, looks like its working!

2017-12-11 17:20:00.082 [ItemStateChangedEvent ] - NightState changed from OFF to ON
2017-12-11 17:20:00.091 [ItemCommandEvent ] - Item ‘Outside_garage_lights’ received command ON
2017-12-11 17:20:00.149 [ItemStateChangedEvent ] - Outside_garage_lights changed from OFF to ON
2017-12-11 17:20:00.159 [ItemStateChangedEvent ] - ZWaveSerialController_FramesAcknowledged changed from 29 to 30
2017-12-11 17:20:00.160 [ItemStateChangedEvent ] - ZWaveSerialController_StartFrames changed from 44 to 45
2017-12-11 17:20:00.164 [ItemStateChangedEvent ] - ZWaveSerialController_StartFrames changed from 45 to 46
2017-12-11 17:20:01.930 [ItemCommandEvent ] - Item ‘Milk_Glass_lamp’ received command ON
2017-12-11 17:20:01.935 [ItemStateChangedEvent ] - Milk_Glass_lamp changed from UNDEF to 100

Any changes need to this script for OH 2.2? After upgrading from 2.1 > 2.2 the sunset and sunrise times no longer display on the sitemap page.