Increase/decrease brightness on HSBType LED

hi
I´ve flashed a MagicHome LED Controller with Tasmota. now I can use it´s IR remote control to trigger various actions like change color of LEDs, open the garage or switch on the outside lights… so far so good…
my problem is that I do not get the increase and decrease buttons to work. I need a rule to read the current HSB Color status and change the brightness.
this is what I tried so far:

Color LED_Office_Color_tasmota   "LED Licht"                    {mqtt=">[broker:cmnd/LED_Office/HSBColor:state:*:default]"}
String LED_Office_IR "Infrarot Empfaenger" {mqtt="<[broker:tele/LED_Office/RESULT:state:JSONPATH($.IrReceived.Data)]"}
when 

    Item LED_Office_IR received update

    then
        switch LED_Office_IR.state {
    case "FF906F": {
        logInfo( "HSBtype", LED_Office_Color_tasmota.state.toString)
		        var HSBType currentState
                currentState = LED_Office_Color_tasmota.state as HSBType
                var DecimalType new_H = currentState.hue
                var PercentType new_S = currentState.saturation
                var PercentType new_B = currentState.brightness 
		
		logInfo( "hueValue" , new_H.toString)
		logInfo( "saturationValue" , new_S.toString)
		logInfo( "brightnessValue" , new_B.toString)
            }   
        }
        end

this rule works fine. now I want to change the brightness by changing this line to:

val PercentType new_B = currentState.brightness - 5

but VSC says “Type mismatch: cannot convert from BigDecimal to PercentType”
what is the correct syntax to decrease the light by 5%?

When you do Math, you end up with a BigDecimal. It doesn’t matter what you start with or what you try to assign it to. If you want to subtract 5 from a PercentType and keep it as a PercentType, you need to create a new PercentType with the result of the calculation.

val PercentType new_B = new PercentType(currentState.brightness - 5)

thanks Rich, that works.
now I can update the item with the new value:

var HSBType newState = new HSBType(new_H,new_S,new_B)
        sendCommand(LED_Office_Color_tasmota,newState.toString)

I´m wondering if there is a simpler way to decrease the brightness, something like:

sendCommand(LED_Office_Color_tasmota,new PercentType(currentState.brightness - 5))

any idea?

First of all, you should use the method, not the Action.

If you do that you can probably send the BigDecimal that is the result of the calculation without creating a PercentType at all.

thanks for pointing me to the right direction.
there is indeed a INCREASE/DECREASE Command for HSBType Color items, however, it does not work:

LED_Office_Color_tasmota.sendCommand(DECREASE)
logInfo( "HSBtype", LED_Office_Color_tasmota.state.toString)
2018-07-19 08:56:38.789 [ome.event.ItemCommandEvent] - Item 'LED_Office_Color_tasmota' received command DECREASE

==> /var/log/openhab2/openhab.log <==

2018-07-19 08:56:38.791 [INFO ] [lipse.smarthome.model.script.HSBtype] - 0,100,100

==> /var/log/openhab2/events.log <==

2018-07-19 08:56:40.666 [ome.event.ItemCommandEvent] - Item 'LED_Office_Color_tasmota' received command DECREASE

==> /var/log/openhab2/openhab.log <==

2018-07-19 08:56:40.666 [INFO ] [lipse.smarthome.model.script.HSBtype] - 0,100,100

to make sure Decrease is valid for HSBType I ruled

logInfo( "HSBtype", LED_Office_Color_tasmota.getAcceptedCommandTypes.toString)

and got:

2018-07-19 08:53:42.341 [INFO ] [lipse.smarthome.model.script.HSBtype] - [class org.eclipse.smarthome.core.library.types.HSBType, class org.eclipse.smarthome.core.library.types.PercentType, class org.eclipse.smarthome.core.library.types.OnOffType, class org.eclipse.smarthome.core.library.types.IncreaseDecreaseType, class org.eclipse.smarthome.core.types.RefreshType]

any idea why that doesn´t rule? thanks

found a workaround via a Dimmer item

Dimmer LED_Office_Dimmer "Dimmer Office [%.0f %%]" {mqtt=">[broker:cmnd/LED_Office/DIMMER:command:*:default], <[broker:stat/LED_Office/RESULT:state:JSONPATH($.Dimmer)"}
switch LED_Office_IR.state {
            case "FF906F":  {  //heller
                val Number newDim = (LED_Office_Dimmer.state as DecimalType) + 10
                LED_Office_Dimmer.sendCommand(newDim)
            }

however, it would be interesting why it doesn´t work via HSBType INCREASE…

Color is supposed to accept INCREASE/DECREASE and it seemed to accept the command but not act upon it. This is a bug and an issue should be filed. I’m going to guess the problem is with the Color Item itself, in which case the issue should be filed here:

Issue #5938 opened…

No, sorry, this is no bug. Items accept commands and forward them to the binding for processing. Items do NOT process commands.
It might be confusing that you nonetheless see item state updates after sending commands even if no binding is involved. This is done by the “autoupdate” feature, which sends a state update for any command, which itself can also be interpreted as a state. These are ON/OFF, HSB, etc. but NOT INCREASE/DECREASE, therefore, no state updates are seen unless a binding (or rule) processes those.

That’s unfortunate. Whenever there is this sort of inconsistency it causes problems for new and sometimes even experienced users.

So it is safe to say that INCREASE/DECREASE, UP/DOWN, and STOP/MOVE are essentially no-ops unless you have written a Rule to do something with those commands or the Item is linked to a Channel or a Binding that does something with it?

In OP’s case he’s using the MQTT binding which will do no processing to implement these commands.

Got stuck in the same problem: :sweat:

I found the INCREASE command working.

HueWiGaSpot_Color.sendCommand(INCREASE)

But it sends the brightness immediately to 100%

So my best try:
(comments are welcome!)

rule "HueWigaLighten"
 when
	Item Command_LigthsBrighter received command ON
 then
   	LogAction.logInfo("Hue", "Lighten wintergarden Hue lamps")
	
	var HSBType currentState = HueWiGaSpot_Color.state

	LogAction.logInfo("Hue", "Lighten wintergarden Hue lamps currentState: {}", currentState.toString)

	var DecimalType hue = currentState.hue
	var DecimalType sat = currentState.saturation
	var PercentType bright

	if( currentState.brightness.intValue < 90 ) {
		bright = new PercentType(currentState.brightness + 10)		
	} else {
		bright = new PercentType(100)
	}

	HueWiGaSpot_Color.sendCommand(new HSBType(hue, sat, bright) as Number)

end 
2 Likes