Sonoff POW R2 mystery

I had a Sonoff POW R2 lying around for some time and finally i found some use for it - monitoring my water pump consumption, warning when the pump runs longer then expected (possible tap left open in the garden somewhere, etc).

I flashed the Sonoff with ESPhome, did some tests with a lightbulb, set up some automations in HA, everything working OK for serveral hours, until I have decided to install it on its intended location, when the issues started:

  • relay started to turn off and on by itself, every 17-18 seconds. so relay was on, then after 17 seconds switched off briefly, stayed on for 17 seconds then back off
  • no connectivity via web interface or home assistant, although i could see it on the router with an IP address
  • no falback AP showed up from the sonoff

So I moved back the Sonoff into my office and hooked up to wall socket for observation. at first everything seemed alright - wifi connected, relay on, but after a few minutes the relay started to restart every 17 seconds and wifi connectivity got lost.

Looking into the ESPHome logs this is what I saw
[W][cse7766:080]: CSE7766 reports abnormal hardware: (0xF1)
[W][cse7766:081]: Coefficient storage area is abnormal.

Any idea why is this happening? I think the 17 sec interval would be a good start for the investigation

ESPhome config attached below (snatched it off a github page and modified slightly):

substitutions:
  esphome_name: water_pump

esphome:
  name: ${esphome_name}
  platform: ESP8266
  board: esp01_1m


wifi:
  ssid: radirpok_iot_outside
  password: !secret iot_password
  domain: !secret local_domain
  ap:
    ssid: "${esphome_name}_fallback"
    password: !secret ap_password

api:
  reboot_timeout: 60min

ota:

time:
  - platform: homeassistant


captive_portal:

# Enable web server
web_server:
  port: 80

# Enable logging
logger:

uart:
  rx_pin: RX
  baud_rate: 4800

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "${esphome_name} Button"
    on_press:
      - switch.toggle: fakebutton
  
  - platform: template
    name: "Water pump Running"
    filters:
      - delayed_off: 15s
    lambda: |-
      if (isnan(id(power).state)) {
        return {};
      } else if (id(power).state > 4) {
        // Running
        return true;
      } else {
        // Not running
        return false;
      }

switch:
  - platform: template
    name: "Water pump Relay"
    optimistic: true
    id: fakebutton
    turn_on_action:
    - switch.turn_on: relay
#    - light.turn_on: led
    turn_off_action:
    - switch.turn_off: relay
#    - light.turn_off: led
  - platform: gpio
    id: relay
    pin: GPIO12
    restore_mode: RESTORE_DEFAULT_ON

output:
  - platform: esp8266_pwm
    id: pow_blue_led
    pin:
      number: GPIO13
      inverted: True

light:
  - platform: monochromatic
    name: "${esphome_name} Blue LED"
    output: pow_blue_led
    id: led
    internal: true

sensor:
  - platform: wifi_signal
    name: "${esphome_name} WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: "${esphome_name} Uptime"
  - platform: cse7766
    update_interval: 2s
    current:
      name: "${esphome_name} Current"
    voltage:
      name: "${esphome_name} Voltage"
    power:
      name: "${esphome_name} Power"
      id: power
      on_value_range:
        - above: 4.0
          then:
            - light.turn_on: led
        - below: 3.0
          then:
            - light.turn_off: led

text_sensor:
  - platform: version
    name: "Water pump power meter"

I’m impressed with all the features you put in your YAML - mine is way simpler than that. Now I want yours.

The relay clicking on and off sounds like the device is rebooting. Maybe monitor it in the Logs view to see what is happening.

From my own experience, way back in 1.13-ish, I had a problem with an ESPHome device that would lose connection to WiFi and get upset. I solved it by assigning it a static IP. As a result, I now always assign a static IP even though it’s probably not necessary. So maybe that’s something you can try too.

It sounds weird and annoying, though.

Try esp8265 as your board type.

@DeeBeeKay the yaml is not my work, have it from here, slightly adapted Sonoff POW R2 Washing Machine Sensor Example · GitHub

the problem is I can’t monitor the logs as the connection is lost when the device starts rebooting (appparently). wifi connectivity is not an issue, tried several locations near the AP, with the same result.

after thinking about it heavily my plan is the following:

  • try to power the board from UART to see if I get any useful logs
  • dumb down the YAML to a bare minimum to see if it helps
  • flash tasmota, always wanted to try it anyways

Okay but before you go overboard, do try @nickrout’s solution because he’s very knowledgeable about this platform and has been a great help to me in the past. If he said it, I trust it.

For what it is worth, here is a link to my YAML for the Sonoff POWR2, which is working well and not rebooting.

sure, will give it a try, but your config uses the same board as mine, and it was working a day before without any issues to i don’t have too high expectations

You are too kind. I just looked at, and repeated, the instructions!

That’s true, but that doesn’t necessarily mean my POWR2 has the same ESP chip as yours. Sonoff are constantly tweaking.

Although, you do say yours was working on the test bench, but then not after you deployed it. Is there a chance you wired it wrong when you installed it, and maybe cooked it a little?

i was playing around with the yaml, gradually addding new lines, and it seems the issue starts when adding the section for the power measurement chip:

sensor:
    - platform: cse7766
    update_interval: 2s
    current:
      name: "${esphome_name} Current"
    voltage:
      name: "${esphome_name} Voltage"
    power:
      name: "${esphome_name} Power"
      id: power

this seems very similar to this issue here Sonoff POW R2 continuous restarts after adding power sensor cse7766 · Issue #1 · esphome/issues · GitHub which should be resolved according to github

for some reason i am not able to get any logs from the device via USB. actually, when the POW R2 is connected via USB and trying to access the logs my dekstop compter become unusable, with random mouse movement and clicks, that disappear the instant i pull the USB out of the computer :confused:

What is you full config now?

this was my last working config:

substitutions:
  esphome_name: water_pump

esphome:
  name: ${esphome_name}
  platform: ESP8266
  board: esp8285


wifi:
  ssid: *******
  password: !secret iot_password
  domain: !secret local_domain
  ap:
    ssid: "${esphome_name}_fallback"
    password: !secret ap_password

api:
  reboot_timeout: 60min

ota:

time:
  - platform: homeassistant


captive_portal:

# Enable web server
web_server:
  port: 80

# Enable verbose logging
logger:
  level: VERBOSE

# uart:
#  rx_pin: RX
#  baud_rate: 4800

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "${esphome_name} Button"
    on_press:
      - switch.toggle: fakebutton
  
#  - platform: template
#    name: "Water pump Running"
#    filters:
#      - delayed_off: 15s
#    lambda: |-
#      if (isnan(id(power).state)) {
#        return {};
#      } else if (id(power).state > 4) {
#        // Running
#        return true;
#      } else {
#        // Not running
#        return false;
#      }

switch:
  - platform: template
    name: "Water pump Relay"
    optimistic: true
    id: fakebutton
    turn_on_action:
    - switch.turn_on: relay
#    - light.turn_on: led
    turn_off_action:
    - switch.turn_off: relay
#    - light.turn_off: led
  - platform: gpio
    id: relay
    pin: GPIO12
    restore_mode: RESTORE_DEFAULT_ON

output:
  - platform: esp8266_pwm
    id: pow_blue_led
    pin:
      number: GPIO13
      inverted: True

light:
  - platform: monochromatic
    name: "${esphome_name} Blue LED"
    output: pow_blue_led
    id: led
    internal: true

sensor:
  - platform: wifi_signal
    name: "${esphome_name} WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: "${esphome_name} Uptime"
#  - platform: cse7766
#    update_interval: 2s
#    current:
#      name: "${esphome_name} Current"
#    voltage:
#      name: "${esphome_name} Voltage"
#    power:
#      name: "${esphome_name} Power"
#      id: power
#      on_value_range:
#        - above: 4.0
#          then:
#            - light.turn_on: led
#        - below: 3.0
#          then:
#            - light.turn_off: led

#text_sensor:
#  - platform: version
#    name: "Water pump power meter"

when i commented above the section mentioned in my previous post the sonoff started to reboot

According to the docs you need to turn off serial logging.

1 Like

@nickrout thanks, that it seems that was it :man_facepalming:

edit: maybe any idea on how to modify my YAML so i can add the device to the new HA Energy Dashboard? The device does not show up for some reason

You need an energy sensor for that. Power is different to energy. See Total Daily Energy Sensor — ESPHome

2 Likes