Dimmer item and parsing of its value

I have a dimmer item:
Dimmer Dimmer_MasterBedRoom “Dimmer [%d %%]”

In my sitemap:
Slider item=Dimmer_MasterBedRoom label=“Dimmer” icon=“slider”

Is a dimmer item a float between 0 and 1.0 or an integer or this strange DecimalType??

I am trying to dim my bedroom lights because they are to bright:)

In my rule:

 var int redValue
 var int greenValue
 var int blueValue
 var String RGBvalues

rule "Change dimming in Master BedRoom"
when
	Item Dimmer_MasterBedRoom changed
then

	
	dimmer_MasterBedRoom_Value = Dimmer_LivingRoom.state as DecimalType
	logInfo("Debug","Dimmer state: " + dimmer_MasterBedRoom_Value )
    
    // do something to get rule below to execute.. is there a better way to execute another rule??
    Color_MasterBedRoom.sendCommand(hsbValueMasterBedRoom.toString())
end

My second rule:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// Change color freely ////////////////7////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
rule "Set RGB value MasterBedRoom"
    when
            Item Color_MasterBedRoom changed
    then
    
    hsbValueMasterBedRoom = Color_MasterBedRoom.state as HSBType
    
    redValue = (redColor*dimmer_MasterBedRoom_Value/100).intValue
	greenValue = (greenColor**dimmer_MasterBedRoom_Value/100).intValue
	blueValue= (blueColor**dimmer_MasterBedRoom_Value/100).intValue
	
    hsbValueMasterBedRoom   = HSBType::fromRGB(redValue, greenValue,blueValue)
	logInfo("Info", "Set RGB value Master BedRoom to : " +redValue.toString+ ":"  +greenValue.toString+ ":"  +blueValue.toString)
   
	Group_DMX_MasterBedRoom.members.filter[l|
			l.state.toString != hsbOff.toString
		].forEach[l| l.sendCommand(hsbValueMasterBedRoom.toString()) ]
end

A dimmer is percentage type , so 0 to 100 will fit for OFF to maximum brightness. As far as I know, RGB would be 0 to 255 each, an HSBType would be 0 to 360 for hue (or color) and 0 to 100 for saturation and brightness. See https://github.com/openhab/openhab1-addons/wiki/Hue-Binding#rules

DecimalType is the class for number states in openHAB, see http://www.eclipse.org/smarthome/documentation/javadoc/org/eclipse/smarthome/core/library/types/DecimalType.html

In addition to Udo’s answer you may take a look at:

OK, I am still not able to get it to work somehow…

So below is a screendump of my sitemap:

So my idea was when i select scene,
it sets the hsbvalue of the color item : Color_MasterBedRoom to my preset values
sets the dimmer value

So for night mode i would like the dimmer to 60%, reading 100%, on 80%

Question is should I do this in my scene change rule

  1. set global variables redColor,greenColor,bluecolor
  2. set dimmer value,
  3. turn off all lights that are not member of scene group, set all members of scene group to redColor,greenColor,blueColor
  4. call the “Set RGB value MasterBedRoom”

(Slightly more efficient if I set color and dimming level at the same time as I switches lights on, and use postupdate to dimmerItem and colorItem instead of setting color then diming level and the sendCommand())

But I can not get number 2 and 4 to work.

So for 2 how do I set the dimmer level for the night scene?
Dimmer_MasterBedRoom.state = "60"

so for 4 how can I use the dimmer?
redValue = (redColor*(Dimmer_MasterBedRoom.state).intValue /100).intValue

there might be better solutions that the one i have chosen, but the idea is:
that if i select a different scene the correct lights get turned on, the dimmer value and the color changes to the preset value, If I am not happy with that color, I can use the color wheel to change it, or if i need more lights i can simply click on the dimmer. (Both these two events trigger my second rule : Item Color_MasterBedRoom changed or Item Dimmer_MasterBedRoom changed)

I do have manually switch on the wall, when it triggers it checks if the scene is larger than 1( on, night,reading) then it switches off,(scene = 1) otherwise it checks if night mode is enabled then it set scene to 3(night), otherwise 2(ON). The reading mode can only be set by my android phone or alexa, I might add a switch later to switch on reading light, however i am pretty happy with my alexa!

2: Dimmer_MasterBedRoom.sendCommand(60) should set the dimmlevel to 60%

4: You have to construct a HSBType and sendCommand this HSBType:

Maybe take a look at this Convert RGB String to Color Item posting

2: Dimmer_MasterBedRoom.sendCommand(60) should set the dimmlevel to 60%, Works now… I will look into 4 after a good night sleep:)

I just cant figure out how to handle the state object of the dimmer:

rule "Change dimming in Master BedRoom"
when
	Item Dimmer_MasterBedRoom changed
then

	
	//dimmer_MasterBedRoom_Value = Dimmer_LivingRoom.state //as DecimalType
	logInfo("Debug","Dimmer state: " + Dimmer_MasterBedRoom.state )
	//Dimmer_Value = (Dimmer_MasterBedRoom.state)
	//Dimmer_Value = (Dimmer_MasterBedRoom.state).toInteger
	//Dimmer_Value = Dimmer_MasterBedRoom.state//receivedCommand.toInteger
    //Color_MasterBedRoom.sendCommand(hsbValueMasterBedRoom.toString())
    
    logInfo("Debug","Dimmer state2: " + (255/Dimmer_MasterBedRoom.state).toInteger )
    //logInfo("Debug","Dimmer state2: " + (255/Dimmer_MasterBedRoom.state) as IntegerType )
end

My log output is like this:

00:27:08.148 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Dimmer_MasterBedRoom' received command 27
00:27:08.161 [INFO ] [marthome.event.ItemStateChangedEvent] - Dimmer_MasterBedRoom changed from 78 to 27
00:27:08.341 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Dimmer_MasterBedRoom' received command 27
00:27:13.349 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber 'org.eclipse.smarthome.model.rule.runtime.internal.engine.RuleEngineImpl@1e78f33' takes more than 5000ms.
00:27:18.000 [INFO ] [eclipse.smarthome.model.script.Debug] - Dimmer state: 27
00:27:18.013 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Change dimming in Master BedRoom': An error occured during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.IntegerExtensions.operator_divide(int,byte) on instance: null

So how can I do the division?

I’m pretty sure, what you really want to do is something like

255/100 * Dimmer.state. :slight_smile: Try

logInfo("Debug","Dimmer state2: {}",  255 / 100 * (Dimmer_MasterBedRoom.state as DecimalType) )

This way openHAB will do the type conversion from float to string for you.

After some read up that the coloritem inheritate methods from the dimmer class this works smoothly

/***********************************************************************************************************
 * ************************************** MASTER BEDROOM ***************************************************
 * *********************************************************************************************************
 */

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// Change color freely ////////////////7//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
rule "Set RGB value MasterBedRoom"
    when
            Item Color_MasterBedRoom changed
    then
    
    hsbValueMasterBedRoom = Color_MasterBedRoom.state as HSBType
    
	Group_DMX_MasterBedRoom.members.filter[l|
			l.state.toString != hsbOff.toString
		].forEach[l| l.sendCommand(hsbValueMasterBedRoom.toString()) ]
end

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// Dim the lights //// ////////////////7//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Change dimming in Master BedRoom"
when
	Item Dimmer_MasterBedRoom changed
then
	Color_MasterBedRoom.sendCommand(Dimmer_MasterBedRoom.state)
end


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// Change the scene of light, e.g. warm white, white, lounge and night //////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

rule "Change the scene in Master Bedroom"
when
	Item Scene_MasterBedRoom received command
then
	
	//warm white
	switch receivedCommand {
		//OFF
		case 1: {
			hsbValueMasterBedRoom = HSBType::fromRGB(0, 0, 0)
			Group_DMX_MasterBedRoom.members.forEach[l|l.sendCommand(hsbValueMasterBedRoom.toString())]	
			Dimmer_MasterBedRoom.sendCommand(0)
		}
		//ON
		case 2:{
			hsbValueMasterBedRoom = HSBType::fromRGB(255, 255, 255)
		    rgbLights.apply(Group_DMX_MasterBedRoom,Group_DMX_MasterBedRoom,hsbValueMasterBedRoom)
		    Dimmer_MasterBedRoom.sendCommand(80)
		}
		//NIGHT
		case 3:{
			hsbValueMasterBedRoom = HSBType::fromRGB(50, 10, 10)
		    rgbLights.apply(Group_DMX_MasterBedRoom,Group_DMX_MasterBedRoom,hsbValueMasterBedRoom)
		    Dimmer_MasterBedRoom.sendCommand(60)
		}
		//READING
		case 4:{
			hsbValueMasterBedRoom = HSBType::fromRGB(200, 200, 100)
		    rgbLights.apply(Group_DMX_MasterBedRoom,Group_DMX_MasterBedRoom,hsbValueMasterBedRoom)
		    Dimmer_MasterBedRoom.sendCommand(100)
		}
	}		
	
end