MQTT Config for Shelly Duo Light Bulb

https://shopusa.shelly.cloud/shelly-duo-wifi-smart-home-automation-1#326

Here is my MQTT Light config for a Shelly Duo bulb - couldn’t find any templates for this one, scraped this together from various other posts. On/off, brightness, color temp and state all working. This is using the native MQTT service on the bulb, with the Shelly cloud function disabled.

light:
  - platform: mqtt
    schema: template
    name: Shelly Duo
    max_mireds: 370
    min_mireds: 154
    state_topic: "shellies/[friendly name]t/light/0/status"
    state_template: "{% if value_json.ison %}on{% else %}off{% endif %}"
    brightness_template: "{{ value_json.brightness | float | multiply(2.55) | round(0) }}"
    color_temp_template: "{{ 1000000 | multiply(1/(value_json.temp | float)) | round(0) }}"
    command_topic: "shellies/[friendly name]/light/0/set"
    command_on_template: >-
      {
      "turn":"on"
      {% if brightness is defined %}
        "brightness":{{brightness | float | multiply(0.3922) | round(0)}}
      {% endif %}
      {% if color_temp is defined %}
        "temp":{{ (1/(color_temp | float)) | multiply(1000000) | round(0) }}
      {% endif %}
      }
    command_off_template: '{"turn":"off"}'
6 Likes

Hi srnoth!
Thanks for that!
This is exactly what I was looking for my Shellies DUO GU10!
Work as a charm !

Excellent!! thanks

Thank you!

Hi there,

great to see complete mqtt solution.

I use my Shelly Duo GU10 in various automations, sometimes bulb is dimmed, sometimes set to 100% brightness (through JSON payloads). I use mqtt.publish (action):

topic: shellies/ShellyBulbDuo-<deviceid>/light/0/set
payload: '{ "brightness": value (0-100), "white": value (0-100), "temp": value (2600-6500), "turn": "on" }'

It works well as long as bulb is online.

What I wanted to automate is whenever bulb is turned on physically (via switch) it should start with brightness set to 100%, and with middle range of temp. It should start this way regardless to the last state before the switch was turned off (bulb offline). Further action is switching the brightness to 50% following set delay (ie. 00:00:30), and finally, after another delay (let say another 20 sec), complete turn off.

A user activate the light again with switch (turning it off - bulb goes offline, and on - bulb again online). Automation start over again.

I was not successful, since it seems bulb switches on (online) with last state, and despite the automation payload does not lead to expected result. Do I mess something with retain/qos flags?

Can your mqtt template be used with above mentioned automation? How to set the trigger (mqtt?) and action (mqtt) properly to get the bulb always 100% bright and set to desired temp? Can you advise? Could you test this with your enviroment?

When you physically turn bulb off (bulb is offline), what entity state you can see. If retain is used, then last state is on in my case, which makes difficult to use that state as trigger for the action.

Hi, thank you for your work.
I have a problem, the brightness works good but the on and off don’t work.

I see that under the mqtt topic the json ison value in my duo light can be true or false but also with this change the light don’t power on and off. This is my example:

  - platform: mqtt
    schema: template
    name: luce_tavolo_pranzo_1
    max_mireds: 370
    min_mireds: 154
    state_topic: "shellies/ShellyBulbDuo-663FC0/light/0/status"
    state_template: "{% if value_json.ison %}on{% else %}off{% endif %}"
    brightness_template: "{{ value_json.brightness | float | multiply(2.55) | round(0) }}"
    color_temp_template: "{{ 1000000 | multiply(1/(value_json.temp | float)) | round(0) }}"
    command_topic: "shellies/ShellyBulbDuo-663FC0/light/0/set"
    command_on_template: >-
      {
      "turn":"on"
      {% if brightness is defined %}
        "brightness":{{brightness | float | multiply(0.3922) | round(0)}}
      {% endif %}
      {% if color_temp is defined %}
        "temp":{{ (1/(color_temp | float)) | multiply(1000000) | round(0) }}
      {% endif %}
      }
    command_off_template: '{"turn":"off"}'

Please can you help me to understand what is the problem

thank you for you help
regards

@TomAutoHome @japh51

Sorry guys I don’t have any of my Shelly bulbs still on the stock firmware.

We now have a working OTA method to upgrade from the stock firmware to Tasmota, which offers you a whole lot more customization options.

I’ve upgraded 4 Shelly Duos with no issues.

1 Like

Thank you for the information
Regards

Very nice. Does anyone know if esphome works on the duo as well?

This works…

esphome:
  name: MYDEVICE_NAME
  platform: ESP8266
  board: esp01_1m
#  arduino_version: recommended
  arduino_version: latest
#  arduino_version: dev
  board_flash_mode: dout
  on_boot:
    priority: 100 # Highest priority, ensures light turns on without delay.
    then:
      - light.turn_on: shelly_duo

#Wifi connection
wifi:
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_pw

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: MY_AP
    password: !secret AP_password
#    ap_timeout: 1min

captive_portal:

debug:

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API - Do not use when MQTT enabled
#api:
#  password: !secret api_password

ota:
  password: !secret ota_password

# Enable mqtt
mqtt:
  broker: MY_MQTT_BROKER
  username: MQTT_USERNAME
  password: MQTT_PW
  client_id: "MYDEVICE_NAME"
  keepalive: 60s

web_server:
  port: 80
  auth:
    username: admin
    password: !secret web_password

output:
  - platform: esp8266_pwm
    id: output_warm_white
    pin: GPIO4
  - platform: esp8266_pwm
    id: output_daylight
    pin: GPIO5

light:
  - platform: cwww
    name: "Shelly Duo"
    id: shelly_duo
    cold_white: output_daylight
    warm_white: output_warm_white
    cold_white_color_temperature: 6500 K
    warm_white_color_temperature: 2700 K
    # Ensure the light turns on by default if the physical switch is actuated.
    restore_mode: ALWAYS_ON

2 Likes

My mqtt configuration for shelly duo RGBW

light:
- platform: mqtt
  schema: template
  name: Shelly_Duo_Room
  unique_id: "shelly_RGBW_BULB_X"
  state_topic: "shellies/shellycolorbulb-XXXXXXXXXXXX/color/0/status"
  command_topic: "shellies/shellycolorbulb-XXXXXXXXXXXX/color/0/set"
  command_on_template: >-
    {
      "turn": "on",
      
      {%- if red is defined and green is defined and blue is defined -%}
        "mode": "color",
        "red": {{ red }},
        "green": {{ green }},
        "blue": {{ blue }},
      {%- endif -%}
      
      {%- if brightness is defined -%}
        "gain": {{brightness | float | multiply(0.3922) | round(0)}},
        "brightness": {{brightness | float | multiply(0.3922) | round(0)}},
      {%- 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 -%}

      {% if color_temp is defined %}
        "mode": "white",
        "temp":{{ (1/(color_temp | float)) | multiply(1000000) | round(0) }},
      {% endif %}
    }
  effect_list:
    - "Off"
    - Meteor Shower
    - Gradual Change
    - Breath
    - Flash
    - On/Off Gradual
    - Red/Green Change
  command_off_template: '{"effect": 0,"turn":"off"}'
  state_template: "{% if value_json.ison %}on{% else %}off{% endif %}"
  brightness_template: "{{ value_json.brightness | float | multiply(2.55) | round(0) }}"
  color_temp_template: "{{ 1000000 | multiply(1/(value_json.temp | float)) | round(0) }}"
  red_template: "{{ value_json.red }}"
  green_template: "{{ value_json.green }}"
  blue_template: "{{ value_json.blue }}"
  effect_template: "{{ value_json.effect }}"
  qos: 2
  retain: true
  max_mireds: 333
  min_mireds: 154
1 Like

Hello guys, I have Shelly Duo Bulb and i want to be able to control RGB, on/off, etc. from HA. How to make the setup, should I use MQTT and how? Where to put these configurations which you have posted?