ZLD-44-EU-W Powerstrip @ ESPHome

Greetings.

I would appreciate help with powerstrip configuration for ESPHome. I got covered every relay switch, the only thing eludes me is a POWER BUTTON (which is a binary sensor): it requires a script, which toggles all sockets ON and OFF simultaneously. I went with lambdas: on_click I check if retrieved state is ‘true’, turn all sockets off, publish_state(id) to ‘false’ and vice versa. I got it to this part:

binary_sensor:
  - platform: gpio
    pin: 3
    name: zld_44eu_w_button
    id: pwr
    on_click:
      min_length: 50ms
      max_length: 500ms
      then:
        lambda: !lambda |-
          if (id(pwr).state) {
            id(zld_44eu_w_relay1).turn_off();
            id(zld_44eu_w_relay2).turn_off();
            id(zld_44eu_w_relay3).turn_off();
            id(zld_44eu_w_relay4).turn_off();
            id(zld_44eu_w_relay_usb).turn_off();
            id(pwr).publish_state(false);
          } else {
            id(zld_44eu_w_relay1).turn_on();
            id(zld_44eu_w_relay2).turn_on();
            id(zld_44eu_w_relay3).turn_on();
            id(zld_44eu_w_relay4).turn_on();
            id(zld_44eu_w_relay_usb).turn_on();
            id(pwr).publish_state(true);

I got GPIOs right, so I’m clearly missing something in the code, because button toggles power on once by double-clicking and not working at all after that. Single click doesn’t work at all, plus once sockets are on, they won’t switch off via the button, only though HA interface. Where am I wrong exactly?

Thank you in advance.

There is a sample code here https://esphome-configs.io/devices/brilliant-smart-powerboard/

It does more than you want, but may give inspiration.

1 Like

Thank you kindly, dear Sir!

I totally missed the idea that lambda condition checks are the same with C++ :open_mouth:
Plus, I misiterpreted button states, so for me this piece of code goes like this:

binary_sensor:
  - platform: gpio
    pin: 3
    name: zld_44eu_w_button
    internal: true
    on_press:
      lambda: |-
        if (! (id(zld_44eu_w_relay1).state || id(zld_44eu_w_relay2).state || id(zld_44eu_w_relay3).state || id(zld_44eu_w_relay4).state || id(zld_44eu_w_relay_usb).state)) {
          id(zld_44eu_w_relay1).turn_on();
          id(zld_44eu_w_relay2).turn_on();
          id(zld_44eu_w_relay3).turn_on();
          id(zld_44eu_w_relay4).turn_on();
          id(zld_44eu_w_relay_usb).turn_on();
        } else {
          id(zld_44eu_w_relay1).turn_off();
          id(zld_44eu_w_relay2).turn_off();
          id(zld_44eu_w_relay3).turn_off();
          id(zld_44eu_w_relay4).turn_off();
          id(zld_44eu_w_relay_usb).turn_off();
        }

“If any of the relays are on - turn everything off, otherwise - turn everything on”
Now I have to realise how to restore relays to previous condition individually, not turn them on all at once.

Glad you got it sorted. I claim no credit for the code though. I copied it from another config.

1 Like

hey @YujiTFD i finally managed to flash this strip with esphome. would you mind sharing your full config for this device?

Hi there.
You message caught me on the train station, leaving city for a day :slight_smile: I will return by Wednesday, stay in touch.

Hello again.
Full code below. Again, it’s a single-click logic “If any of the relays are on - turn everything off, otherwise - turn everything on”:

esphome:
  name: zld-44eu-w
  platform: ESP8266
  board: esp8285
  esp8266_restore_from_flash: false

wifi:
  ssid: !secret wifi_ssid_liot
  password: !secret wifi_password_liot
  fast_connect: on

# Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "ZLD_44EU_W Fallback Hotspot"
#    password: !secret ap_password

captive_portal:

# Enable logging (NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE)
logger:
  level: DEBUG
  baud_rate: 0
  esp8266_store_log_strings_in_flash: false

# Enable Home Assistant API
api:
#  password: !secret esphome_api_password

ota:
#  password: !secret esphome_ota_password

web_server:
  port: 80

status_led:
  pin: 1

binary_sensor:
  - platform: gpio
    pin: 3
    name: zld_44eu_w_button
    internal: true
    on_press:
      lambda: |-
        if (! (id(zld_44eu_w_relay1).state || id(zld_44eu_w_relay2).state || id(zld_44eu_w_relay3).state || id(zld_44eu_w_relay4).state || id(zld_44eu_w_relay_usb).state)) {
          id(zld_44eu_w_relay1).turn_on();
          id(zld_44eu_w_relay2).turn_on();
          id(zld_44eu_w_relay3).turn_on();
          id(zld_44eu_w_relay4).turn_on();
          id(zld_44eu_w_relay_usb).turn_on();
        } else {
          id(zld_44eu_w_relay1).turn_off();
          id(zld_44eu_w_relay2).turn_off();
          id(zld_44eu_w_relay3).turn_off();
          id(zld_44eu_w_relay4).turn_off();
          id(zld_44eu_w_relay_usb).turn_off();
        }

switch:
  - platform: gpio
    pin: 5
    name: zld_44eu_w_relay1
    icon: mdi:power-socket-eu
    id: zld_44eu_w_relay1
    restore_mode: RESTORE_DEFAULT_ON

  - platform: gpio
    pin: 4
    name: zld_44eu_w_relay2
    icon: mdi:power-socket-eu
    id: zld_44eu_w_relay2
    restore_mode: RESTORE_DEFAULT_ON

  - platform: gpio
    pin: 12
    name: zld_44eu_w_relay3
    icon: mdi:power-socket-eu
    id: zld_44eu_w_relay3
    restore_mode: RESTORE_DEFAULT_ON

  - platform: gpio
    pin: 13
    name: zld_44eu_w_relay4
    icon: mdi:power-socket-eu
    id: zld_44eu_w_relay4
    restore_mode: RESTORE_DEFAULT_ON

  - platform: gpio
    pin: 14
    inverted: yes
    name: zld_44eu_w_relay_usb
    icon: mdi:usb
    id: zld_44eu_w_relay_usb
    restore_mode: RESTORE_DEFAULT_ON
2 Likes