Help Needed: Shelly.Cloud Bulb (RGBW) via MQTT

Hi All

I tried to make my Shelly.Cloud Bulb work, but i seem to be missing something.

According to https://shelly-api-docs.shelly.cloud/?shell#bulb-mqtt
I should send on and off commands to the /color/0/command topic, but the rest of the commands should go to the /color/0/set topic. Then status is always provided back in /color/0/status

I have tried various different configurations, but i always end up something missing or working completely. EG: I can switch on the light, change colors (rgb), but not switch off. Or i can switch on and off, but not change color (rgb), etc etc

Here i have posted my two most recent configs.

In the “LED Huiskamer 1-a” config i need the brightness_command_template, so it doesn’t just send the brightness as an INT to the /color/0/set topic, but a nicely formatted json. Alas, the brightness_command_template is not allowed in the config. :frowning:

In the “LED Huiskamer 1-b” i can not switch off the device. Because off commands always go to the command_topic. But on/off and color/brightness have different topics in this bulb. (see the url mentioned above)

To remove confusion. I didn’t use these two configs at the same time. It’s just posted here as one.

How to properly setup this Shelly.Cloud bulb in HA ?

Kind regards in advance :slight_smile:


light:
  - platform:                     mqtt
    name:                         "LED Huiskamer 1-a"
    state_topic:                  "shellies/shellybulb-420FB6/color/0"
    command_topic:                "shellies/shellybulb-420FB6/color/0/command"
    rgb_state_topic:              "shellies/shellybulb-420FB6/color/0/status"
    brightness_state_topic:       "shellies/shellybulb-420FB6/color/0/status"
    rgb_command_topic:            "shellies/shellybulb-420FB6/color/0/set"
    brightness_command_topic:     "shellies/shellybulb-420FB6/color/0/set"
    payload_on:                   "on"
    payload_off:                  "off"
    rgb_command_template:         '{ "mode":"color", "red":{{red}}, "green":{{green}}, "blue":{{blue}} }'
    rgb_value_template:           "{{value_json.red}},{{value_json.green}},{{value_json.blue}}"
    brightness_scale:             100
    brightness_value_template:    "{{ value_json.gain  }}"
    #brightness_command_template: '{ "mode":"color", "gain":{{ brightness }} }'
    retain:                       false
    qos:                          1
    optimistic:                   false

  - platform: mqtt
    name: "LED Huiskamer 1-b"
    schema: template
    state_topic:                  "shellies/shellybulb-420FB6/color/0/status"
    command_topic:                "shellies/shellybulb-420FB6/color/0/set"
    command_on_template: >         
      { "mode":"color" 
      {%- if red is defined and green is defined and blue is defined -%} ,"red":{{ red }},"green":{{ green }},"blue":{{ blue }}  {%- endif -%}    
      {%- if brightness is defined -%},"gain":{{ (brightness|float / 2.55)|round(0) }}{%- else -%},"gain":10{%- endif -%} 
      }
    command_off_template:         '{ "mode":"white","brightness":0 }'
    state_template:               '{% if value_json is defined and value_json.ison is defined and value_json.ison==1 %}on{% else %}off{% endif %}'
    brightness_template:          '{{ (value_json.gain|float * 2.55)|round(0) }}'
    red_template:                 '{{value_json.red}}'
    green_template:               '{{value_json.green}}'
    blue_template:                '{{value_json.blue}}'
    retain:                       false
    qos:                          2
    optimistic:                   false

Hi, I have the same problem but I am no very experienced and still trying to find a way to turn it on and off. If you found something can you keep this discussion updated ?

Solved this yet? Any working setup for the Bulb?

I have adapted this to be able to manipulate the color, but can not get it to turn on and off… If you look at the RGBW2…the difference seems to be the ison vs turn and “on” and “off” having quotations… If you can figure that out I would be happy to know…

Asked on the Shelly Facebook group. This two bulb solution is c/o Shay Levy. I owe him.

Just in case anybody is looking for this as it somewhere burried in facebook

light:
  - platform: mqtt
    name: "Shelly Bulb Color Mode"
    schema: template
    effect_list:
      - "Off"
      - Meteor Shower
      - Gradual Change
      - Breath
      - Flash
      - On/Off Gradual
      - Red/Green Change
    state_topic: "shellies/shellybulb-123456/color/0/status"
    command_topic: "shellies/shellybulb-123456/color/0/set"
    command_on_template: >
      {
        "turn": "on",
        "mode": "color",
        {%- if red is defined and green is defined and blue is defined -%}
          "red": {{ red }},
          "green": {{ green }},
          "blue": {{ blue }},
        {%- endif -%}
        {%- if white_value is defined -%}
          "white": {{ white_value }},
        {%- endif -%}
        {%- if brightness is defined -%}
          "gain": {{ (brightness/255*100)|int }},
        {%- endif -%}
        {%- if effect is defined -%}
          {%- if effect == 'Meteor Shower' -%}
            "effect": 1
          {%- elif effect == 'Gradual Change' -%}
            "effect": 2
          {%- elif effect == 'Breath' -%}
            "effect": 3
          {%- elif effect == 'Flash' -%}
            "effect": 4
          {%- elif effect == 'On/Off Gradual' -%}
            "effect": 5
          {%- elif effect == 'Red/Green Change' -%}
            "effect": 6
          {%- else -%}
            "effect": 0
          {%- endif -%}
        {%- else -%}
          "effect": 0
        {%- endif -%}
      }
    command_off_template: >
      {
        "turn": "off",
        "mode": "color",
        "effect": 0
      }
    qos: 1
    state_template: '{% if value_json.ison == true and value_json.mode == "color" %}on{% else %}off{% endif %}'
    brightness_template: '{{ (value_json.gain/100*255)|int }}'
    red_template: '{{ value_json.red }}'
    green_template: '{{ value_json.green }}'
    blue_template: '{{ value_json.blue }}'
    white_value_template: '{{ value_json.white }}'    
    effect_template: >
      {%- if value_json.effect == 1 -%}
        Meteor Shower
      {%- elif value_json.effect == 2 -%}
        Gradual Change
      {%- elif value_json.effect == 3 -%}
        Breath
      {%- elif value_json.effect == 4 -%}
        Flash
      {%- elif value_json.effect == 5 -%}
        On/Off Gradual
      {%- elif value_json.effect == 6 -%}
        Red/Green Change
      {%- else -%}
        Off
      {%- endif -%}
    retain: false

  - platform: mqtt
    name: "Shelly Bulb White Mode"
    schema: template
    state_topic: "shellies/shellybulb-123456/color/0/status"
    command_topic: "shellies/shellybulb-123456/color/0/set"
    command_on_template: >
      {
        "turn": "on",
        "mode": "white",
        {%- if color_temp is defined -%}
          "temp": {{ (1000000/(((float(color_temp)-153)/354*180)+153)-35) | int }},
        {%- endif -%}
        {%- if brightness is defined -%}
          "brightness": {{ (brightness/255*100) | int }},
        {%- endif -%}
        "effect": 0
      }
    command_off_template: >
      {
        "turn": "off",
        "mode": "white",
        "effect": 0
      }
    qos: 1
    state_template: '{% if value_json.ison == true and value_json.mode == "white" %}on{% else %}off{% endif %}'
    brightness_template: '{{ (value_json.brightness/100*255) | int }}'
    color_temp_template: "{{ (1000000/(((float(value_json.temp)-3000)/3500*4500)+2000)) | int }}"
    retain: false

8 Likes

Just want to let you know I used your template and it works great. Thank you for posting this.

Thank you, had to come back and find this…and it the facebook link was struggling…

The template works great but it adds 2 entities for the same device in home assistant. Is it possible to make it only one entity with all the features?

Great thank you

if using qos on script, dont forget to set it in the Network Settings of Device :Max QoS

Another nice approach is keep using shellyforhas and use a button only to change the mode, the current mode will be nicelly handled by the shellyforhas.

light:
  - platform: mqtt
    name: "Shelly Bulb Switch mode"
    schema: template
    state_topic: "shellies/shellycolorbulb-xxxxxxxxxxxx/color/0/status"
    command_topic: "shellies/shellycolorbulb-xxxxxxxxxxxx/color/0/set"
    command_on_template: >
      {
        "turn": "on",
        "mode": "white",
        "effect": 0
      }
    command_off_template: >
      {
        "turn": "on",
        "mode": "color",
        "effect": 0
      }
    qos: 1
    state_template: '{% if value_json.mode == "white" %}on{% else %}off{% endif %}'
    retain: false