I assume you saw this:
Things that I see that are errors or don’t make sense:
-
why postUpdate the new value to the same Item? That will trigger the rule again and never update the proxy Item
-
you do not return anything from the lambda. The result of the last line of the lambda is what gets returned. Since postUpdate returns void, the line
val Pressure2_mm = convertsAtm.apply(Pressure_OWM)
doesn’t make sense. -
not an error, but it is better to use MyItem.postUpdate than the postUpdate Actions
-
you need to get the value of an Item by calling item.state (e.g. pressuredata.state)
The following makes more sense. However, for one liners like this you really are not saving anything and adding a lot of complexity by using a lambda. (NOTE: I’m using a slightly different syntax here, one that will eliminate warnings in ESH Designer). I also change things up a bit to avoid needing to case things inline which makes the code clearer.
import org.eclipse.xtext.xbase.lib.Functions
val Functions$Function1<Number, Integer> convertAtm = [ pressureData |
(pressuredata / 1.3332239 + 0.5).intValue
]
rule "PressureProxy2"
when
Item Pressure_OWM changed
then
PressureProxy2.postUpdate(convertAtm.apply(Pressure_OWM.state as Number))
end
Personally, I’d just write (assuming two Pressure Items):
rule "PressureProxy"
when
Item Pressure_OWM changed or
Item Pressure_Other changed
then
PressureProxy1.postUpdate((Pressure_Other.state as DecimalType) / 1.3332239 + 0.5).intValue)
PressureProxy2.postUpdate((Pressure_OWM.state as DecimalType) / 1.3332239 + 0.5).intValue)
end
The above code does more in far fewer lines of code and is much easier to understand and maintain.