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"
when
Item Ikea_dimmer_hellig_Wohnz changed
then
bright= Ikea_dimmer_hellig_Wohnz.state as Number // value between 0..255
bright=bright/256
sendCommand(Wohnz_Lampen_Dimmer, bright) // value between 0..100 needed
end
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"
when
Item Ikea_dimmer_hellig_Wohnz changed
then
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
end
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 .
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.
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.
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.
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.