How can I use Astro to have a light go on at sunset?

1,740 views
Skip to first unread message

Rob Goodman

unread,
Jul 17, 2015, 11:22:08 AM7/17/15
to ope...@googlegroups.com
Here's what I have so far:

In my OpenHab.CFG file I included the bindings for Astro.

In my ITEMS file I have this:
DateTime Sunset_Time   "Sunset [%1$tH:%1$tM]"   {astro="planet=sun, type=set, property=end"}

I can see that I am returning the correct times because I added this line: Text item=Sunset_Time   to the .SITEMAP file.


My question is, in the Rules file, what is the syntax to have my porch lights go on at sunset? If I was going to have the lights turn on at a specific time (say 6:30 AM), I would do the following:

rule "LampOnMorning"
when Time cron "0 30 6 * * ?"
then  sendCommand(Lamp_Module, ON)
end

How would I do this for the sunset time? I tried replacing cron  "0 30 6 * * ?" with Sunset_Time but it doesn't seem to like it.

Any suggestions on actual code of getting this to work would be very much appreciated.

Thank you.

-Rob

Kevin Gottsman

unread,
Jul 17, 2015, 12:22:18 PM7/17/15
to ope...@googlegroups.com
Rob,

I use the astro binding to turn on my landscape lights every night. They turn off in the morning with the sunrise event.

Here is my items file:
*********
DateTime Sunrise_Time   "Sunrise [%1$tl:%1$tM %1$tp]"  {astro="planet=sun, type=rise, property=start"}
DateTime Sunset_Time    "Sunset [%1$tl:%1$tM %1$tp]"   {astro="planet=sun, type=set, property=end"}
Switch   Sunrise_Event                           {astro="planet=sun, type=rise, property=start, offset=0"}
Switch   Sunset_Event                            {astro="planet=sun, type=set, property=end, offset=0"}
**********

Here is my rules file:
*********
rule "Example Rule at sunrise"
when
    Item Sunrise_Event received update ON
then
    sendCommand(Switch_Landscape, OFF)
end

rule "Example Rule at sundown"
when
    Item Sunset_Event received update ON
then
    sendCommand(Switch_Landscape, ON)
**********
--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
To view this discussion on the web visit https://groups.google.com/d/msgid/openhab/34bd2bdf-2d0a-497e-9274-f75e1a3bc5e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rob Goodman

unread,
Jul 17, 2015, 5:34:32 PM7/17/15
to ope...@googlegroups.com
Kevin,

That was exactly what I was looking for! It is so simple once you know how to do it. I think I was over-thinking it.

Thank you so much for sharing this. This is a great help for me.

-Rob
Reply all
Reply to author
Forward
0 new messages