Number L1_v "L1_V [JS(divide10.js):%.1f] " <energy> { channel="knx:device:bridge:ZennioKes:L1_v" }
but I’m getting the following error from log:
2019-02-09 12:17:27.902 [WARN ] [rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state '2219.52' on item 'L1_v' with pattern 'JS(divide10.js):%.1f': Cannot format state '2219.52' to format '%.1f'
not the best news for me as I’m not very strong on coding.
I’m currently using the following JS transformation to convert some of my modbus values:
// Wrap everything in a function (no global variable pollution)
// variable "input" contains data passed by openhab
(function(inputData) {
// on read: the polled number as string
// on write: openHAB command as string
var DIVIDE_BY = 10;
return parseFloat(inputData) / DIVIDE_BY;
})(input)
(function(inputData) {
// on read: the polled number as string
// on write: openHAB command as string
var DIVIDE_BY = 10;
var result = parseFloat(inputData) / DIVIDE_BY;
return result.toString();
})(input)
Thanks.
I replaced the code, but I’m getting the same error.
2019-02-09 13:12:16.751 [WARN ] [rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state '2219.52' on item 'L1_v' with pattern 'JS(divide10.js):%.s': Cannot format state '2219.52' to format '%.s'
I tried with “:%.s” as well as it is now string but still.
without the part [profile=“transform:JS”, function=“divide10.js”] Item reads its old value.
With it, it doesn’t even show up on the bus (log). No errors either.
Can you be clear about whether you’d like to store the divided-by-10 value in the Item ? (rather than just for display in the UI)
As your other (modbus) items are stored that way, it would make sense if this KNX Item was too.
It’s a shame KNX2 doesn’t support transforms as well, but a profile should do a similar job for reading a sensor.
Number L1_v "L1_V [%s] " <energy> { channel="knx:device:bridge:ZennioKes:L1_v"[profile="transform:JS", function="divide10.js"] }
really should work. Be sure you’ve not got any funny quote marks.
Is the KNX channel a number type?
Yes, I would like to store the divided-by-10 value, not just to use it the UI.
I don’t see any typos nor funny quote marks.
And the new code still didn’t work.
knx.things:
Thing device ZennioKes [
address="1.1.8",
fetch=false,
pingInterval=900,
readInterval=0
] {
Type number : L1_mA "L1_mA" [ ga="3/2/1" ]
Type number : L2_mA "L2_mA" [ ga="3/2/2" ]
Type number : L3_mA "L3_mA" [ ga="3/2/3" ]
Type number : L1_v "L1_V" [ ga="3/1/1" ]
Type number : L2_v "L2_V" [ ga="3/1/2" ]
Type number : L3_v "L3_V" [ ga="3/1/3" ]
Type number : L1_w "L1_W" [ ga="3/3/1" ]
Type number : L2_w "L2_W" [ ga="3/3/2" ]
Type number : L3_w "L3_W" [ ga="3/3/3" ]
Type number : Hz "Hz" [ ga="3/0/1" ]