Simple time Selection for Shutter movement

Hi guys,

so far I use a simple rule that changes an item “night” to ON when the astro channel for dusk is triggered or a certain time of a day is reached to shut roller shutters. Similar in the morning where the item “day” is switched on and night is switched of.

Works fine but I would like to have a bit more comfort. I tried to implement a selection with a few options for example dusk, sunset, 20:00, 18:00. However I could not manage to create a selection in DateTime format and then compare it with the current time. I thought of something like this…


DateTime    Sunset          "Sonnuntergang um [%1$tH:%1$tM]" <sunset>    {channel="astro:sun:local:set#end"}
DateTime    Dusk             "Ende Dämmerung [%1$tH:%1$tM]"  <sunset>    {channel="astro:sun:local:civilDusk#end"}
DateTime    ShutterDownTimeSelector 


Selection item=ShutterDownTimeSelector label="Choose when to close shutter" mappings=[dusk="after Dusk", sunset="at sunset", ="at 18:00", ="at 20:00"]


rule "Shutters down"
    Time cron "0 0/1 * 1/1 * ? *"  //every minute

Tried to play around but no solution so far. Thank you for your inputs.

When referring to an Item in a Rule it’s important to realize that the Item carries a whole bunch of stuff like:

  • name
  • label
  • state
  • named of the Groups it belongs to
  • tags
  • metadata (Scripted Automation only)

The only part of the Item that has the date time information, for a DateTime Item, is the state. So you need to us ShutterDownTimeSelector.state to get that date time information.

The second problem is now is not the same type as ShutterDownTimeSelector.state. There are lots of ways to convert it but the easiest is if(now.isAfter(new DateTime(ShutterDownTimeSelector.state.toString))

It’s not clear how ShutterDownTimeSelector is populated but it’s important to remember also that a DateTime is just that, a DateTime, meaning it represents an exact instance in time (e.g. May 11, 2020 15:27:12.234). You can’t use a DateTime Item, by itself, to represent “20:00” every day. You need to regenerate it every day so it represents “20:20 today”.

You would do well to review Design Pattern: Time Of Day which combines Astro events and static times or DateTimes from any source in a central location to calculate a given time of day. It figures out what time it is when the Rule runs and updates an Item. Then you could use as your Rule:

    Item vTimeOfDay changed to NIGHT

openHAB is an event driven system. In general you should try to avoid rules that poll once a minute or whatever. Instead find and/or generate an event to trigger the Rule.

Hey Rich,

thank you for your detailed input. I think it´s still not clear to me but first I´ll try again with these info, hopefully within the next days. I´ll give an update here, just wanted to say thank you for now.

Anybody else with a similar problem/solution is still welcome to share or link.

Another point to take care of:
Your rule will just do what what you tell it to do. So in this case (given you get the correct time to compare) it will close all Shutters in the group once per Minute, regardless whether they are closed or not. I doubt that this is your intention :slight_smile:

now.isAfter() will compare the whole Date and Time, so if your time selector is a DateTime Item, it depends on the exact Date. If it’s not, now.isAfter() will not work at all.

In question of shutters, there is a nice addon, called astro, which gives the ability to close/open the shutters depending on sun position. I’m using the civilDusk/civilDawn events with some extra offset and upper and lower limit, e.g. earliest time to open is 05:30 AM, latest time to open is 08:30 AM, earliest time to close is 4:30 PM and latest time to close is 09:30 PM. astro now will chose the open/close time depending on sun height (civilDusk/civilDawn is 6° under horizon) but will take care of the limits.

The rules for this will execute once a day by using the Channel trigger.