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.