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)
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]
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:
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.