I’m having troubles adding variables to item states with units.
I would like to add 1 km/h to an item to compare it to another item:
if ( localForecastMax24hWindSpeed.state >= (localCurrentWindSpeed.state + 1|"km/h") )
both items are in units “km/h”, according to the openhab.log:
[INFO ] [smarthome.model.script.weather.rules] - localForecastMax24hWindSpeed is: 6.2 km/h
[INFO ] [smarthome.model.script.weather.rules] - localCurrentWindSpeed is: 5.5 km/h
yet, the above command results in an error:
2021-01-23 17:55:06.928 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'visibility localForecastMax24hWindSpeed': Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null
so, it seems I cannot add 1|“km/h” to the item state.
If I forcefully strip all units, I can add 1 to the items value by doing
if ( (localForecastMax24hWindSpeed.state as Number).floatValue >= (localCurrentWindSpeed.state as Number).floatValue + 1 )
I tried many different things but only stripping the unit works for me.
What am I doing wrong, why is it so hard to add a numerical value to an item with a unit?