I am on OH 3.4.2 final build (please forgive but I had no time yet to migrate to OH4) and I have added a sensor for reading my power meter data and I receive the data via MQTT.
Everything works but I like to transform the data from Watts to KiloWatts by dividing the incoming value by 1000. I found the following way as the shortest and smartest but it does not work. I also found several other ways in similar topics in the community and I tried them all without success.
Donât bother. Make the Item a Number:Power, set the âUnit of Measurementâ property (near the bottom after clicking âShow Advancedâ) to W. Then on your Item set the State Description Pattern to %.0f kW. OH will convert between them automatically for you. Thereâs no need for a transformation to convert between units.
In OH 4 use the unit metadata.
The transform will not apply until the next update.
If youâve not set the âUnit of Measurementâ property on the Channel, then input doesnât have units and therefore is not a Quantity. I think itâs possible to create a Quantity without units but I think it will still add something. This might be a problem.
Transformations go in the transformations folder, not the scripts folder.
div us already a number. Trying to parse it is likely to fail.
Always look at the logs for errors. Most of the above should have generated error messages in the log telling you something of what is going wrong.
If you donât want to use UoM, a JS transform solution would be
You cannot be successful in using openHAB without access to the logs somehow. If you canât access the logs now, you need to drop everything and figure that out first.
In docker the logs are located in the userdata/logs folder where userdata is the volume you mount to /openhab/userdata in the container.
You can run Frontail in a docker container and point it at that file.
I have access to the logs folder and I know how to check but I am not using Frontail ⊠I run while testing such things the karaf console with log:DISPLAY in parallel but it shows no errors.
Let me first copy my javascript to the transform folder and see what this does âŠ
⊠and I will also test to use the units (I have removed it as I thought it only works with plain numbers) âŠ
Well, you didnât do what I described above. Of course it doesnât work.
Item type needs to be Number:Power (so far so good)
There should be no transformation at all, particularly not a transformation profile. But even so, this particular transform is absolutely not going to work in OH 3.4, Quantity only exists in the newer JS Scripting add-on and 3.4 uses the older Nashorn JS for transformations
Youâve still not shown the Thing configuration, you must set the âUnit of Measurementâ property to W.
You need to set the State Description pattern Item metadata, to kW.
There are only these entries but I am not sure if they correlate exactly with my testing:
18:39:06.636 [WARN ] [core.io.rest.auth.internal.AuthFilter] - Unauthorized API request from 172.17.0.1: Error while processing JWT token
18:39:14.643 [WARN ] [core.io.rest.auth.internal.AuthFilter] - Unauthorized API request from 172.17.0.1: Error while processing JWT token
Ok, will do. May you kindly tell me where to put the line that you have provided in my thing channel definition as I have already a transformation pattern to extract the value from JSON array?
Type number : power_feed "Stromzaehler Power provided" [ stateTopic="stromzaehler/tele/tasmota_15C3BD/SENSOR", transformationPattern="JSONPATH:$.SM.2_8_0" ]
I fear that I cannot make two transformations in the thing channel and as I primarily need the JSONPATH transformation to gather the data from a JSON array I guess that I cannot apply the javascript transformation to convert the value as well.
I donât do .things files. I find far more time is wasted fighting syntax errors than any benefit, real or perceived, that comes from using .things files. Iâd guess youâd want to chain the JS transform to the JSONPATH transform.
I will take your advise and remove all manual definition and create the mqtt channel via the UI to if I can get it run when I completely switch from file based definition to the UI based definition (even though I would expect that it shoudl behave the same )
And for sure a message has been published after the change? There was also a bug in the file loader in OH 3.4 IIRC where it doesnât always pick up changes to .things files You might need to reload the MQTT bundle from the karaf console (or restart OH) to ensure the changes got picked up.