Integration of new power sensor ADE7953 with shelly 2.5

Not sure, where to post this:

The new shelly 2.5 is available
https://github.com/arendst/Sonoff-Tasmota/wiki/Shelly-2.5

It can be used as a roller shutter.
It has the integrated power sensor (ADE7953) to determine whether the motor reached the end-position and stopped.

I’m already running ESPhome firmware on it, but I am missing the power sensor.
Any idea if/when this will be integrated in ESPhome?

Until someone comes fwd and integrate it. I think the main dev won’t add them. Not even shelly 2 had the power measure sensor.
For the moment try this

https://github.com/esphome/feature-requests/issues/182

Oh I see. To bad :frowning:

But thank you for the pointer. I will give this a try.

I see this has a branch to test, I’m trying to configure one now using this do you have a config you can share for the 2.5?

Hi,
I’m currently testing that branch, here’s a config for the shelly 2.5. Be aware that the webserver is enabled and I haven’t yet set the proper reporting intervals and I have to filter out readings lower than 1 W because they look like noise even if there’s nothing connected.

Have fun!

esphome:
  name: shellylaundry
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "SSID"
  password: "password"

# Enable logging
logger:
  level: INFO

# Enable Home Assistant API
api:

ota:

i2c:
  sda: GPIO12
  scl: GPIO14

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
    name: "Washing Machine Switch"
    on_press:
      then:
        - switch.toggle: washing_machine_relay
  - platform: gpio
    pin:
      number: GPIO5
    name: "Dryer Switch"
    on_press:
      then:
        - switch.toggle: dryer_relay

sensor:
  - platform: ntc
    sensor: laundry_resistance_sensor
    id: laundry_temperature
    name: "Laundry Temperature"
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    icon: mdi:thermometer
    calibration:
      b_constant: 3350
      reference_temperature: 25°C
      reference_resistance: 10kOhm
  - platform: adc
    id: laundry_source_sensor
    pin: A0
    update_interval: 10s
  - platform: resistance
    id: laundry_resistance_sensor
    sensor: laundry_source_sensor
    configuration: DOWNSTREAM
    resistor: 32kOhm
  - platform: ade7953
    voltage:
      name: "Laundry Voltage"
    current_a: 
      name: "ADE7953 Current 1"
    current_b:
      name: "ADE7953 Current 2"
    active_power_a:
      name: "ADE7953 Power 1"
    active_power_b:
      name: "ADE7953 Power 2"
      filters:
      - multiply: -1.0


status_led:
  pin:
    number: GPIO0
    inverted: yes

switch:
  - platform: gpio
    id: washing_machine_relay
    name: "Washing Machine Relay"
    pin: GPIO15
    restore_mode: ALWAYS_ON
  - platform: gpio
    id: dryer_relay
    name: "Dryer Relay"
    pin: GPIO4
    restore_mode: ALWAYS_ON 

web_server:
  port: 80
1 Like

This is a little off topic, but are you sure about your settings for the temperature-sensor? I get crazy high temperatures with this adc-resistance and b-constant.

Hi,

I think this is the correct configuration:

Could someone please try it?

Now I don’t have any shelly to try it…

substitutions:
  devicename: shelly1

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

wifi:
  ssid: "xx"
  password: "xxxxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Shelly Hotspot (xxxx)"
    password: "xxxx"

web_server:
  port: 80

captive_portal:

# Enable logging
logger:
  level: INFO

# Enable Home Assistant API
api:
  password: "xxxxxx"

ota:
  password: "xxxxxx"


i2c:
  sda: GPIO12
  scl: GPIO14

sensor:
  - platform: ade7953
    voltage:
      name: ${devicename} Voltage
    current_a:
      name: ${devicename} Current B
    current_b:
      name: ${devicename} Current A
    active_power_a:
      name: ${devicename} Active Power B
      filters:
        - multiply: -1
    active_power_b:
      name: ${devicename} Active Power A
      filters:
        - multiply: -1
    update_interval: 60s

  # NTC Temperature
  - platform: ntc
    sensor: temp_resistance_reading
    name: ${devicename} Temperature
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    icon: "mdi:thermometer"
    calibration:
      b_constant: 3350
      reference_resistance: 10kOhm
      reference_temperature: 25C
  - platform: resistance
    id: temp_resistance_reading
    sensor: temp_analog_reading
    configuration: DOWNSTREAM
    resistor: 32kOhm
  - platform: adc
    id: temp_analog_reading
    pin: A0
    update_interval: 10s
    
status_led:
  pin:
    number: GPIO0
    inverted: yes

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
    name: ${devicename} Switch1
    on_press:
      then:
        - switch.toggle: shelly_relay_1
  - platform: gpio
    pin:
      number: GPIO5
    name: ${devicename} Switch2
    on_press:
      then:
        - switch.toggle: shelly_relay_2

switch:
  - platform: gpio
    id: shelly_relay_1
    name: ${devicename} Relay1
    pin: GPIO15
    icon: "mdi:electric-switch"
    restore_mode: RESTORE_DEFAULT_OFF
  - platform: gpio
    id: shelly_relay_2
    name: ${devicename} Relay2
    pin: GPIO4
    icon: "mdi:electric-switch"
    restore_mode: RESTORE_DEFAULT_OFF

Thank you

1 Like

@anarro Just started working with my Shelly 2.5 and found this thead. Saved me a lot of work figuring things out. I loaded your code and it seems to be working. Here is a sample of the log output…

[12:20:44][D][adc:056]: ‘temp_analog_reading’: Got voltage=0.43V
[12:20:44][D][sensor:092]: ‘temp_analog_reading’: Sending state 0.43457 V with 2 decimals of accuracy
[12:20:44][D][resistance:037]: ‘temp_resistance_reading’ - Resistance 4853.1Ω
[12:20:44][D][sensor:092]: ‘temp_resistance_reading’: Sending state 4853.11182 Ω with 1 decimals of accuracy
[12:20:44][D][ntc:026]: ‘Smart Plug Temperature’ - Temperature: 45.5°C
[12:20:44][D][sensor:092]: ‘Smart Plug Temperature’: Sending state 45.50340 °C with 1 decimals of accuracy
[12:20:49][D][api.connection:583]: Client ‘Home Assistant 0.102.3 (192.168.1.200)’ connected successfully!
[12:20:54][D][adc:056]: ‘temp_analog_reading’: Got voltage=0.44V
[12:20:54][D][sensor:092]: ‘temp_analog_reading’: Sending state 0.43555 V with 2 decimals of accuracy
[12:20:54][D][resistance:037]: ‘temp_resistance_reading’ - Resistance 4865.7Ω
[12:20:54][D][sensor:092]: ‘temp_resistance_reading’: Sending state 4865.67578 Ω with 1 decimals of accuracy
[12:20:54][D][ntc:026]: ‘Smart Plug Temperature’ - Temperature: 45.4°C
[12:20:54][D][sensor:092]: ‘Smart Plug Temperature’: Sending state 45.42505 °C with 1 decimals of accuracy
[12:21:00][D][sensor:092]: ‘Smart Plug Active Power B’: Sending state -0.01299 W with 1 decimals of accuracy
[12:21:00][D][sensor:092]: ‘Smart Plug Active Power A’: Sending state 0.07792 W with 1 decimals of accuracy
[12:21:00][D][sensor:092]: ‘Smart Plug Current B’: Sending state 0.01773 A with 2 decimals of accuracy
[12:21:00][D][sensor:092]: ‘Smart Plug Current A’: Sending state 0.01773 A with 2 decimals of accuracy
[12:21:00][D][sensor:092]: ‘Smart Plug Voltage’: Sending state 123.33615 V with 1 decimals of accuracy
[12:21:04][D][adc:056]: ‘temp_analog_reading’: Got voltage=0.44V
[12:21:04][D][sensor:092]: ‘temp_analog_reading’: Sending state 0.43652 V with 2 decimals of accuracy
[12:21:04][D][resistance:037]: ‘temp_resistance_reading’ - Resistance 4878.2Ω
[12:21:04][D][sensor:092]: ‘temp_resistance_reading’: Sending state 4878.24854 Ω with 1 decimals of accuracy
[12:21:04][D][ntc:026]: ‘Smart Plug Temperature’ - Temperature: 45.3°C
[12:21:04][D][sensor:092]: ‘Smart Plug Temperature’: Sending state 45.34689 °C with 1 decimals of accuracy

Hope this helps.

Hi @edboston,

Thanks for trying the code!, and I’m glad I could help you. I have a question, the values shown and the consumption of each channel are correct?

Didn’t see a reply to this until today. I had to fudge the values around to get them to match another sensor for voltage. I also played around with the values for power and current to get them to match the values of the device (LED bulb) specs.

Just stumbled upon this thread… is anyone got any updates or improvements on the esphome code. I’m wanting to flash some shelly 2.5 and shelly 1.0 relays.

Does anyone have the code for shelly 1.0 to save me sometime?

Edit found this code for Shelly 1

esphome:
  name: relais_wohnzimmer_lampe
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "f"
  password: !secret wifipassword

# Enable logging
logger:

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

ota:
  password: !secret password


output:
  - platform: gpio
    pin: GPIO4
    id: gpio_4

light:
  - platform: binary
    name: "Lampe Wohnzimmer"
    output: gpio_4
    id: lightid
    
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
      #mode: INPUT_PULLUP
      #inverted: True
    name: "Schalter Wohnzimmer"
    on_state:
      - light.toggle: lightid
    internal: true

If you mean the 1PM this is one of mine:

sensor:
  - platform: hlw8012
    cf_pin: GPIO05
    cf1_pin: GPIO13
    sel_pin: GPIO14
    power:
      name: light_power
      unit_of_measurement: W
      id: light_power
      icon: mdi:flash-circle
      accuracy_decimals: 0
      filters:
      - lambda: if (x < (2 + 1)) return 0; else return (x - 1);
    update_interval: 3s

binary_sensor:
  - platform: gpio
    name: light_switch
    pin:
      number: GPIO4
      inverted: false
    on_press:
      - light.turn_on: light
    on_release:
      - light.turn_off: light

output:
  - platform: gpio
    id: relay1   
    pin:
      number: GPIO15

light:
  - platform: binary
    name: Light
    output: relay1
    id: light
    
status_led:
  pin:
    number: GPIO0
    inverted: True

Or the Shelly 1:

binary_sensor:
  - platform: gpio
    name: light_switch
    pin:
      number: GPIO5
      inverted: false
    on_press:
      - light.turn_on: light
    on_release:
      - light.turn_off: light

output:
  - platform: gpio
    id: relay 
    pin:
      number: GPIO4

light:
  - platform: binary
    name: Light
    output: relay
    id: light
1 Like

Or the Shelly 2.5:

output:
  - platform: gpio
    id: relay1
    pin:
      number: GPIO4
  - platform: gpio
    id: relay2
    pin:
      number: GPIO15

light:
  - platform: binary
    name: Bathroom Light
    output: relay1
    id: bathroom_light
      
fan:
  - platform: binary
    name: Bathroom Fan
    output: relay2
    id: bathroom_fan

binary_sensor:
  - platform: gpio
    name: bathroom_light_switch
    pin:
      number: GPIO13
      inverted: false
    on_press:
      - light.turn_on: bathroom_light
    on_release:
      - light.turn_off: bathroom_light

i2c:
  sda: GPIO12
  scl: GPIO14

sensor:
  - platform: ade7953
    voltage:
    name: Bathroom Light Fan Voltage
    current_a:
      name: Bathroom Fan Current
      filters:
        - lambda: if (x < 0.1) return 0; else return (x);
    current_b:
      name: Bathroom Light Current
      filters:
        - lambda: if (x < 0.1) return 0; else return (x);
    active_power_a:
      name: Bathroom Fan Power
      filters:
        - lambda: if (x < 1) return 0; else return (x);
    active_power_b:
      name: Bathroom Light Power
      filters:
        - multiply: -1
        - lambda: if (x < 1) return 0; else return (x);
    update_interval: 5s
1 Like

Hi Edward:
Could you share with me for ESPhome yaml of shelly2.5?
I can not pass valid yaml.
Tks
Leo Yang

Here is the configuration I am using to control my shop lights (inside and outside lights)

substitutions:
  device: shop_light
  Name: Shop Light
  SSID: !secret SSID_NoT
  SSID_PWD: !secret SSID_NoT_pwd
  IP_Addr: 192.168.30.32

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

wifi:
  ssid: ${SSID}
  password: ${SSID_PWD}

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${Name} Fallback Hotspot"
    password: !secret WIFIpwdFallback

#  manual_ip:
#    static_ip: ${IP_Addr}
#    gateway: 192.168.1.1
#    subnet: 255.255.255.0
#    dns1: 192.168.1.1

time:
  - platform: homeassistant
    id: homeassistant_time

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80
  
i2c:
  sda: GPIO12
  scl: GPIO14

sensor:
  - platform: ade7953
    voltage:
      name: ${Name} Voltage
    current_a:
      name: ${Name} Current B
    current_b:
      name: ${Name} Current A
    active_power_a:
      name: ${Name} Active Power B
      filters:
        - multiply: -1
    active_power_b:
      name: ${Name} Active Power A
      filters:
        - multiply: -1
    update_interval: 60s

  # NTC Temperature
  - platform: ntc
    sensor: temp_resistance_reading
    name: ${Name} Temperature
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    icon: "mdi:thermometer"
    calibration:
      b_constant: 3350
      reference_resistance: 10kOhm
      reference_temperature: 298.15K
  - 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: ${device}_relay1
    
  - platform: gpio
    pin: GPIO15
    id: ${device}_relay2

light:
  - platform: binary
    name: "${Name} Inside"
    output: ${device}_relay1
    id: ${device}_inside
    
  - platform: binary
    name: "${Name} Outside"
    output: ${device}_relay2
    id: ${device}_outside

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
      #mode: INPUT_PULLUP
      #inverted: True
    name: "${Name} Switch Inside"
    on_state:
      then:
        - light.toggle: ${device}_inside
    internal: true
    id: ${device}_switch_inside
    
  - platform: gpio
    pin:
      number: GPIO5
      #mode: INPUT_PULLUP
      #inverted: True
    name: "${Name} Switch Outside"
    on_state:
      then:
        - light.toggle: ${device}_outside
    internal: true
    id: ${device}_switch_outside
    

You may have to play around with some of the resistor settings to get the voltage/power values correct for your unit.

thanks a lot for sharing

What should you adjust for better voltage / power readings? Today I flashed my shelly 2.5 to ESPHome but the power sensors show very strange values.

On the Power B entity, I’ve a light of 50W …

I had partly the same problem. Only that the value was negative, I did not have the value multiplied by 10.

To solve my problem I had to comment out the filter on active_power_a (which is for Active Power B in Home Assistant)

sensor:
  - platform: ade7953
    voltage:
      name: ${devicename} Voltage
    current_a:
      name: ${devicename} Current B
    current_b:
      name: ${devicename} Current A
    active_power_a:
      name: ${devicename} Active Power B
#      filters:
#        - multiply: -1
    active_power_b:
      name: ${devicename} Active Power A
      filters:
        - multiply: -1
    update_interval: 60s

I suggest you try with this code and see if that solves your issue. Do a test with different known loads to confirm.

sensor:
  - platform: ade7953
    voltage:
      name: ${devicename} Voltage
    current_a:
      name: ${devicename} Current B
    current_b:
      name: ${devicename} Current A
    active_power_a:
      name: ${devicename} Active Power B
      # Multiply by positive 0.1 to try to correct wrong values
      filters:
        - multiply: 0.1
    active_power_b:
      name: ${devicename} Active Power A
      filters:
        - multiply: -1
    update_interval: 60s