In Openhab 4, I have the following item configuration:
Number Windgeschwindigkeit "Windgeschwindigkeit [%1.f km/h]" { channel="knx:device:bridge:sensors:Windgeschwindigkeit"[profile="transform:JS", toItemScript="ms_to_kmhval.js", toHandlerScript="kmh_to_msval.js"] }
The intent is to use the script ms_to_kmhval.js to convert the meter/second value that comes from the KNX bus to km/h.
The respective transform script is this:
(function(i) {
return i*3.6;
})(input)
The problem is now that if I configure things that way then the wind speed no longer updated, updates from the bus do not reach the item. If I remove the scripts, instead using the following, then updates work as expected (after a restart of OH):
Number Windgeschwindigkeit "Windgeschwindigkeit [%1.f m/s]" { channel="knx:device:bridge:sensors:Windgeschwindigkeit" }
knx Binding is unit aware since OH4.0 (maybe since OH3.4), so it’s way easier to do it the UoM way.
Type number : windspeed "Windgeschwindigkeit" [ ga="9.005:1/2/3" ] // which DPT is used?
Type number : windspeed "Windgeschwindigkeit" [ ga="14.065:1/2/3" ] // which DPT is used?
I’m not sure if that answers his question about why toItemScript doesn’t seem to work.
Setting aside for the moment whether to use units vs transforms. I have a regular Number type (no units) from a binding holding a temperature value that I want to convert from C to F.
Number OutTempX “Temperature [%.1f °F]” { channel=“fineoffsetweatherstation:gateway:4368657686:temperature-outdoor” [profile=“transform:JS”, toItemScript=“C2F.js”]}
Where C2F.js is
(function(x) {
return 5;
})(input)
So I’de expect the Item to be “5”, but it just ignores the transformation.
If instead I do something like
Number OutTempX “Temperature [JS(C2F.js):%.1f]” { channel=“fineoffsetweatherstation:gateway:4368657686:temperature-outdoor” }
Then the item displays correctly, so I know the script works.
The forum likes to make our posts “pretty” and it replaces normal double quotes with these fancy reversy quotes.
Because @billfor is using quotes instead of code fences, the original characters are not preserved and the quotes are being replaced. Always use normal double quotes in your configs and pay close attention to the difference between block quotes:
This is a block quote.
A block quote looks like this
If not setting the double quotes, you can’t set the child parameters (at least this was true for OH3.x) via text file. And of course you can see it in the metadata listing (here: Not Set)
Well, at least for now you have to set the empty string when configuring the stateDescription pattern (openHAB states an error when not using the quotes).
Number:Temperature OutTempX "Temperature" { channel="...", unit="°C", stateDescription=[pattern="%.1f °C"] }
// openHAB will mark that as an configuration error here ^^
Number:Temperature OutTempX "Temperature" { channel="...", unit="°C", stateDescription=""[pattern="%.1f °C"] }
// openHAB will use this configuration without complaining
It’s really weird. I also tried setting this through the UI, creating a new Item of type Number:Speed, but as soon as I connect it with the proper channel, the value changes to UNDEF, no matter whether a state description is even present. Maybe something is wrong with my particular Version of OH. I am using version 4.0.1.