After Playing around a bit and changing values from percentage to 0-255 range as this is what is required by esphome.
rule "Get LED State"
when
Item Ledstate changed
then
val json = transform("JSONPATH", "$.", Ledstate.state.toString)
val number1 = transform("JSONPATH", "$.color.r", json)
val number2 = transform("JSONPATH", "$.color.g", json)
val number3 = transform("JSONPATH", "$.color.b", json)
val int red1 = Integer.parseInt(number1)
val int green1 = Integer.parseInt(number2)
val int blue1 = Integer.parseInt(number3)
logInfo("rule1", "state msg coming back r=" + red1+ " g=" +green1+ " b=" +blue1)
var HSBType hsb = HSBType::fromRGB(red1, green1, blue1)
sendCommand(fastled_ws2811_light, hsb)
logInfo("rule1", "corresponding hsb value " + hsb)
end
rule "Publish changes to the Color for LEDs"
when
Member of LEDs changed
then
val topic = "ledstrip/light/"+triggeringItem.name+"/command"
val HSBType newState = triggeringItem.state
val st = triggeringItem.getStateAs(OnOffType).toString // get the on off state
val brightnessint = ((triggeringItem.getStateAs(PercentType) * 215) /100) + 40 // change max value 100 to 255
val brightness = brightnessint.toString
val redint = (newState.getRed * 255) /100
val red = redint.toString
val greenint = (newState.getGreen * 255) /100
val green = greenint.toString
val blueint = (newState.getBlue * 255) /100
val blue = blueint.toString
val message = "{\"state\":"+st+",\"brightness\":"+brightness+",\"color\":{\"r\":"+red+",\"g\":"+green+",\"b\":"+blue+"}}"
logInfo("rule2", "Command sent r=" + red+ " g=" +green+ " b=" +blue)
val mqttActions = getActions("mqtt","mqtt:broker:btid")// user the Thing ID for your configured Broker
mqttActions.publishMQTT(topic,message)
logInfo("rule2", "Full Command in json " + message)
end
Log
2019-07-05 17:37:03.016 [INFO ] [eclipse.smarthome.model.script.rule2] - Command sent r=7.89140000 g=28.05000000 b=3.36600000
2019-07-05 17:37:03.043 [INFO ] [eclipse.smarthome.model.script.rule2] - Full Command in json {"state":ON,"brightness":63.65000000,"color":{"r":7.89140000,"g":28.05000000,"b":3.36600000}}
2019-07-05 17:37:03.129 [INFO ] [eclipse.smarthome.model.script.rule1] - state msg coming back r=71 g=255 b=30
2019-07-05 17:37:03.136 [INFO ] [eclipse.smarthome.model.script.rule1] - corresponding hsb value 109,88,100
2019-07-05 17:37:03.175 [INFO ] [eclipse.smarthome.model.script.rule2] - Command sent r=71.73999999 g=255.00000000 b=30.60000000
2019-07-05 17:37:03.367 [INFO ] [eclipse.smarthome.model.script.rule2] - Full Command in json {"state":ON,"brightness":255.00000000,"color"":{"r":71.73999999,"g":255.00000000,"b":30.60000000}}
2019-07-05 17:37:03.465 [INFO ] [eclipse.smarthome.model.script.rule1] - state msg coming back r=71 g=255 b=30
2019-07-05 17:37:03.474 [INFO ] [eclipse.smarthome.model.script.rule1] - corresponding hsb value 109,88,100
So, as can be seen, as I change the color in UI, first rule 2 gets values, after converting a bit to 0-255 range, sends command to esphome… then esphome sends state mqtt msg back, rule 1 immediately gets the values from that msg and unfortunately, the values are changed drastically by the esphome because of them being rgb type and these values change the color picker brightness to maximum i.e. 100%. Because the values are changed so rule 2 again kicks into play sending another command with brightness value 255 this time and thus also changes actual brightness of LED to max.
I think I should leave the state mqtt msg for someone smarter, I’ll have to live without that for now.