Sonoff POW Elite Configuration

Hello everyone,

This is my first post ever, I’ve been here for a long time, but just reading. After all this years I’ve learned a lot so I feel like I owe you this contribution, cuz I searched a lot and I found nothing so here you go, a configuration example of the new Sonoff POW Elite or POWR316D for ESPHome.

substitutions:
  device_name: your_device_name
  device_ip: your_device_ip

esphome:
  name: ${device_name}

esp32:
  board: nodemcu-32s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: ${device_ip}
    gateway: !secret wifi_gateway
    subnet: 255.255.255.0
  ap:
    password: !secret wifi_password
captive_portal:

logger:
    baud_rate: 0
    
api:
  reboot_timeout: 15min
  password: !secret api_key
  encryption:
    key: !secret api_key_cryp

ota:
  password: !secret ota_password

uart:
  rx_pin: GPIO16
  baud_rate: 4800

sensor:
  - platform: cse7766
    update_interval: 30s
    current:
      name: ${device_name} Current
      id: a_sensor
    voltage:
      name: ${device_name} Voltage
      id: v_sensor
    power:
      name: ${device_name} Power
      id: w_sensor
    energy:
      name: ${device_name} Energy
      id: wh_sensor
  - platform: wifi_signal
    name: ${device_name} Wifi Signal Strength
    update_interval: 60s
  - platform: uptime
    name: ${device_name} Uptime

binary_sensor:
  - platform: gpio
    pin: GPIO00
    id: reset
    internal: true
    filters:
      - invert:
      - delayed_off: 10ms
    on_click:
      - max_length: 350ms  # short press to toggle the relay
        then:
          switch.toggle: relay_1
      - min_length: 360ms  # long press to cycle display info
        max_length: 3s
        then:
          - if:
              condition:
                binary_sensor.is_on: page
              then:
                binary_sensor.template.publish:
                  id: page
                  state: OFF
              else:
                binary_sensor.template.publish:
                  id: page
                  state: ON
  - platform: template  # this is a fake sensor to tell the screen which info to show on display
    name: "Display page"
    id: page
    publish_initial_state: true
    internal: true

display:
  platform: tm1621
  id: tm1621_display
  update_interval: 1s
  cs_pin: GPIO25
  data_pin: GPIO14
  read_pin: GPIO26
  write_pin: GPIO27
  lambda: |-
    if (id(page).state) {
      it.display_voltage(true);
      it.display_kwh(false);
      it.printf(0, "%.1f", id(v_sensor).state);
      it.printf(1, "%.1f", id(a_sensor).state);
    } else {  
      it.display_voltage(false);
      it.display_kwh(true);
      it.printf(0, "%.1f", id(wh_sensor).state);
      it.printf(1, "%.1f", id(w_sensor).state);
    }

output:
  - platform: ledc
    id: led
    pin: GPIO18

switch:
  - platform: gpio
    name: ${device_name}_switch
    icon: "mdi:light-switch-off"
    pin: GPIO13
    id: relay_1
    restore_mode: restore_default_off
    on_turn_on:
      light.turn_off: switch_led
    on_turn_off:
      light.turn_on: switch_led

status_led:
  pin:
    number: GPIO05
    inverted: True

light:
  - platform: monochromatic
    name: ${device_name}_switch_led
    id: switch_led
    output: led
    internal: true
    restore_mode: restore_default_off

I’m not a programmer or anything, just a geek so you are invited to improve my code.

Regards!

3 Likes

Hi, first of all, thanks for your contribution. I’m having trouble registering my Sonoff POW Elite, it does not show me the current consumption etc. To where exactly have I upload this configuration?

With the original sonoff firmware the kwh shows in the app, but not on the display on the unit or in home assistant. Must be an sonoff issue.

I didn’t test this device with Sonoff original firmware, sorry. I went directly to flash it with EspHome :sweat_smile:

Awesome! I was waiting for someone to do the hard work of setting up config and getting the libraries for the LCD on these so thanks! Will test it out soon.

Hi Thanks.

I got it working on the Sonoff Elite Origin also. (disabled the display feature of course)

Are the readings of your devices correct? For example, with an amperage of 15.5A and a voltage of 230V, the power I get is about 3.05kW when it should be about 3.5kW.
I’m still on ewelink firmware because for some reason i can’t use the serial port without errors

I’ve flashed the sonoff with the custom firmware. I’ve tested the load of some appliances first with a standalone reader first … In my case the readings
of the sonoff are showing the same results as the standalone power monitor.

Thanks for the answer. Could you explain how to flash this sonoff? I’m having problems getting always “unhandled exception” or “invalid head of packet” erros. With the same serial i’m able to flash other sonoff devices and ESP without any problem. My serial adapter have a cp2102 chip, so i don’t think the problem is the serial adapter.
I’ve tried with pair button always pushed, pushed for a while and then released, wituout pushing the button… without succesful

Hi GenGT.

i’ve used esphome flasher. this video helped me in the right direction. ⚡SONOFF POW Elite Tasmota Firmware - YouTube
I guess this video is not in your native language but the enabling the captions might help you.

1 Like

Thanks, seems the problem is on the usb chip. My USB chip is a CP2102 purchased a usb with the chip ch340 and it works!

1 Like

So I finally got hold of 2 of these switches (for the pool pump and geyser)

Now between this post and the official ESPhome example Sonoff POW Elite 20a (POWR320D) | ESPHome-Devices I got the switch working fine. However I’m not getting any readings on the power sensors (power current voltage energy) all reading “unknown”

I have another sonoff pow2 which shows everything fine and the have supposedly the same cse7766 sensor.

Any idea from anyone?

Here is my config

substitutions:
  friendly_name: Pool Pump
  device_name: sonoff-pow-elite-pool-pump

esphome:
  name: $device_name

esp32:
  board: nodemcu-32s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: $device_name
    password: !secret wifi_failover

captive_portal:
api:
ota:
logger:
  baud_rate: 0

uart:
  rx_pin: RX
  baud_rate: 4800

time:
  - platform: homeassistant
    id: homeassistant_time

sensor:
  - platform: cse7766
    update_interval: 2s
    current:
      name: $friendly_name Current
      id: a_sensor
    voltage:
      name: $friendly_name Voltage
      id: v_sensor
    power:
      name: $friendly_name Power
      id: w_sensor
    energy:
      name: $friendly_name Energy
      id: wh_sensor

  - platform: total_daily_energy
    name: $friendly_name Total Daily Energy
    power_id: w_sensor

  - platform: wifi_signal
    name: $friendly_name Wifi RSSI
    update_interval: 60s

binary_sensor:
  - platform: status
    name: $friendly_name Status

  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    id: button_1
    on_press:
      then:
        - switch.toggle: relay_1

  - platform: template # this is a fake sensor to tell the screen which info to show on display
    id: page
    publish_initial_state: true
    internal: true

display:
  platform: tm1621
  id: tm1621_display
  cs_pin: GPIO25
  data_pin: GPIO14
  read_pin: GPIO26
  write_pin: GPIO27
  lambda: |-
    if (id(page).state) {
      it.display_voltage(true);
      it.display_kwh(false);
      it.printf(0, "%.1f", id(v_sensor).state);
      it.printf(1, "%.1f", id(a_sensor).state);
    } else {  
      it.display_voltage(false);
      it.display_kwh(true);
      it.printf(0, "%.1f", id(wh_sensor).state);
      it.printf(1, "%.1f", id(w_sensor).state);
    }

output:
  - platform: ledc
    id: led
    pin:
      number: GPIO18
      inverted: True

switch:
  - platform: template
    name: $friendly_name
    optimistic: true
    id: relay_1
    lambda: |-
      if (isnan(id(w_sensor).state)) {
        return {};
      } else if (id(w_sensor).state > 4) {
        // Running
        return true;
      } else {
        // Not running
        return false;
      }
    turn_off_action:
      - switch.turn_on: relay_off
    turn_on_action:
      - switch.turn_on: relay_on
  - platform: gpio
    restore_mode: ALWAYS_ON
    internal: true
    id: relay_off
    pin: GPIO04
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: relay_off  #bi-stable relay so no need to keep on.
      - light.turn_off: switch_led
    interlock: [relay_on]
  - platform: gpio
    restore_mode: ALWAYS_OFF
    internal: true
    id: relay_on
    pin: GPIO02
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: relay_on  #bi-stable relay so no need to keep on.
      - light.turn_on: switch_led
    interlock: [relay_off]
  - platform: restart
    name: $friendly_name Restart

light:
  - platform: monochromatic
    id: switch_led
    output: led
    internal: True
  - platform: status_led
    id: wifi_status_led
    internal: True
    pin:
      number: GPIO05
      inverted: True

interval:
  - interval: 30s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - light.turn_on: wifi_status_led
        else:
          - light.turn_off: wifi_status_led

@fstof I’ve recently posted a problem with the POWR320D and the example you post, with the switch not working, but readings seems to work OK, not solved yet…
Try tasmota to see if all is working fine, i don’t think is a diferent sensor…

@GenGT do you perhaps have a link to the issue you posted? I’d like to watch it.

I’m not too keen in tasmota, as I like having all my esp stuff running on ESPhome and I don’t have an mqtt broker set up at the moment…

But anyway, I might just give it a test.

Thanks

This is the link

https://community.home-assistant.io/t/help-config-sonoff-powr320d-that-works-on-tasmota-but-not-in-esphome/492524

Below you have the link to tasmota. You only have to download the tasmota32.bin, upload to POWR320D, reboot, connect to the new SSID go to http://192.168.4.1 config your ssid, and finally choose powr320d template from the list. You can see all values on the web without configure anything of mqtt

A HA!
That post cleared something up on my config… I had the wrong pin on my uart (RX instead of GPIO16)

So now mine are working fine (relay and sensors)

Is fine to know it works for you, could you paste your config so i can see why my relay isn’t working?

Thanks

Here is my config
Note, some of the button functions I removed as I won’t be using the screen

substitutions:
  friendly_name: Pool Pump
  device_name: sonoff-pow-elite-pool-pump

esphome:
  name: $device_name

esp32:
  board: nodemcu-32s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: $device_name
    password: !secret wifi_failover

captive_portal:
api:
ota:
logger:
  baud_rate: 0

uart:
  rx_pin: GPIO16
  baud_rate: 4800

time:
  - platform: homeassistant
    id: homeassistant_time

sensor:
  - platform: cse7766
    update_interval: 2s
    current:
      name: $friendly_name Current
      id: a_sensor
    voltage:
      name: $friendly_name Voltage
      id: v_sensor
    power:
      name: $friendly_name Power
      id: w_sensor
    energy:
      name: $friendly_name Energy
      id: wh_sensor

  - platform: total_daily_energy
    name: $friendly_name Total Daily Energy
    power_id: w_sensor

  - platform: wifi_signal
    name: $friendly_name Wifi RSSI
    update_interval: 60s

binary_sensor:
  - platform: status
    name: $friendly_name Status

  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    id: button_1
    on_press:
      then:
        - switch.toggle: relay_1

  # - platform: gpio
  #   pin: GPIO00
  #   id: reset
  #   internal: true
  #   filters:
  #     - invert:
  #     - delayed_off: 10ms
  #   on_click:
  #     - max_length: 350ms # short press to toggle the relay
  #       then:
  #         switch.toggle: relay_1
  #     - min_length: 360ms # long press to cycle display info
  #       max_length: 3s
  #       then:
  #         - if:
  #             condition:
  #               binary_sensor.is_on: page
  #             then:
  #               binary_sensor.template.publish:
  #                 id: page
  #                 state: OFF
  #             else:
  #               binary_sensor.template.publish:
  #                 id: page
  #                 state: ON

  - platform: template # this is a fake sensor to tell the screen which info to show on display
    id: page
    publish_initial_state: true
    internal: true

display:
  platform: tm1621
  id: tm1621_display
  cs_pin: GPIO25
  data_pin: GPIO14
  read_pin: GPIO26
  write_pin: GPIO27
  lambda: |-
    if (id(page).state) {
      it.display_voltage(true);
      it.display_kwh(false);
      it.printf(0, "%.1f", id(v_sensor).state);
      it.printf(1, "%.1f", id(a_sensor).state);
    } else {  
      it.display_voltage(false);
      it.display_kwh(true);
      it.printf(0, "%.1f", id(wh_sensor).state);
      it.printf(1, "%.1f", id(w_sensor).state);
    }

output:
  - platform: ledc
    id: led
    pin:
      number: GPIO18
      inverted: True

switch:
  - platform: template
    name: $friendly_name
    optimistic: true
    id: relay_1
    lambda: |-
      if (isnan(id(w_sensor).state)) {
        return {};
      } else if (id(w_sensor).state > 4) {
        // Running
        return true;
      } else {
        // Not running
        return false;
      }
    turn_off_action:
      - switch.turn_on: relay_off
    turn_on_action:
      - switch.turn_on: relay_on
  - platform: gpio
    restore_mode: ALWAYS_ON
    internal: true
    id: relay_off
    pin: GPIO04
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: relay_off  #bi-stable relay so no need to keep on.
      - light.turn_off: switch_led
    interlock: [relay_on]
  - platform: gpio
    restore_mode: ALWAYS_OFF
    internal: true
    id: relay_on
    pin: GPIO02
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: relay_on  #bi-stable relay so no need to keep on.
      - light.turn_on: switch_led
    interlock: [relay_off]
  - platform: restart
    name: $friendly_name Restart

light:
  - platform: monochromatic
    id: switch_led
    output: led
    internal: True
  - platform: status_led
    id: wifi_status_led
    internal: True
    pin:
      number: GPIO05
      inverted: True

interval:
  - interval: 30s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - light.turn_on: wifi_status_led
        else:
          - light.turn_off: wifi_status_led

Finally!

Seems the problem is on this code

    lambda: |-
      if (isnan(id(w_sensor).state)) {
        return {};
      } else if (id(w_sensor).state > 4) {
        // Running
        return true;
      } else {
        // Not running
        return false;
      }

I’m making test without having anything connected to the output, and this code seems that only works if a device with consumption is connected…

Yea not sure about that, because it was working fine when I tested with no load on the output.

this lambda is a little confusing, I need to still try and understand it, there is a lot of simplification to be done in my opinion