Cron rule controled by the user

  • Platform information:
    • Hardware: _ 32 bits 2MB RAM
    • OS: _Linux xubuntu 18
    • openHAB version: 2.5
  • Issue of the topic: the idea is: I have a cron rule like:
    rule “Monday at HH switch on TV”
    Time cron “0 0 20 ? * MON *”
    logWarn(“mylog”,“TV switched ON”)

I wish to let the user configure the hour ( a number between 0 and 23 in the sitemap) changing the “20” by a variable “mon-tvswitchon”. But unfortunately I have no idea how to create the variable in rules, neither how to configure the needed input in sitemap…

The final idea is to have a user panel in which the user will be able to chose from Monday to Sunday:
a switch on hour + minute
a switch off hour + minute

I would create 14 rules (1 for each weekday switch on, and 1 for each weekday switch off)
Any idea will me very appreciate.

You can’t. Cron expressions used to trigger rules are fixed and hard coded.

For OH 2.5 see one of the many Alarm Clock examples posted here to the forum.

For OH 3, create a DateTime Item, configure the card per OH 3 Examples: How to boot strap the state of an Item. When that Item changes trigger a rule to set a Timer to do the actions at the time chosen.

An additional way to handle stuff like this includes the Time of Day Design Pattern. There is even a couple of versions of that you can just download and use, configuring using Items. You don’t even have to write or edit any code.

Thanks so much to point me in the right way!!