Issue with modifying one value in a string (from State)

The following will dim a z-wave light bulb by 5% (note: Study_Light.state returns a string from “0” to “100”). Nice an easy as there is one value to change for dimming on this bulb.

Study_Light.sendCommand((Study_Light.state as Number) -5 )

I’m struggling however to do the same with a Lifx Light bulb as Test_Light_Colour.state returns a string from “0.0,0,0” to "0.0,0,100) where it is just the 3rd variable I need to change (also, note the first variable has a decimal place). I’ve been faffing around for a couple of hours and just can’t nail the syntax. The following is the best I’ve got so far…any suggestions would be great!

var HSB = Test_Light_Colour.state.toString.split(",")
Test_Light_Colour.sendCommand(HSB.get(0),HSB.get(1),((HSB.get(2) as Number) -5 )) 


You know that’s a string, you made it into one.
There is more to converting from string to number than “as”, you need to parse e.g. use a function like parseInt()

Can’t help feeling string manipulation is the wrong approach here


    val hue = Test_Light_Colour.getStateAs(HSBType).hue
    val saturation = Test_Light_Colour.getStateAs(HSBType).saturation
    var brightness = Test_Light_Colour.getStateAs(HSBType).brightness 
    logWarn("Rules", "hue: {}, saturation: {}, brightness: {}", hue, saturation, brightness)
    brightness = if (brightness.intValue - 5 > 0) new PercentType(brightness.intValue - 5) else new PercentType(0)
    logWarn("Rules", "HSBType: {}", new HSBType(hue, saturation, brightness))

    Test_Light_Colour.sendCommand(new HSBType(hue, saturation, brightness))

It’s a bit more straightforward using Jython…

hue = items["Test_Light_Colour"].hue
saturation = items["Test_Light_Colour"].saturation
brightness = items["Test_Light_Colour"].brightness 
LOG.warn("hue: {}, saturation: {}, brightness: {}".format(hue, saturation, brightness))

brightness = PercentType(brightness.intValue() - 5) if brightness.intValue() - 5 > 0 else PercentType(0)
LOG.warn("HSBType: {}".format(HSBType(hue, saturation, brightness)))

Test_Light_Colour.send(HSBType(hue, saturation, brightness))

I never said I knew what I was doing! :slight_smile: Any suggestions on how to manipulate it would be most welcome.

@5iver Thanks Scott, The logic works. :slight_smile: Just polishing an example to post on using a fibaro button to control various lights like the hardwired fibaro dimmer (eg Press for On/Off, Long Hold Dim, etc). Good Man!
Thanks again,

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.