I’m having a frustrating time with a simple problem.
There is a Zigbee smart plug reporting multiple values. It must be reporting electric current in “mA”
I’m trying to adjust current value dividing by a thousand. This is typically done by applying a gain factor of “0.001 A”, however I get UNDEF result instead
WARN org.openhab.binding.modbus.internal.profiles.ModbusGainOffsetProfile Profile can only process plain numbers from handler. Got unit A. Returning UNDEF
I don’t know where else to look at on dealing this issue. I tried to mix and match multiple combinations of gain factor, measurement units, etc., but nothing seemed to help.
Point configuration:
label: Current
type: Number:ElectricCurrent
category: Energy
groupNames:
- Zigbee_Smart_Plug_1
tags:
- Point
If the unit reported by the binding is incorrect, then ultimately this is a bug in the add-on and you should file an issue to have it fixed.
My understanding of the Gain/Offset profile is it expects the value from the Channel to not have a unit already. Modbus doesn’t supply one and the profile is a part of the modbus add-on.
So you’ll have to use a script transformation. Luckily this would be just a one liner. For JS it would be something like the following for the Thing to Item transform:
JS: | Quantity(Quantity(input).float/1000, "mA")
That parses and pulls the unit off of the value from the Channel, divides by 1000, then rebuilds the Quantity with the correct units.
Same place where you set the Gain/Offset profile, select ECMAScript instead. You’ll have three fields, one to translate the value from the thing to the Item, one to translate commands from the item to the thing and another to transform states from the item to the thing.
You just put the one-liner in the field for the thing to item field.
I must be doing something wrong with syntax.
Tried to copy-paste:
ERROR org.openhab.core.automation.module.script.profile.ScriptProfile Failed to process script 'JS: | Quantity(Quantity(input).float/1000, "mA")': Could not get script for UID 'JS: | Quantity(Quantity(input).float/1000, "mA")'.
Tried couple of other options quickly reviewing other sources.
ERROR org.openhab.core.automation.module.script.profile.ScriptProfile Failed to process script 'Quantity(Quantity(input).float/1000, "mA")': Could not get script for UID 'Quantity(Quantity(input).float/1000, "mA")'.
ERROR org.openhab.core.automation.module.script.profile.ScriptProfile Failed to process script 'JS(|Quantity(Quantity(input).float/1000, "mA"))': Could not get script for UID 'JS(|Quantity(Quantity(input).float/1000, "mA"))'.
Trying this | Quantity(Quantity(input).float/1000, "mA") gave me new error and a hope moving somewhere
ERROR org.openhab.core.automation.module.script.profile.ScriptProfile Failed to process script '| Quantity(Quantity(input).float/1000, "mA")': org.graalvm.polyglot.PolyglotException: TypeError: Argument of wrong type provided, required Item, string or Quantity.
I then tried concatenate as if parameters were strings | Quantity(Quantity(input).float/1000 + "mA")
but that gave me no errors, no warnings at all, as if there were no issue.
As the item seemed to work ok with “A” dimension from my previous tries I jumped back on other similar topic (Modbus binding: gain-offset correction doesn't work - #10 by FranzS) for some ideas.
I gave a try for this adjusted script | input.replace("A", "mA") and got this item finally working as intended.
Is there a way for a noob like me to see a raw data that is going straight to the item? Not sure whether it would have helped me, but still.