[SOLVED] Convert number-value of a slider item to PercentType

Hello everybody,
I just want to change the brightness of an tradfri-bulb. But there ist no available channel, so I want to use a item-value of a slider to adjust the brightness.
My problem is, that I dont know how to convert this number-value to a PercentType that can be used for the HSBType.

Number Tradfri_Leuchte_Dimmen (RRD4J_TEMP) //(Dummy-Item für einen Slider in der sitemap)
Color Tradfri_Leuchte_Farbe { channel=“tradfri:0210:gwa0c9a0d7b653:Tradfri_Flur_Alarm:color” } //Tradfri-Binding

rule (–> error-line ERROR!! Works if its comment out. Brightness is set to 100 - corresponding to the declaration ):

rule "Helligkeit steuern" 
Item Tradfri_Leuchte_Dimmen received update 
         logInfo("Leuchte", " Helligkeit wird berechnet.")
        //Variablen anlegen
        var DecimalType hue = new DecimalType(240) // 0-360; 
        var PercentType sat = new PercentType(100) // 0-100
        var PercentType bright = new PercentType(100) // 0-100

	hue=(Tradfri_Leuchte_Farbe.state as HSBType).hue
	sat=(Tradfri_Leuchte_Farbe.state as HSBType).saturation
-->	bright = (Tradfri_Leuchte_Dimmen.state as Number) //ERROR!! Works if its comment out. Brightness is set to 100 - corresponding to the declaration 

Tradfri_Leuchte_Farbe.sendCommand(new HSBType(hue, sat, bright)) 

Thanks a lot for your help!

There is no channel because there is no need for a Channel. You can just send a PercentType value to a Color Item and it will adjust the brightness. Similarly, you can turn on/off the light by sending ON/OFF commands to it as if it were a Switch Item.

So put the ColorItem on the sitemap using a slider and it should just work, no Rules required. Just make sure to configure the slider to only go from 0-100. I think that’s the default but just in case doulbe check in the docs.

1 Like

:sweat_smile: It can be so easy! I just didn’t knew.

Thanks a lot!:+1:

Please tick the solution, thanks