Simple rules for dimmer 255 to percentage

Hello, everybody,

I just need one simple rule, but I don’t know how to implement it. I have a dimmer that outputs a value between 0…255 (Ikea_dimmer_hellig_Wohnz). This dimmer should now dim my Hue lamps (Wohnz_Lampen_Dimmer). Here however only a percentage value between 0…100% is accepted.

I.e. I would have to divide the value input value by 256, round it to an integer and send it to the lamps.

My solution below doesn’t work of course. Therefore I would be very grateful for help.

val Number bright

rule "Test"
		Item Ikea_dimmer_hellig_Wohnz changed 
    		bright= Ikea_dimmer_hellig_Wohnz.state as Number // value between 0..255
    		sendCommand(Wohnz_Lampen_Dimmer, bright) // value between 0..100 needed


If it is > 0, divide by 2.55? (same as divide by 255 & multiply by 100)

I always get the following message:

Command '111' not supported by type 'PercentageValue': Value must be between 0 and 100

So the dividing does not work correctly with my code.

var Number bright

val makes it a constant (see this).

Unless you need to use this variable in other rules it would be better to define it inside your rule.

You may need to round the value as well, so your rule could look like this:

rule "Test"
		Item Ikea_dimmer_hellig_Wohnz changed 
		var Number bright = Ikea_dimmer_hellig_Wohnz.state as Number
		bright = (bright / 255) * 100

    		sendCommand(Wohnz_Lampen_Dimmer, bright.intValue) // value between 0..100 needed

I have updated the rule with the remark from Rich. I have also tested this and it works as intended, so either add logging or check the event.log which state Ikea_dimmer_hellig_Wohnz gets when you control your Ikea dimmer .



thanks for yout help. But it does not work. The error Message still says:

Command '111' not supported by type 'PercentageValue': Value must be between 0 and 100

I think the value i want to send is to large and not between 0…100. But why?

Log the value of bright. The number returned by the binding seems to be larger than 255 if you are getting 111.

You probably don’t need to do the rounding.


Correct, rounding is not necessary when using bright.intValue (I’ll update the rule in the post above).

Have you considered doing this “at source”? Wherever that value comes from, presumably a binding, maybe you could apply a transformation and normalize the 255 range to 100 as it comes into openHAB.

thanks at all! now it works perfect.

I have another question. When I use the dimmer, the lamp on the sitemap is displayed as off even though it is on. I have an item (switch) that theoretically should be switched from off to on or vice versa.

How can I do this?

This is the demo.sitemap that I used during testing. When the slider is moved to 0 then the light icon is “off” (gray), otherwise it is “on” (yellow). The closer to maximum value, the more yellow it gets.

sitemap demo label="Demo"
        Frame {
            Switch item=Ikea_dimmer_hellig_Wohnz icon="light"
            Slider item=Ikea_dimmer_hellig_Wohnz minValue=0 maxValue=255 step=1 icon="light"
            Switch item=Wohnz_Lampen_Dimmer label="Wohnz_Lampen_Dimmer [%s]" icon="light"
            Text item=Wohnz_Lampen_Dimmer label="Wohnz_Lampen_Dimmer [%s]" icon="light"

I have added two switches as well. You’ll notice that when moving the slider (in your case the Ikea dimmer) the switches will automatically move to the “on” position for any value greater than 0 or to the “off” position when the value equals 0.

1 Like