Modbus Dimmer Item update

Hello community.
I have a question about Dimmer Item updating. In sitemap file I have slider to control light brightness. When I change brightness level via Openhab UI (sitemap), the level is successfully saved in slave device, but when I change this level from other source, slider in Openhab UI (sitemap) is not updated, but actually level is changed.
Modbus communication works good. I suppose there is an issue in read transform file.

things file data:

Bridge poller Holdings5 [ start=50, length=3, refresh=3000, type=“holding” ] {
Thing data Holding57 [ readStart=“57”, readTransform=“JS(readTr.js)”, readValueType=“int16”, writeStart=“57”, writeValueType=“int16”, writeType=“holding”, writeTransform=“JS(writeTr.js)”, updateUnchangedValuesEveryMillis=50000 ]

   Thing data Holding58 [ readStart="58",  readTransform="JS(readTr.js)", readValueType="int16",  writeStart="58", writeValueType="int16", writeType="holding",  writeTransform="JS(writeTr.js)", updateUnchangedValuesEveryMillis=50000 ]

   Thing data Holding59 [ readStart="59",  readTransform="JS(readTr.js)", readValueType="int16",  writeStart="59", writeValueType="int16", writeType="holding",  writeTransform="JS(writeTr.js)", updateUnchangedValuesEveryMillis=50000 ]

items file data:

Dimmer dali1 “Dali 1 [%d]” { channel=“modbus:data:localhostTCP:Holdings5:Holding57:number”, homekit=“Lighting, Lighting.OnState, Lighting.Brightness”}
Dimmer dali2 “Dali 2 [%d]” { channel=“modbus:data:localhostTCP:Holdings5:Holding58:number”, homekit=“Lighting, Lighting.OnState, Lighting.Brightness”}
Dimmer dali3 “Dali 3 [%d]” { channel=“modbus:data:localhostTCP:Holdings5:Holding59:number”, homekit=“Lighting, Lighting.OnState, Lighting.Brightness”}

read transform function:

(function(inputData) {
var MAX_SCALE = 100;
return Math.round( parseFloat(inputData, 10) * 100 / MAX_SCALE );

write transform function:

(function(inputData) {
var MAX_SCALE = 10000;
var out = 0
if (inputData == ‘ON’) {
} else if (inputData == ‘OFF’) {
out = 0
} else {
out = Math.round( parseFloat(inputData, 10) * MAX_SCALE / 100 )
return out

I have no problems with writing in the slave register. So, I suppose, in write transport function var MAX_SCALE set correctly. But I cannot correctly set that variable in read transform function. Any ideas ? Maybe there are some others mistakes I don’t know ?

Does your events.log show your Item getting updated, other than by a ‘prediction’?

You probably have autoupdate default enabled on your Item, which will make it appear to respond to UI commands, but mask a failure to get real status from the device.
You might want to disable autoupdate to investigate.

I don’t see anything obvious wrong with your transform. It doesn’t seem to do much though, multiply by 1?
You can make another data Thing without transform and link to another test Item to make sure you get the raw data from Modbus that you expect.

I do next steps: In items file I changed type Dimmer with type Number, and I remove read and write transformation from thing file. After this all work good. So, it seems to me, the problem is with transformation.

But I cannot use Number type item because I want to have possibility to control these items (change brightness) from Apple Home app. So, I cannot use Number type item.

I’ve just noticed the mismatch in your original post …

Thank you for your help. Now it works.

1 Like