Hello,
so let me try to explain.
Each room as a device, with buttons and a screen, that controls the rooms temperature.
The room temperature regulator has a couple of internal states.
A) A base temperature, usually the comfort temperature
B) an HVAC mode, i.e. comfort, stand-by, night, and frost-protection
C) a temperature offset that can be used locally to deviate from the temperatures programmed into the device
In principle it operates as follows:
var RTR_mode
var target_temperature
var offset // in the range between -10° and + 10°
var base_temperature
switch (RTR_mode)
case "Frost": target_temperature = 7° // or any other fixed temperature
case "Comfort": target_temperature = base_temperature+offset
case "Stand-By": target_temperature = base_temperature-2.0+offset
case "Night": target_temperature = base_temperature-4+offset
You can change the mode locally, and you can change the offset locally. The offset resets after a mode-change.
My plan is to add in OpenHAB for every room items with the desired comfort temperature, stand-by temperature and night temperature.
Changes made on the device should reflect on these items, as well as changes on the items should reflect on the device, when the device switches to the corresponding mode.
My current plan was to have
a) a rule, that would trigger on changes in the mode, calculate the base_temperature and offset, and communicate that to the device.
b) a rule, that would trigger on changes in the target_temperature, read the current mode and store the new temperature to the corresponding items
The problem is then
a) when the “mode-rule” fires the new mode has already been set, so I can’t store the recent target temperature to the correct item in the mode rule. Therefore I need a rule to trigger on changes in target_temperature in order to store it to the correct mode-item.
b) when updating base_temperature and offset I need two seperate sendUpdate/sendCommand pairs, which in turn generate two updates on the target_temperature, which in turn fires that rule twice, messing up my temperature store in turn.
c) There is a race bound to happen, with these seperate entities.
As I want to preserve the ability to locally change the temperature on the device, I can’t deactive that function on the device.
Updating pairs of items via OpenHAB is not possible.
So, I am stuck.
Simplified rules, original rules are generic and use string transformations and pulls from object store to access the corresponding item, depending on the name of the triggering item. I hope,I did not mess things up, when simplifying things:
rule "RTR Target Temperature Change"
when
Item TargetTemperatur changed
then
switch (RoomMode.state) {
case 1: RoomComfortTemperature.sendCommand(newState)
case 2: RoomStandByTemperature.sendCommand(newState)
case 3: RoomNightTemperature.sendCommand(newState)
}
end
var Number auto_temperature = 20
var Number comfort_temperature = 21
var Number standby_temperature = 19
var Number night_temperature = 17
var Number RTRInternalOffset = -2
rule "RTR Mode Change"
when
Item RoomMode changed
then
var Number new_target_temperature
// pull target temperature from item
switch(newState) {
case 0: new_target_temperature=auto_temperature
case 1: new_target_temperature=RoomComfortTemperature.state
case 2: new_target_temperature=RoomStandByTemperature.state - RTRInternalOffset
case 3: new_target_temperature=RoomNightTemperature.state - 2*RTRInternalOffset
}
// transform "target temperature" to base_temperature and offset
var Number current_base = CurrentBaseTemperature.state
var Number new_offset = new_target_temperature - current_base
// map offset back to ]-10 .. 10 [
if ( new_offset >= 10.0 || new_offset <= -10.0) {
var Number new_base_temperature
// must adjust base temperature to achieve target temperature
if (new_offset < - 10.0) { // preserve some room for local adjustment
new_base_temperature = (new_target_temperature + 10.0)
} else if (new_offset > 10.0 ) {
new_base_temperature = (new_target_temperature - 10.0)
}
new_offset = new_target_temperature - new_base_temperature
BaseTemperature.sendCommand(new_base_temperature)
}
BaseTemperatureOffset.sendCommand(new_offset)
end
Since both rules interact with the same items and events can potentially occur concurrently, there is a problem.
Hence, I am stuck with the mechanisms in Rule-DSL with OpenHAB, or at least with my understanding thereof.