How to initialize 'derived' items once real values become known?

Hi,

I have some items that are not bound directly to a device/channel but that are used by one of my rules to drive multiple devices. For example one item would be ‘Switch BedroomRadiators’. When that is changed all bedroom radiators are either set to 7 (off) or 20 (on) degrees.
This works fine, except when I restart openhab. At that point these unbound items are not initialized with the actual current values of my radiator thermostats - which arrive asynchronously. So even though the radiators might actually be set to 20C, the ‘BedroomRadiators’ item could still have its bootup value of ‘OFF’.

How can I improve my setup so that on restart from openhab these derived items are properly initialized based on actual device values as they come in?

Thanks!

David

Commonly referred to around here as Proxy Items.

Two things:

  1. Set up persistence and restoreOnStartup for the proxy items. When OH restarts the Item will be initialized to whatever it happened to be when OH went down. This isn’t full proof of course because the state of the devices could have changed while OH was down but it will cover 90-95% of the cases.

  2. Create a rule that triggers when the radiators report their state and recalculate the value of your proxy Item.

Without seeing your actual Items I can’t say for sure, but you might be able to use a Group instead of a proxy Item in this case. Assuming your radiator Items are Numbers your Group would look something like:

Group:Number:MAX BedroomRadiators

Assign all the applicable bedroom radiators to this Group and the state of the Group itself will be the maximum of all its members. Any command that gets sent to the Group will be forwarded to all its members.

MIN might also make sense in this case as well. But again, without seeing the actual Items or getting more info about what you want to happen when for whatever reason all of the radiators are not set to the same state.

Hi Rich,

Many thanks for the response!

One further question.

How would I create such a rule? I mean how does the rule know that the current setpoint value is being reported by the item?

Thanks!

David

When the binding receives a message from your device it changes the state of the device through an update. You can write a rule that triggers when the Item receives this update.

rule "Device updated"
when
    Item Device1 received update or
    Item Device2 received update
then
    if(Device1.state.toString == "20" || Device2.state.toString == "20") {
        ProxyItem.postUpdate(ON)
    }
    else {
        ProxyItem.postUpdate(OFF)
    }
end

Note the difference between postUpdate and sendCommand. When you postUpdate it only changes the state of an Item internally. When you sendCommand the change gets sent on the binding and on down to the device itself.