Sonoff B1 RGBCW WiFi Bulb w/ Sonoff-Tasmota

Hey @Carywin,

you can simplify a good part of your first rule with this line:

var HSBType hsb = HSBType.fromRGB(red, green, blue)

Best!

Oh nice, thanks! I’ll work this into it

Moved to Light Color RGB/RGBW/RGBCW to and from HSB+Dimmer Conversion

Hello!

Have you made any progress with B1? I’ve been unable to make it enter firmware flashing mode too, and I’m out of ideas what to try. I’ve already tried switching TX and RX, connecting GPIO0 and GND for a second, 2 seconds, holding it connected all the time, used ESPTool, Arduino IDE, PlatformIO, but it just doesn’t connect. I’ve read that some people had partial success (flashed 2 out of 4 devices), but they don’t know how to reproduce it. And they suspect it’s some kind of timing issue (I’m really not sure what they’ve meant with that). If you’ve managed to flash it, I would really appreciate an info on a ways to do it.

Best regards,
Davor

Yes I have many B1s flashed and working around my home now. When flashing them I connect GPIO0 to GND and it seems to work fine. After the initial flash you can use OTA to keep them updated.

1 Like

Moved to Light Color RGB/RGBW/RGBCW to and from HSB+Dimmer Conversion

I’m getting exceptions when using your rule:

Rule 'Arilux HSB -> RGB': Could not cast NULL to org.eclipse.smarthome.core.library.types.HSBType; line 14, column 15, length 27

It seems like my lamp is null. The item is defined like this:

Color TischColor "Tisch" <light> (LR,gLight) [ "Lighting" ]

and I modified the rule like this:

rule "Arilux HSB -> RGB"
when
    Item TischColor received command
then
    var r = ((TischColor.state as HSBType).getRed * 255 / 100).intValue
    var g = ((TischColor.state as HSBType).getGreen * 255 / 100).intValue
    var b = ((TischColor.state as HSBType).getBlue * 255 / 100).intValue
    var rgb = String.format("%02x%02x%02x", r, g, b)

    TischColorString.sendCommand(rgb)
end

What am I doing wrong?

Hey @DerEnderKeks, nothing wrong with the rule. The error claims that your item is not initialized (NULL). Did you confirm that this is NOT the case? Check your log to see the state of the Item. It might be a good idea to catch this case at the beginning of the rule:

if (TischColor.state == NULL) {
    logInfo("tisch.rules", "Item is null, cancelling...")
    return;
}

This is more of a general best practice thing and I’d recommend to always consider such a case.

Always think about which states an Item can have and how you want to react to those. Do you maybe need to initialize an Item during startup or do you want to persist its state to be restored on Startup? Almost all rule files of mine have such a rule for Items that are not automatically initialized through a Binding:

rule "Init: Kodi"
when
    System started
then
    createTimer(now.plusSeconds(120)) [ |
        if (Kodi_Summary.state == NULL) Kodi_Summary.postUpdate("(unknown) ⁉")
        if (Some_Counter.state == NULL) Some_Counter.postUpdate(0)
        // and so on
    ]
end

The timer ensures that restoreOnStartup or Binding-wise initialization have time to initialize the Item for you

Why exactly is the state of the item null? Shouldn’t it be set as soon as it receives an command event? (I’m new to OH rules :smiley: … )

The answer to that is simple, check out the log and see which event triggered the execution of the rule. Received command does not necessarily mean that the Item is now initialized! Just imagine me executing: TischColor.sendCommand(NULL)

Do you know how to access the log? It’s one of if not The most important tool during rule development.

If you are not sure about the meaning of the log lines you are seeing post them here and we can discuss them.

It receives a command from the basic UI, where I select a color.

Item 'TischColor' received command 279,54,100

So doesn’t this mean it should have a state with that color?

Hmm yes… where is this exactly?

The first line where the rule accesses the state.

The way you’ve presented the error doesn’t make sense to me.
Please add a logging line to the beginning of the rule:

logInfo("tisch.rules", "Item received command:" + receivedCommand)
Item received command:271,33,100

Everything looks correct. There’s probably a stupid little mistake in your setup. Please add some more logging lines.

Restarting openHAB somehow fixed it. (While restarting it also uninstalled the rule engine for some reason…)

Thanks for your help! :smiley:

Hi @ThomDietrich, I had @Carywin version working until I upgraded the firmware on the B1s. I’m trying to adapt your version, but I’m struggling to make it work. Could you please post your complete rules and items files?
Thanks.

@Carywin I ended up typing down my own article. So I decided to post a more generic Tutorial:

1 Like

Were you able to fix this based on @ThomDietrich comment?