bieniu / ha-shellies-discovery

Script that adds MQTT discovery support for Shellies devices
Apache License 2.0
295 stars 90 forks source link

Add support for Shelly Duo RGBW light bulbs #585

Closed Xinayder closed 50 minutes ago

Xinayder commented 3 months ago

This PR adds support for Shelly Duo RGBW light bulbs. Currently only tested with a GU10.

KEY_EFFECT_TEMPLATE was added for Lovelace to properly display what effect is currently selected. I used the Shelly RGBW2 as a base, but had to change KEY_BRIGHTNESS_VALUE_TEMPLATE to KEY_BRIGHTNESS_TEMPLATE for the same reason previously described. The light bulb only supports 4 effects, including "Off" (no effect).

To turn on the light bulb, the effect field must be present on the MQTT payload, thus if you only want to turn on the light and not use any effects, just set the field to 0.

Thanks to @tc-maxx for providing a MQTT discovery payload for this light bulb (#424)

This is the YAML generated by the Python script:

schema: template
qos: 0
red_template: '{%if value_json.mode == "color"%}{{value_json.red}}{%else%}{{ none }}{%endif%}'
green_template: >-
  {%if value_json.mode == "color"%}{{value_json.green}}{%else%}{{ none
  }}{%endif%}
blue_template: >-
  {%if value_json.mode == "color"%}{{value_json.blue}}{%else%}{{ none
  }}{%endif%}
state_topic: shellies/shellycolorbulb-485519DA73A9/color/0/status
brightness_state_topic: shellies/shellycolorbulb-485519DA73A9/color/0/status
origin:
  name: Shellies Discovery
  sw_version: 5.1.0
  support_url: https://github.com/bieniu/ha-shellies-discovery
effect_command_template: >-
  { {%if value=="Off"%}"effect":0{%elif value=="Meteor Shower"%}"effect":1{%elif
  value=="Gradual Change"%}"effect":2{%elif value=="Flash"%}"effect":3{%endif%}
  }
state_template: '{%if value_json.ison%}on{%else%}off{%endif%}'
unique_id: shellycolorbulb-485519da73a9-light-0
effect_state_topic: shellies/shellycolorbulb-485519DA73A9/color/0/status
availability:
  - payload_not_available: 'false'
    topic: shellies/shellycolorbulb-485519DA73A9/online
    payload_available: 'true'
  - value_template: '{%if value_json.mqtt.connected%}online{%else%}offline{%endif%}'
    topic: shellies/shellycolorbulb-485519DA73A9/info
max_mireds: 333
min_mireds: 154
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%},"brightness":{{brightness|float|multiply(0.3922)|round}},"gain":{{brightness|float|multiply(0.3922)|round}}{%endif%}{%if
  color_temp is
  defined%},"mode":"white","temp":{{(1000000/(color_temp|int))|round(0,"floor")}}{%endif%}{%if
  transition is defined%},"transition":{{min(transition|multiply(1000),
  5000)}}{%endif%}{%if effect is defined%},"effect": {%- if effect == "Meteor
  Shower" -%}1{%- elif effect == "Gradual Change" -%}2{%- elif effect == "Flash"
  -%}3{%- else -%}0{%- endif -%}{%- else -%},"effect": 0{%endif%} }
brightness_command_topic: shellies/shellycolorbulb-485519DA73A9/color/0/set
effect_list:
  - 'Off'
  - Meteor Shower
  - Gradual Change
  - Flash
brightness_template: '{{value_json.brightness|float|multiply(2.55)|round(0)}}'
effect_command_topic: shellies/shellycolorbulb-485519DA73A9/color/0/set
brightness_command_template: >-
  {"gain":{{value|float|multiply(0.3922)|round(0)}},
  "brightness":{{value|float|multiply(0.3922)|round(0)}}}
device:
  name: Shelly Duo RGBW 485519DA73A9
  connections:
    - - mac
      - 48:55:19:da:73:a9
  hw_version: gen1 (SHCB-1)
  sw_version: 20231107-162425/v1.14.1-rc1-g0617c15
  model: Shelly Duo RGBW
  configuration_url: http://192.168.1.138/
  manufacturer: Allterco Robotics
command_off_template: >-
  {"turn":"off","effect":0{%if transition is
  defined%},"transition":{{min(transition|multiply(1000),5000)}}{%endif%}}
effect_template: >-
  {%if value_json.effect==1%}Meteor Shower{%elif value_json.effect==2%}Gradual
  Change{%elif value_json.effect==3%}Flash{%else%}Off{%endif%}
name: Light 0
command_topic: shellies/shellycolorbulb-485519DA73A9/color/0/set
color_temp_template: '{{((1000000/(value_json.temp|int,2700)|max)|round(0,"floor"))}}'
platform: mqtt

image image

Closes https://github.com/bieniu/ha-shellies-discovery/issues/588

github-actions[bot] commented 1 month ago

Stale pull request message

tcsmaxx commented 1 month ago

Hi @Xinayder, it looks like there are still some requested changes for this PR. Would you be able to take a look and help implement the necessary adjustments? Let me know if there's anything I can assist with to move this forward. Thanks for your work on this!

Xinayder commented 44 minutes ago

My notifications were off for some reason, I am terribly sorry for forgetting about this PR. I'm happy that it was merged!

bieniu commented 42 minutes ago

Thanks for your contribution 👍