Calculation of item value


i would like to do some calculation before a value from a thing-channel gets written to the item state - is that somehow possible in OH3?

At OH2.5 i used a second item and a rule but i would like to “simplify” this:

rule "Umrechnung Ventilstellung HM_WZ_Heizkoerper_K_Level"
    Item HM_WZ_Heizkoerper_K_Level changed
    var valvelevel_wz_k = triggeringItem.state as Number
    HM_WZ_Heizkoerper_K_Valve.postUpdate(valvelevel_wz_k * 100)

At OH3 i also get an error with this rule - i think i would have to add an if condition for the case the value is 0?

18:47:51.558 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'heizung_calc_valvelevel-4' failed: cannot invoke method public abstract org.openhab.core.types.State org.openhab.core.items.Item.getState() on null in heizung_calc_valvelevel

What is your Thing and Thing Channel? Some Bindings allow for transformations to occur at the Channel level.

Its a Homematic IP HMIP-eTRV on a CCU3 in this case. I already had a look at the channel config, but there seems to be no relevant option:

My rules are looking similar and I’m getting the same error message. But instead of an Homematic IP actor, I’m using MAX Thermostats with Homegear.

My problem could be solved here:

Thanks for the link to your thread. That was very helpful. Even though you did not post you solution to you problem with your Rule 1, I did some further research and found this Pull Request:

This led me to the OpenHAB documentation chapter “Implicit Variables inside the Execution Block”.

So now I simply use newState instead of triggeringItem.state. In your case, this should also work, if you convert it to a number.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.