Hi all, I am trying this configuration on a test environment (RPi3 with OH 2.3) for the Sonoff B1 which has Tasmota version 5.12.0i installed. I used the same configuration as in the first post of this thread.
Switching ON/OFF is working as is the Color picker. But can’t get the Dimmer and Color Temp working.
I also read the Solution from Thom Dietrich: Light Color RGB/RGBW/RGBCW to and from HSB+Dimmer Conversion Here is also mentionned that since Tasmota version 5.12.0.h the conversion HSB ↔ RGB no longer is needed. This make me a bit confused; would that be the reason why my config is not working?
I am not a programmer, so could someone please post me a working configuration for the Sonoff B1?
If needed i can post my items, sitemap and rules files…
EDIT, Decided to post the extra info needed right away. I am looking at the mqtt status using this cmd in a terminal:
mosquitto_sub -v -h 192.168.178.238 -u admin -P ****** -p 1883 -t '+/Sonoff_1B1/#'
And when i use the Sonoff web-if and i set the slides for Cold—Warm and Dark—Bright, i see the results (values 90 and 42.9) both in the terminal and in the OH sitmap.
This is the items file as i use it:
Dimmer dBedroom_Lamp "Bedroom Lamp" <dimmablelight> ["Lighting"]
{mqtt=">[mybroker:cmnd/Sonoff_1B1/DIMMER:command:*:default],
<[mybroker:stat/Sonoff_1B1/RESULT:state:JSONPATH($.Dimmer)]",autoupdate="false"}
Switch sBedroom_Lamp "Bedroom Lamp Switch" <light> (gAllLights)
{mqtt=">[mybroker:cmnd/Sonoff_1B1/POWER:command:*:default],
<[mybroker:stat/Sonoff_1B1/RESULT:state:JSONPATH($.POWER)]",autoupdate="false"}
Color cBedroom_Lamp "Bedroom Lamp Colour" <colorlight>
{autoupdate="false"}
Dimmer ctBedroom_Lamp "Bedroom Lamp Colour Temperature" <light>
{autoupdate="false"}
String mqBR_Lamp_Colour "Bedroom Lamp Colour MQTT Target" <colorlight>
{mqtt=">[mybroker:cmnd/Sonoff_1B1/COLOR:command:*:default],
<[mybroker:stat/Sonoff_1B1/RESULT:state:JSONPATH($.Color)]",autoupdate="false"}
This is the sitemap file which i use for this test:
sitemap sonoff1b1Carywin label="Sonoff_1B1 Carywin test sitemap" {
Frame label="Date" {
Text item=Date
}
Frame label="Test Sonoff_1B1 Carywin"{
//
Switch item=sBedroom_Lamp label="Lamp [%s]"
Slider item=dBedroom_Lamp label="Dimmer [%d]"
Slider item=ctBedroom_Lamp label="Colour Temp [%.1f]"
Colorpicker item=cBedroom_Lamp label="Lamp Colour [%s]"
}
}
And this is the rules file in which i only changed the publish command in the “Bedroom Colour Temperature” rule:
import java.awt.Color
import java.util.List
rule "Bedroom Lamp Colour Return"
when
Item mqBR_Lamp_Colour changed
then
var String RGB = mqBR_Lamp_Colour.state.toString
var String red_s = RGB.charAt(0).toString + RGB.charAt(1).toString
var Number red = Integer::parseInt(red_s, 16)
var String green_s = RGB.charAt(2).toString + RGB.charAt(3).toString
var Number green = Integer::parseInt(green_s, 16)
var String blue_s = RGB.charAt(4).toString + RGB.charAt(5).toString
var Number blue = Integer::parseInt(blue_s, 16)
val List<Float> hsb = Color.RGBtoHSB(red.intValue, green.intValue, blue.intValue, null)
var float hue = hsb.get(0)
hue *= 360
var float sat = hsb.get(1)
sat *= 100
var float bri = hsb.get(2)
bri *= 100
val String hsbString = hue + "," + sat + "," + bri
var HSBType HSB = new HSBType(hsbString)
cBedroom_Lamp.postUpdate(HSB)
var String ww_s = RGB.charAt(8).toString + RGB.charAt(9).toString
var Number ww = Integer::parseInt(ww_s, 16)
var String cc_s = RGB.charAt(6).toString + RGB.charAt(7).toString
var Number cc = Integer::parseInt(cc_s, 16)
var Number ct
if (ww == 0 && cc == 0) {
ct = 50
} else if (ww == 0) {
ct = 0
} else if (cc == 0) {
ct = 100
} else {
ct = ww / (ww + cc) * 100
}
ctBedroom_Lamp.postUpdate(ct)
end
rule "Bedroom Lamp Colour Output"
when
Item cBedroom_Lamp received command
then
if (receivedCommand instanceof HSBType) {
var red_n = receivedCommand.red * 2.55
var green_n = receivedCommand.green * 2.55
var blue_n = receivedCommand.blue * 2.55
var String hex = Integer::toHexString(red_n.intValue)
if (hex.length < 2) hex = "0" + hex
var String output = hex
hex = Integer::toHexString(green_n.intValue)
if (hex.length < 2) hex = "0" + hex
output = output + hex
hex = Integer::toHexString(blue_n.intValue)
if (hex.length < 2) hex = "0" + hex
output = output + hex
var String whites = mqBR_Lamp_Colour.state.toString
var String whitelevels
try {
whitelevels = whites.charAt(6).toString + whites.charAt(7).toString + whites.charAt(8).toString + whites.charAt(9).toString
} catch(Throwable t) {
whitelevels = "0000"
}
logInfo("BRColour","BR Colour: " + output + whitelevels)
mqBR_Lamp_Colour.sendCommand(output + whitelevels)
}
else if (receivedCommand == ON){
sBedroom_Lamp.sendCommand(ON)
}
else if (receivedCommand == OFF){
sBedroom_Lamp.sendCommand(OFF)
}
end
rule "Bedroom Colour Temperature"
when
Item ctBedroom_Lamp received command
then
val Number ctValue = (receivedCommand as Number * 3.47) + 153
publish("mybroker","cmnd/Sonoff_1B1/CT",ctValue.intValue.toString)
end
Hope someone can help me with this…
Kind regards, Bert

