Power metering for the Sonoff Dual R3 r1.6 using esphome
Note: The CSE7761 is now supported by ESPhome!
Al little while back we published this article on the new Sonoff Dual R3. We mentioned that the only disadvantage was that esphome did not yet support power metering as esphome has no support for the CSE7761 chip used for power metering.
That has now changed with this custom module for the CSE7761 made by Berfenger that works just great!
Please mind that this only works on PCB revision 1.6.
Here’s the modified version of our config that includes this module:
substitutions: devicename: sonoff-dualr3 long_devicename: Sonoff DualR3 external_components: - source: github://berfenger/esphome_components components: [ cse7761 ] esphome: name: $devicename platform: ESP32 board: esp32dev wifi: ssid: !secret esphome_wifi_ssid password: !secret esphome_wifi_password power_save_mode: light ap: ssid: $devicename password: !secret esphome_ap_password captive_portal: api: password: !secret esphome_api_password ota: password: !secret esphome_ota_password web_server: port: 80 logger: baud_rate: 0 # remove # below to enable ble tracking #esp32_ble_tracker: uart: tx_pin: GPIO25 rx_pin: GPIO26 baud_rate: 38400 parity: EVEN stop_bits: 1 sensor: - platform: wifi_signal name: "$long_devicename WiFi Signal" update_interval: 60s - platform: cse7761 update_interval: 5s voltage: name: "$long_devicename Voltage" current_1: name: "$long_devicename Current 1" current_2: name: "$long_devicename Current 2" active_power_1: name: "$long_devicename Power 1" active_power_2: name: "$long_devicename Power 2" output: - platform: gpio pin: GPIO27 id: relay1 - platform: gpio pin: GPIO14 id: relay2 switch: - platform: output name: "$long_devicename - relay 1" output: relay1 id: sw1 - platform: output name: "$long_devicename - relay 2" output: relay2 id: sw2 status_led: pin: number: GPIO13 inverted: yes binary_sensor: - platform: gpio pin: number: GPIO0 mode: INPUT_PULLUP inverted: True name: "$long_devicename button" on_press: - logger.log: "$long_devicename button" - switch.toggle: sw1 - platform: gpio pin: number: GPIO32 mode: INPUT_PULLUP inverted: True name: "$long_devicename switch 1" on_press: - logger.log: "$long_devicename switch 1" - switch.toggle: sw1 - platform: gpio pin: number: GPIO33 mode: INPUT_PULLUP inverted: True name: "$long_devicename switch 2" on_press: - logger.log: "$long_devicename switch 2" - switch.toggle: sw2
If you would like to change power usage to kW in stead of Watt in ESPhome change:
active_power_1: name: "$long_devicename Power 1" id: act_power_1 filters: - multiply: 0.001 unit_of_measurement: kW active_power_2: name: "$long_devicename Power 2" id: act_power_2 filters: - multiply: 0.001 unit_of_measurement: kW
If you like to add a sensor for kW usage, do so in Home Assistant:
sensor: - platform: template sensors: sonoff_dual_kilowatt_sensor_1: friendly_name: "Sonoff Dual Kilowatt Sensor 1" unit_of_measurement: "kW" value_template: "{{ states('sensor.your_esphome_active_power_1_sensor_name') | float * 0.001 }}" - platform: template sensors: sonoff_dual_kilowatt_sensor_2: friendly_name: "Sonoff Dual Kilowatt Sensor 2" unit_of_measurement: "kW" value_template: "{{ states('sensor.your_esphome_active_power_2_sensor_name') | float * 0.001 }}"
Please subscribe to our YouTube channel and hit the notification bel. We are not very active on Youtube yet, but we will be in the future. It’s the best way to support us and you won’t miss any of our upcoming video’s!
Please subscribe to our newsletter!
[…] anyone knows how to get the power metering working, please share in the comments! << Now fixed and config […]
Super, thanks!
How can set kWh to switch 1 (sw1) and switch 2 (sw2) and all switches (sw1+sw2)?
What the code in Sonoff Dual R3?
Can you help me?
Hi, that’s all in the documentation of esphome: https://esphome.io/components/sensor/total_daily_energy.html
I just noticed that this trick does not work for this sensor, so then just create a template sensor in Home Assistant. Check the article again. I have added it.
Hi, Just gotten my Dual R3 and flashed wit exactly the same config as above (wifi stuff changed).
Flashing was fine, however after hard reboot I get a unsuccessful boot loop with:
* (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
No matter if I flash esphome or tasmota32solo1.bin, the result is the same.
Board version is 1.6 and the esp32 is the D0WD V3, so I do not understand what is the actual issue.
I thought it may be power related so I also tried a more powerful power supply.
Still no luck
Any pointers?
I really do not know what could be wrong with that one, sorry.