Shelly RGBW2 with 4x white output and multi-press switch config

Hello,

I’m trying to use RGBW2 as a 4xwhite output. I wan’t to expose all 4 lights as a single light in home assistant.

I was thinking I should do 4 PWM outputs, 4 monocromatic light entities and then some sort of switch to turn on all those lights and set brightness. Does anyone has this scenario working?

I would also like to have a few different multi-press switch configs:

  • single press: turn on/off
  • press-and-hold: dimming
  • double press: max power
  • triple press: 50% brightness

Anyone has anything like this working?

What is the motivation behind this approach?
Shelly RGBW2 allows to set required values anytime (even when light is turned off). Then you can turn it on when needed. Saying that, additional switch on the output is not needed. The only “problem” is, that HA doesn’t support this feature. You have to set RGBW2 using mqtt or http API. Then on/off via HA light entity.

multi-press, if using native firmware of RGBW2 is kind of limited. It can max out on double-press for RGB mode. But not sure about 4ch mode.
One of your options is to set input as detached, then intercept input presses by some automation.
Don’t know what can Tasmota do.

What I want to have is a single light entity in Home Assistant controlling 2 or 4 light strips from the same RGBW2 conroller. I have multiple light strips in my room and they act as a single light, but I can’t drive all of them via a single output on RGBW2 as they are too powerful.

I could mix something up with MQTT and templated switches I guess in HA, but if there is a support for that in ESPHome, I would go that way.

Multi-press is something I really want to have and I don’t want to detach the switch as I want to have my buttons operational even when HA is down.

I guess my solution would be something in the line of:

binary_sensor:
  - platform: gpio
    # ...
    on_press:
      then:
        - light.toggle: light1
        - light.toggle: light2
        - light.toggle: light3

But thinking about that, this will create a button entity in HA, but not a light entity, so I can’t configure brightness of a light.

you can also make 4 entities representing each channel, then group them into single light using light group.

So I found out, I can use light partition to group light together:

light:
  - platform: partition
    name: "Lobby livingroom light"
    segments:
      - single_light_id: output_component_left
      - single_light_id: output_component_right
    effects:
      - random:
      - pulse:
      - strobe:
      - flicker:
  - platform: monochromatic
    name: "Livingroom light left"
    id: output_component_left
    output: pwm_b
    internal: true
  - platform: monochromatic
    name: "Livingroom light right"
    id: output_component_right
    output: pwm_w
    internal: true

The problem is that I get a simple on/off light in HA now instead of dimmable LED light. Almost had it:)

I’m not familiar to partition platform. I suggested light group

Yes, partitions for monochromatic lights were released in the latest ESPHome version.

I now have a working example with button switch doing multiple thing:

  • single press: on/off
  • double press: full power
  • triple press: evening mode
  • long hold: slow dimming
substitutions:
  devicename: lobby_livingroom_light
  friendly_name: Lobby livingroom light
  device_description: Shelly RGBW2 lobby livingroom light

esphome:
  name: ${devicename}
  platform: ESP8266
  # Set modwifi on shelly devices since they have 2MB of flash
  board: modwifi

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Should make wifi signal better (https://www.die-welt.net/2020/04/controlling-roller-shutters-using-a-shelly-25-esphome-and-home-assistant/)
  power_save_mode: none
  fast_connect: true
  manual_ip:
    static_ip: 192.168.50.73
    gateway: !secret ip_gateway
    subnet: !secret ip_subnet
    dns1: !secret ip_dns1

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ${friendly_name}
    password: !secret ap_password

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

time:
  # Sync RTC time with HA
  - platform: homeassistant
    id: homeassistant_time

text_sensor:
  # Sensor with esphome versiona and fw build time
  - platform: version
    name: ${friendly_name} version
  # Extra wifi info from device
  - platform: wifi_info
    ip_address:
      name: ${friendly_name} IP
    ssid:
      name: ${friendly_name} SSID
    bssid:
      name: ${friendly_name} BSSID

sensor:
  # Reports the WiFi signal strength
  - platform: wifi_signal
    name: ${friendly_name} RSSI
    update_interval: 60s
  # Reports how long the device has been powered (in minutes) since last reboot
  - platform: uptime
    name: ${friendly_name} uptime
    update_interval: 60s
    filters:
      - lambda: return x / 3600;
    unit_of_measurement: "h"

switch:
  - platform: restart
    name: ${friendly_name} restart

# RGBW2 Pings
# Red 12
# Green 15
# Blue 14
# White 04
# AC switch: 5 (input)
# Push button: 13 (input)
# Status led: 2
# Power usage: A0 (analog input)

output:
  - platform: esp8266_pwm
    pin: GPIO12
    frequency: 1000 Hz
    id: out_ch1
  - platform: esp8266_pwm
    pin: GPIO15
    frequency: 1000 Hz
    id: out_ch2
  - platform: esp8266_pwm
    pin: GPIO14
    frequency: 1000 Hz
    id: out_ch3
  - platform: esp8266_pwm
    pin: GPIO4
    frequency: 1000 Hz
    id: out_ch4

light:
  - platform: partition
    name: "Lobby livingroom light"
    id: light_group
    default_transition_length: 0.3s
    segments:
      - single_light_id: light_ch1
      - single_light_id: light_ch2
      - single_light_id: light_ch3
      - single_light_id: light_ch4
  - platform: monochromatic
    id: light_ch1
    output: out_ch1
    internal: true
  - platform: monochromatic
    id: light_ch2
    output: out_ch2
    internal: true
  - platform: monochromatic
    id: light_ch3
    output: out_ch3
    internal: true
  - platform: monochromatic
    id: light_ch4
    output: out_ch4
    internal: true


binary_sensor:
  - platform: status
    name: ${friendly_name} status
  - platform: gpio
    pin:
      number: GPIO5
    name: "Livingroom light switch"
    id: light_touch
    # internal: true
    on_multi_click:
      # Dimming
      - timing:
        - ON for at least 1s
        then:
          - logger.log: "Start dimming"
          - while:
              condition:
                binary_sensor.is_on: light_touch
              then:
                - light.dim_relative:
                    id: light_group
                    relative_brightness: -5%
                    transition_length: 0.2s
                - delay: 0.1s
      # Double click
      - timing:
          - ON for at most 1s
          - OFF for at most 0.5s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - logger.log: "Double Clicked - Full power"
          - light.turn_on:
              id: light_group
              brightness: 100%
      # Triple click
      - timing:
          - ON for at most 1s
          - OFF for at most 0.5s
          - ON for at most 1s
          - OFF for at most 0.5s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - logger.log: "Triple Clicked - Evening mode"
          - light.turn_on:
              id: light_group
              brightness: 60%
      # Toggle light
      - timing:
        - ON for at most 1s
        - OFF for at least 0.5s
        then:
          - if:
              condition:
                - light.is_off: light_group
              then:
                - logger.log: "Single Short Clicked - toggle on"
                - light.turn_on:
                    id: light_group
                    brightness: 100%
              else:
                - logger.log: "Single Short Clicked - toggle off"
                - light.turn_off: light_group

status_led:
  pin:
    number: GPIO2
    inverted: yes
1 Like