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 changed the mqtt channel but behavior did not change and I still get the Watt value
Type number : power_feed "Stromzaehler Power provided" [ stateTopic="stromzaehler/tele/tasmota_15C3BD/SENSOR", transformationPattern="JSONPATH:$.SM.2_8_0"∩JS:| parseFloat(input)/1000 ]
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.
I keep my file based mqtt thing and channel definition but at the item level I can add my w2kw.js and it then converts the data …
But this means that something does not work when defining the item transformation on file level …
I know that file based configuration is old-fashioned but I can see in human readable format what it does
UID: mqtt:topic:mosquitto:cerberos_sensor_reporter
label: cerberos sensor_reporter
thingTypeUID: mqtt:topic
configuration:
payloadNotAvailable: OFFLINE
availabilityTopic: sensor_reporter/cerberos/status
payloadAvailable: ONLINE
bridgeUID: mqtt:broker:broker
location: Garage
channels:
- id: garagedoor1
channelTypeUID: mqtt:contact
label: Large garage door
description: Large garage door open status
configuration:
stateTopic: sensor_reporter/cerberos/garagedoor1/state
off: CLOSED
on: OPEN
- id: garagedoor2
channelTypeUID: mqtt:contact
label: Small garage door
description: Small garage door open status
configuration:
stateTopic: sensor_reporter/cerberos/garagedoor2/state
off: CLOSED
on: OPEN
- id: garagedoor1_opener
channelTypeUID: mqtt:switch
label: Large garage door opener
description: ""
configuration:
commandTopic: sensor_reporter/cerberos/garagedoor1/cmd
off: OFF
on: ON
- id: garagedoor2_opener
channelTypeUID: mqtt:switch
label: Small garage door opener
description: Small garage door opener controller
configuration:
commandTopic: sensor_reporter/cerberos/garagedoor2/cmd
off: OFF
on: ON
- id: online
channelTypeUID: mqtt:switch
label: Online status
description: Indicates online status of this sensor_reporter
configuration:
stateTopic: sensor_reporter/cerberos/status
off: OFFLINE
on: ONLINE
Yes, I saw that … Maybe I think about switching now … up to now it worked as expected. The transformation seems not be working correctly … maybe a hint to move forward