[SOLVED] Modbus Dimmer item dividing by 100

I have a NodeMCU running as a dimmer via Modbus with a signed 16 bit address with a range of 0 to 100.

This works fine in paper UI and also works fine in basic UI with a number item pointed at either the number, brightness or dimmer of the channel (the last suffix of the channel doesn’t appear to change anything) but when i change the item type in the .items file only to dimmer (required for Google home tagging) the item doesn’t respond correctly.

If I command the item to 0 it turns the light off. If I command the item to a number less than 100% the light flashes to the requested brightness then turns off. If I command the item to 100% it flashes to full bring brightness then goes to 1% and stays at 1%.

It’s like something is doing a divide by 100 somewhere but only for a dimmer item.

There’s no related errors in the log and I have the dummy transformation (multiply by 1 to get percent) in place (although I haven’t enabled verbose logging).

I suspect i somehow have the items reading percent and writing decimal or vice versa but i don’t know how this can happen.

Dummy transormation thread


Dimmer Lounge_Spots "Lounge Spots" ["Lighting"] { channel="modbus:data:02aa6391:dimmer" }
Number Dining "Dining" ["Lighting"] { channel="modbus:data:Dining:dimmer" }
Number Kitchen_Bench "Kitchen bench" ["Lighting"] { channel="modbus:data:Kitchen-Bench:dimmer" }

Site Map

			    Slider item=Lounge_Spots label="Lounge Spots"
			    Switch item=Lounge_Spots label="Lounge Spots"  mappings=[0="Off", 1="1", 10="10", 100="Full"]


// 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 MULTIPLY_BY = 1;
    return Math.round(parseFloat(inputData, 10) * MULTIPLY_BY);

The Dining and Kitchen_Bench items work as Numbers but the Lounge_Spots appear to divide by 100. if i change Dining or Kitchen_Bench to Dimmer items I get the same divide by 100 behavior.
I can change the range of the dimmer in the NodeMCU if required. The PWM output has a range of 0-1024 which i currently get by multiplying the Modbus value by 10.

I should also note that I get similar behavior with no transformation.
Also, the dimmer item appears to read and update correctly. The problem happens when I command the dimmer item.

Please see the docs on dimmer items for inspiration for the transformations https://www.openhab.org/addons/bindings/modbus/#dimmer-example

You probably want to consider disabling autoupdate, further discussion here https://www.openhab.org/addons/bindings/modbus/#autoupdate-parameter-with-items

Also, it’s unclear whether you use transformation with read, write or both. Please share all things configuration.

Edit: when you said “Modbus with a signed 16 bit address with a range of 0 to 100.” do you mean that you would like to scale full range of 16 bit register to 0…100%? Or no scaling at all, using a fraction of the 16 bit range?

Thanks Ssalonen

I have updated the transformations to those detailed in the Modbus dimmer example. I have changed the range of the registers in the NodeMCU from 0-100 to 0-255. I am using a fraction of the 16 bit range.
The Modbus bit of the configuration appears to work correctly. When I change the value as dimmer in Paper UI, the lights respond correctly. It’s only once I build a dimmer item against the dimmer channel that the flashing happens. The item responds correctly when the light level is changed in the NodeMCU but not when the item is commanded.
It is more noticeable with the added resolution that the value appears to be divided by 100 at lower values now.

I have disabled autoupdate on the items but this does not appear to make any difference.


Dimmer Lounge_Spots "Lounge Spots" ["Lighting"] { channel="modbus:data:02aa6391:dimmer", autoupdate="false" }
Dimmer Dining "Dining" ["Lighting"] { channel="modbus:data:Dining:dimmer", autoupdate="false" }
Dimmer Kitchen_Bench "Kitchen bench" ["Lighting"] { channel="modbus:data:Kitchen-Bench:dimmer", autoupdate="false" }



Thank you. Could you please repeat the exercise with verbose logging enabled? Consult docs for further information how to set this up.

I am interested reading what the logs say when this flashing happens.

Thanks Ssalonen

I stopped OpenHAB as a service then started it interactively to get to the console. I then executed the following:

log:set DEBUG org.openhab.bindings.modbus

I am still not seeing any log entries when I command the lights but the flashing problem appears to be resolved.
I suspect that org.openhab.bindings.modbus is the V1.X Modbus binding not the new V2.X that I’m using. For future reference, could you tell me what the new binding is called. I can’t seem to find it listed anywhere.

I’m not sure what fixed it but restarting OpenHAB appears to have done the trick. Sorry I didn’t think to ‘turn it off and turn it back on again’ before posting but I’m pretty sure I have had this issue since before the last PC reboot.

Thanks again for your help.

I’ve never quite pinned it down, but as you imagine there are various places in openHAB that keep copies or cache of setup info. Editing existing details particularly can miss updating all those. If in doubt, … :wink:

Glad you got it sorted!

For posterity, the logging setup is a bit different, see https://www.openhab.org/addons/bindings/modbus/#enable-verbose-logging. Note that it is not bindings, it’s binding.

You can check which version is active by listing the bundles :

bundle:list -s | grep modbus