Shelly 2.5 Power Monitoring Issues - ADE7953 Power Sensor

Hi I wanted to create a thread about my inaccurate power readings from my Shelly 2.5’s flashed with ESP Home.

I converted over my Shelly 2.5s to ESP Home out of frustration with the MQTT auto-discovery script and the inability to easily create a device in YAML rather than creating single entities not tied together in 1 device (yes I know attributes exist but it’s just not the same as a device).

Anyway after setting the config file to just the way I like I realised the power monitoring is wildly off. Scavenging off forum threads this is the best config I can make.

Does anyone have suggestions on how to make the power monitoring more accurate for Shelly 2.5’s? I’m using linear calibration, I actually had worse results with polynomial 2 and 3 degree’s (I haven’t tried 5 degrees) I’m thinking of just disabling the sensors at this rate as I have whole home power monitoring.

I’m thinking of reading this dreaded document on the ADE7953 Power Sensor to see what the best method will be for calibration but it’s overwhelming for the moment… Also after a quick glance no idea how to go about implementing this…

https://www.analog.com/media/en/technical-documentation/application-notes/an-1118.pdf

I’m carrying over findings for the Shelly 2.5 from this thread as it mostly relates to the Shelly 1PM which uses a different chip to the 2.5

substitutions:
  friendly_name: Bedroom Ensuite Secondary Light Switches
  device_name: bedroom-ens-sec-light-switches
  channel_1: Bedroom Ensuite Heat Lamps
  channel_2: Bedroom Ensuite Lightstrip

  ssid: !secret wifi_ssid
  password: !secret wifi_password

  max_power: "2000.0"
  max_temp: "80.0"

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

wifi:
  ssid: ${ssid}
  password: ${password}
  power_save_mode: HIGH # for ESP8266 LOW/HIGH are mixed up, esphome/issues/issues/1532

  ap:
    ssid: ${device_name}

captive_portal:

logger:

api:

ota:

web_server:
  port: 80
  version: 1

time:
  - platform: sntp
    id: my_time

i2c:
  sda: GPIO12
  scl: GPIO14

sensor:
  - platform: ade7953
    irq_pin: GPIO16 # Prevent overheating by setting this
    voltage:
      name: ${friendly_name} Voltage
    # On the Shelly 2.5 channels are mixed ch1=B ch2=A
    current_a:
      name: ${channel_2} Current
      internal: true
    current_b:
      name: ${channel_1} Current
      internal: true
    active_power_a:
      name: ${channel_2} Power
      id: power_channel_2
      # active_power_a is normal, so don't multiply by -1
      filters:
        - calibrate_linear:
            - 0.0 -> 0.0
            - 70 -> 10
            - 4600 -> 600
        # Make everything below 2W appear as just 0W.
        # Furthermore it corrects 1.0W for the power usage of the plug.
        - lambda: if (x < (2 + 1)) return 0; else return (x - 1);
      on_value_range:
        - above: ${max_power}
          then:
            - light.turn_off: shelly_light_2
            - homeassistant.service:
                service: persistent_notification.create
                data:
                  title: Message from ${friendly_name}
                data_template:
                  message: Switch turned off because power exceeded ${max_power}W
    active_power_b:
      name: ${channel_1} Power
      id: power_channel_1
      # active_power_b is inverted, so multiply by -1
      filters:
        - multiply: -1
        - calibrate_linear:
            - 0.0 -> 0.0
            - 70 -> 10
            - 4600 -> 600
        # Make everything below 2W appear as just 0W.
        # Furthermore it corrects 1.0W for the power usage of the plug.
        - lambda: if (x < (2 + 1)) return 0; else return (x - 1);
      on_value_range:
        - above: ${max_power}
          then:
            - light.turn_off: shelly_light_1
            - homeassistant.service:
                service: persistent_notification.create
                data:
                  title: Message from ${friendly_name}
                data_template:
                  message: Switch turned off because power exceeded ${max_power}W
    update_interval: 5s

  - platform: total_daily_energy
    name: ${channel_1} Energy
    power_id: power_channel_1
    filters:
      # Multiplication factor from W to kWh is 0.001
      - multiply: 0.001
    unit_of_measurement: kWh

  - platform: total_daily_energy
    name: ${channel_2} Energy
    power_id: power_channel_2
    filters:
      # Multiplication factor from W to kWh is 0.001
      - multiply: 0.001
    unit_of_measurement: kWh

  # NTC Temperature
  - platform: ntc
    sensor: temp_resistance_reading
    name: ${friendly_name} Temperature
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    icon: "mdi:thermometer"
    calibration:
      b_constant: 3350
      reference_resistance: 10kOhm
      reference_temperature: 298.15K
    on_value_range:
      - above: ${max_temp}
        then:
          - light.turn_off: shelly_light_1
          - light.turn_off: shelly_light_2
          - homeassistant.service:
              service: persistent_notification.create
              data:
                title: Message from ${friendly_name}
              data_template:
                message: Switch turned off because temperature exceeded ${max_temp}°C
  - platform: resistance
    id: temp_resistance_reading
    sensor: temp_analog_reading
    configuration: DOWNSTREAM
    resistor: 32kOhm
  - platform: adc
    id: temp_analog_reading
    pin: A0

status_led:
  pin:
    number: GPIO0
    inverted: yes

output:
  - platform: gpio
    pin: GPIO4
    id: shelly_relay_1
  - platform: gpio
    pin: GPIO15
    id: shelly_relay_2

light:
  - platform: binary
    id: shelly_light_1
    name: ${channel_1}
    output: shelly_relay_1
    icon: "mdi:heat-wave"
    restore_mode: RESTORE_DEFAULT_ON
  - platform: binary
    id: shelly_light_2
    name: ${channel_2}
    output: shelly_relay_2
    icon: "mdi:led-strip-variant"
    restore_mode: RESTORE_DEFAULT_ON

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
    name: "${channel_1} Switch Input"
    
  - platform: gpio
    pin:
      number: GPIO5
    name: "${channel_2} Switch Input"

How does it compare to just using the Shelly integration, which creates a device?

Ok so now I’m just going to replace the Shelly’s I have flashed with ESPHome for a stock Shelly with this issue. Glad I did a test run before I “upgraded” all my Shelly’s.

I have had endless problems with both the “official” Shelly integration, and ShellyforHASS (Somehow I found it to be worse than the official integration). I noticed switching speed was really slow compared to MQTT. I have around 30 shelly devices around the house, I tried the Shelly MQTT autodiscovery scripts and so forth which worked great up until I cleared all the retained msgs from my MQTT broker…(big mistake) because that reset all the device and entity configurations I had for my shelly’s. No way was I going to redo everything just to have it probably deleted again in the future.

So I have now resorted to just hard coding in my Shelly entities in yaml. I have 1000 lines of yaml config now… Absolute torture but it had to be done.

Since this ESPHome power monitoring issue is kind of a deal breaker in my books as now I have lost / downgraded the functionality of my product, ESPHome is off the table. I want to be confident about the values that the Shelly reports.

Gen 2 Shelly’s look even worse from the ESPHome front. You apparently have to calibrate the internal temperature sensor?? Shelly’s primarily use will be in the wall this is a huge fire hazard issue if the firmware to auto shut off the switch is reporting inaccurate temperature values. And there is no good way of measuring the temperature to calibrate it. Until this issue gets resolved (No idea how it will happen) please stay away from ESPHome on Gen 2 Shelly’s that are going inside your walls.

The irony is now all my lights are either dumb(like 3 switches) or Phillips Hue Zigbee or ESPHome based so now most of my Shelly’s are permanently in detached mode and I could probably just get away with the official integration.

I pray some brave soul goes and makes a Shelly competitor with Australian electrical approvals that is Tasmota or ESPHome based.

Never had any problem with the shelly home assistant integration. I just don’t get it.