rule "OpenHAB system started - astro"
when
System started
then
createTimer(now.plusSeconds(180)) [ |
if (now.isAfter((SunsetTime.state as DateTimeType).calendar.timeInMillis) ||
now.isBefore((SunriseTime.state as DateTimeType).calendar.timeInMillis)
) {
postUpdate(NightState, ON)
} else {
postUpdate(NightState, OFF)
}
]
end
rule "Update NightState"
when
Item SunElevation changed
then
if(SunElevation.state > 0){
if(NightState.state != OFF) postUpdate(NightState, OFF)
} else {
if(NightState.state != ON) postUpdate(NightState, ON)
}
end
rule "Night has started"
when
Item NightState changed to ON
then
logInfo("RULE", "Night has started!")
sendCommand(RELAY1, ON)
sendCommand(RELAY2, ON)
end
rule "Night has ended"
when
Item Nightstate changed to OFF
then
logInfo("RULE", "Night has ended!")
sendCommand(RELAY1, OFF)
sendCommand(RELAY2, OFF)
end
2016-12-25 07:36:05.835 [ItemStateChangedEvent ] - SunElevation changed from -0.61 to -0.43
2016-12-25 07:37:05.844 [ItemStateChangedEvent ] - SunElevation changed from -0.43 to -0.25
2016-12-25 07:38:05.837 [ItemStateChangedEvent ] - SunElevation changed from -0.25 to -0.08
2016-12-25 07:39:05.839 [ItemStateChangedEvent ] - SunElevation changed from -0.08 to 0.10
2016-12-25 07:39:05.865 [ItemStateChangedEvent ] - NightState changed from ON to OFF
2016-12-25 07:40:05.835 [ItemStateChangedEvent ] - SunElevation changed from 0.10 to 0.27
2016-12-25 07:41:05.836 [ItemStateChangedEvent ] - SunElevation changed from 0.27 to 0.45
2016-12-25 07:42:05.839 [ItemStateChangedEvent ] - SunElevation changed from 0.45 to 0.62
2016-12-25 07:43:05.840 [ItemStateChangedEvent ] - SunElevation changed from 0.62 to 0.80
openhab.log
2016-12-24 21:15:01.850 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /ui
2016-12-24 21:15:02.054 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2016-12-24 21:15:02.252 [INFO ] [ui.habmin.internal.servlet.HABminApp] - Started HABmin servlet at /habmin
2016-12-24 21:15:04.343 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled astro DailyJob at midnight for thing astro:moon:local
2016-12-24 21:15:04.349 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled astro DailyJob at midnight for thing astro:sun:local
2016-12-24 21:15:05.805 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled astro DailyJob at midnight for thing astro:sun:home
2016-12-24 21:15:05.814 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled astro PositionalJob with interval of 60 seconds for thing astro:sun:home
2016-12-24 21:15:05.850 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled astro DailyJob at midnight for thing astro:moon:home
2016-12-24 21:15:06.675 [INFO ] [.eclipse.smarthome.model.script.RULE] - Night has started!
2016-12-24 21:15:06.686 [WARN ] [ding.astro.handler.AstroThingHandler] - The Astro-Binding is a read-only binding and can not handle commands
2016-12-24 21:15:06.698 [WARN ] [ding.astro.handler.AstroThingHandler] - The Astro-Binding is a read-only binding and can not handle channel updates
2016-12-24 21:15:06.701 [WARN ] [ding.astro.handler.AstroThingHandler] - The Astro-Binding is a read-only binding and can not handle commands
2016-12-24 21:15:06.712 [WARN ] [ding.astro.handler.AstroThingHandler] - The Astro-Binding is a read-only binding and can not handle channel updates
2016-12-25 10:27:23.902 [WARN ] [ding.astro.handler.AstroThingHandler] - The Astro-Binding is a read-only binding and can not handle commands
2016-12-25 10:27:23.909 [WARN ] [ding.astro.handler.AstroThingHandler] - The Astro-Binding is a read-only binding and can not handle channel updates
2016-12-25 10:27:24.661 [WARN ] [ding.astro.handler.AstroThingHandler] - The Astro-Binding is a read-only binding and can not handle commands
2016-12-25 10:27:24.668 [WARN ] [ding.astro.handler.AstroThingHandler] - The Astro-Binding is a read-only binding and can not handle channel updates
rule "example trigger rule"
when
Channel 'astro:sun:home:rise#event' triggered START
then
...
end
This will give an ON with no duration, means it will switch to OFF right after the ON.
I you need a steady ON/OFF you can use the above rule and use a proxy item.
Thank you! I do (and did) see that in the paper UI. Even so I don’t have an example on how to reference this event vs. the non offset events. Also having a predefined number (there are 13 ?) is probably not the way to go either as I don’t see that working for vast population that we all hope end up using openHAB. It could easily be a limitation of the UI as it stands currently and the devs trying to get something out there that we can use (or more probably I’m just not very smart) but it seems to be a limitation that will bite us sooner rather than later. In any case, thank you for the info. I might set something up with this once I learn more … but I’m really hoping for some textual config. Perhaps Kai will have info along this line – or at least some alternative.
I did just find Defining Channels though and that may be more what I’m looking for.
Great that offsets finally become available. Thanks for your link too, Bruce! Would be great if you can “duplicate” a channel in Paper UI though (and then set properties individually).
In addition to the sample rules I will provide my easy solution for a light which switches on at 6am and goes off a couple of minutes after sunrise completes. If sunrise is already completed by 6am, the light will not go on at all.
import org.joda.time.*
import org.openhab.core.library.types.*
var Timer tMorningLightOff
rule "ruleMorningLightOnAndOff"
when
Time cron "0 0 6 ? * MON-FRI"
then
var DateTime dtSunRiseEnd = parse(astroSun1AmsterdamRiseEndDateTime.state.toString)
if(now < dtSunRiseEnd){
sendCommand(hueMediumGlobeDimmer, 30)
tMorningLightOff = createTimer(dtSunRiseEnd.plusMinutes(15)) [|
sendCommand(hueMediumGlobeDimmer, 0)
]
}
end
In an attempt to solve this problem in a way that I actually understand, I thought, I know … I’ll just be create multiple locations that I can reference all along the same latitude. If the longitude that I reference is 15 degrees apart from my own, then the sunset times of the other location will be an hour different (360 degrees / 24hrs per day = 15 degrees per hour).
Warning (Danger Danger) - The below is not tested as of this post! Use at your own risk.
So in my things file (sanitized in this example below for my protection) I now have:
astro:sun:home [ geolocation=“45.000000,-80.000000”, interval=60 ]
astro:moon:home [ geolocation=“42.000000,-80.000000”, interval=60 ]
Then if I want to turn on a light, say 60 mins before sunset I can simply:
// Stairwell Lights On at Sunset - 1 hour.
rule "Stairwell Lights On - Sunset - 1 hour"
when
Channel 'astro:sun:minus60:set#event' triggered START
then
sendCommand(swStairway, ON)
end
It looks like this should work out well until I can figure out how to do the offsets in a file. In the end I might not want them there but I don’t understand how to use them as they are - or even how to reference them if I define them.