Basic UI Custom/Dynamic item scheduling

Hi,

Here’s the end goal.

Have something like this setup in openhab basic UI. (from victron solar system to schedule battery charging)

My plan is have Item selector, the options for this selector being all the items in the group gScheduleABLE. And have a rule dynamically update the options based on items names of things in that group.

Additionally having a start command and stop command which rules will use to send at the start and end times.

I’m having issues getting this working. Mainly because my selector items are not showing up at all unless i manually edit the options in sitemap rather than .items files.

Here’s my attempt so far (which isnt working). I havent drafted rules yet.

// Schedule 1 Items
String ScheduleItem1 "Schedule Item" (gSchedule1) {
    stateDescription="Options=[HotWater=Hot Water, Heating=Heating, Immersion=Immersion]"
}



String DaySelection1 "Select Day" (gSchedule1) {
    stateDescription="Options=[Everyday=Everyday, Weekdays=Weekdays, Weekends=Weekends, Monday=Monday, Tuesday=Tuesday, Wednesday=Wednesday, Thursday=Thursday, Friday=Friday, Saturday=Saturday, Sunday=Sunday]"
}


String ScheduleItem1StartState "Start Command" (gSchedule1)
String ScheduleItem1StopState "Stop Command" (gSchedule1)
DateTime StartTime1 "Start Time" (gSchedule1)
DateTime EndTime1 "End Time" (gSchedule1)

And then the sitemap:

Frame label="Schedules" {
    Group item=gSchedule1 label="Schedule 1" icon="calendar" {
        Selection item=ScheduleItem1 label="Item to Schedule"
        Selection item=DaySelection1 label="Select Day" mappings=[
             Everyday="Everyday",
             Weekdays="Weekdays",
    Weekends="Weekends",
    Monday="Monday",
    Tuesday="Tuesday",
    Wednesday="Wednesday",
    Thursday="Thursday",
    Friday="Friday",
    Saturday="Saturday",
    Sunday="Sunday"
]
        Input item=ScheduleItem1StartState label="Start Command"
        Input item=ScheduleItem1StopState label="Stop Command"
        Input item=StartTime1 label="Start Time" staticIcon=time inputHint="time"
        Input item=EndTime1 label="End Time" staticIcon=time inputHint="time"
    }
}

Then my first attempt at dynamically updating the options.

rule "Update Selector based on gScheduleABLE"
when
    System started or
    Member of gScheduleABLE changed
then
    // Generate options string dynamically
    var options = newStringBuilder
    gScheduleABLE.members.forEach[ item |
        options.append(item.label).append(",")
    ]

    // Remove trailing comma
    if (options.length > 0) {
        options.deleteCharAt(options.length - 1)
    }

    // Set the state to reflect the options dynamically
    ScheduleItem1.postUpdate(options.toString)
end

Then of course I’ll need rules to loop the schedule items to execute start and stop command strings at the defined time intervals.

Well, typically, one should use either builtin functions (Main UI Settings → Schedule) or an external calendar (see icalendar Addon).
But of course you could build some sort of scheduler sitemap. Be aware that you will always at some point end in a huge mess :slight_smile: and the real question is: is it worth the effort?

a first option of simplification:

  • use seven bits instead of strings for weekday selection: mappings=[1=Monday,2=Tuesday,4=Wednesday,8=Thursday,16=Friday,32=Saturday,64=Sunday,31=Weekday,96=Weekend,127=Everyday] As a result a rule can check whether the bit of the current day is set (something like testBit(now.dayOfWeek.value)

t has been a very long time since I’ve used Sitemaps but I’m pretty sure it doesn’t use the state description options at all. You have to hard code the options in the sitemap. So that’s why you can’t get that to work.

Have you seen Timeline picker to setup heating, light and so on? I think it does most of what you are looking to do.

Of course options in state description are considered by sitemap UIs.

Hi, try this pattern of state description in your items file

String DaySelection1 "Select Day" (gSchedule1) {
    stateDescription=" "[ options="HotWater=Hot Water, Heating, Immersion" ] }

If text is command you don’t need the =

In the sitemap no mapping is needed, the command options is used in the sitemap.

Greets

Thanks after seeing this i was going to head down the main ui → schedule route. Then setup a static number of generic schedules which will read the data from sitemap so users can edit schedules via there rather than needing to open another app/page given all my home automations are controlled via basic ui sitemaps.

I don’t suppose you know if schedules can be configured via text files (or am i just describing rules and schedules are really just rules with a different front end?). I’m a big fan of the text file option with openhab (I find it much quicker to migrate/backup)