Help with heating/time rule

It would be more dynamic if you used timers instead of a 30 minute polling period. Then you could trigger the rule only when one of the times change and around midnight to reschedule the timers for the next day.

If you use MainUI or can figure out how to update a DateTime Item in HABPanel you could trigger rules based on the state of those Items.

So these are mutually exclusive. You’ve never have TimerMorgensan and TimerMorgensaus active at the same time. So just have one Item and set its state based on the currently active state. For example, have a String Item named WohnzimmerHeizung_State and set it to “TimerMorgensan”, “TimerMorgensaus” etc.

If I were to implement this I’d do the following.

  1. Create a separate DateTime Item for each room and each time state (i.e. TimerMorgensan, TimerMorgensaus, etc.). This assumes that each room has a different set of times. So if you have four rooms and four states, you’d have 16 Items.
  2. Use an input card with the “type” set to “time” This generates a widget that looks like this.

  1. If these Items are in the semantic model, they will automatically appear on the locations tab of the Overview Page in the right rooms. Otherwise I’d crate a page for them to have a place to edit them. But the semantic model makes it really nice, the UI creates itself.

  2. The rules could be handled in a bunch of different ways. Probably the simplest would be to create separate rules which could be triggered by one of the Items above using the Time is <item> trigger. Then all you need to do is command the Item as appropriate (presumably setting the thermostat setpoint in that room). You could use just UI rules and not even need to write code for that and you don’t need a separate Item to keep track of the current time state.
    Another approach could be to consolidate all the rules for a given rule into one but this will require keeping track of the time of day state separately from the rules that do the work. You could use Time Based State Machine [3.2.0;3.4.9], or just create a separate simple rule triggered by Time is <item> triggers that commands a String Item with the current time of day state (e.g. “TimerMorgensan”). If you have more than one “schedule” per room, you’d have one String Item per room. Then you’d have a rule triggered when that String Item receives a command or changes and you can use a simple switch statement to set the setpoint based on the String the state Item changed to.
    Yet another approach would be to create a universal rule for all rooms. In this approach I would use the Time Based State Machine to send a command to a String Item. The command will include the room name and the time of day state. This will trigger a rule which has a switch statement on the room+state to update the setpoint accordingly. That rule could be made simpler by using Design Pattern: Associated Items. So, for example, if the room is the first part of your setpoint’s Item name and “thermostat” is the second part the consolidated rule and you put the setpoints into Items with a predictable pattern using those it would look something like:

import org.eclipse.smarthome.model.script.ScriptServiceUtil

rule "Heizungssteuerung"
when
    Item Thermostat_State received command
then
    val parts = receivedCommand.toString.split('_')
    val roomName = parts.get(0)
    val timeState = parts.get(1)
    val setpointItemName = roomName+"_"+timeState+"_Setpoint"
    val setpointItem = ScriptServiceUtil.getItemRegistry.getItem(setpointItemName)
    val setpoint = setpointItem.state as Number

    sendCommand(roomName+"_Thermostat", setpoint)
end

That’s it. That’s the full rule which handles all your rooms. But you are trading lots of Items for a simpler rule. And I don’t show the rule that updates the Thermostat_State Item (which drives this whole thing) because you’d just install that from the marketplace.