I currently use cron-based rules for controlling several items.
However, my question now is…is there a structured way of replacing cron with self set schedules, which can be adjusted trough a UI (preferably Habpanel).
Example
When I have a rule like this:
rule "Event start at 15:00 on SAT-SUN"
when
Time cron "0 0 15 ? * SAT,SUN *"
then
// *do stuff*
Is is possible to create the same, but based on a setting from UI, e.g. where I can select the days and set the time for example?
Reason is that I don’t want to go into the rules files all the time when I need to change the schedule(s).
If someone can point me in the right direction…
LOL…I was afraid of it…
Yes I did search and found some ‘workarounds’ but not satisfying so far.
will do some more investigations later tonight in that case…
/Jasper
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
4
If it helps
I’ve modified this to suit my needs and I have to say that they are working really well.
On a similar theme, I’ve adapted the widget to work with the built in timers in the hardware I have… (Ahem… ahem…)
I did try a few of the other options I found on the forum, but nothing really worked for me as I had hoped.
But how does the times set get triggered?
It looks good as a start, but what I miss is the ‘knowledge’ of how these settings are checked by openhab and get triggered…
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
8
Are you asking about the DSL solution or the NodeRed one?
DSL rules check every minute and act as the rule demands.
It’s a rather good solution.
Read the chaps write up carefully and it should make sense.
I’m reading about Joda time… make me wonder if something like this is possible?
when
currentTime.compareTo(setTime) == 0
then
//execute something
end
Since the result of compare to shall be 0 when they match…otherwise it’s -1 or 1.
I see that you can use string types with Parse method to get them to compare to a datetime object…
If this can be achieved, then it should be possible to set hours and minutes and combine them in a string type item (“hh:mm”) and compare this to currentTime…then there is the scheduler…
Or am I too optimistic?
How about a rule that triggers on an Item change, where the action creates/modifies another rule that triggers on the time from the Item in the first rule? This is not possible in the old rule engine, but with scripted automation, you could do something like this…
from core.rules import rule
from core.triggers import when
@rule("Adjust rule trigger")
@when("Item Virtual_DateTime_1 changed")
@when("System started")
def adjust_rule_trigger(event):
adjust_rule_trigger.log.warn("Cron Item changed")
# if rule exists, remove it
try:
rule_uid = [rule_object for rule_object in rules.getAll() if rule_object.name == "Alarm clock"][0].UID
adjust_rule_trigger.log.warn("Alarm clock rule exists, so removing it")
scriptExtension.importPreset("RuleSupport")
ruleRegistry.remove(rule_uid)
except:
pass
# create rule
time = items["Virtual_DateTime_1"].zonedDateTime
@rule("Alarm clock")
@when("Time cron {} {} {} * * ?".format(time.second, time.minute, time.hour))
def alarm_clock(event):
alarm_clock.log.warn("Wake up!")
This adjusts the cron rule based on the time portion of the DateTimeItem’s state. If you’re not using this for a recurring daily timer, it can be easily modified to trigger on a specific date and time. You can use something similar for scheduling through Alexa or the alarm Item updated through Habdroid.