Do you have a working ESPhome config for Shelly 3gen 2PM?

I feel like I’m going insane while looking for an answer, which will probably be super simple.

I bought a couple of Shelly gen3 2PM relays and successfully flashed them with ESPhome. The problem is, there seems to be not a single working config file anywhere on the internet.

As all gen3 devices from Shelly, it’s running a esp-shelly-c38f chip, which apparently is pretty much the same thing as esp32-c3 (but with more memory).
When I flashed the initial sketch, I let ESPhome builder figure it out, which it did.

It gave me a esp32 header like this:

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: Arduino

Now, the sketch works, ESPhome is happy and connected, but where are all the darn GPIO connections? Where is the i2c bus? The relays?

I have the older Shelly 2PM, but that used a different processor - meaning the original config file does not work.

If you have a working one, could you please share it here with everyone?

You could start with this, try to find the right gpios from other forums if here doesn’t match.

I don’t have one working but I found some clues that might help you. The esphome devices page have the working code for a Shelly 1PM gen3 which is a start. And the Tasmota guys reverse engineered the 2PM gen3 and posted the template format, so you’d have to figured out what all those numbers map to in order to convert it to esphome code.

EDIT: ok that’s a lot of work converting the Tasmota template so, since I have a esp32-c3 tasmota device handy, I plugged in the template and here are the values which hopefully helps:

2 Likes

So tasmota has I2C and esphome uart connection on IO6/7?

Yes, the template implies that 2PM uses a different energy monitoring chip (ADE7953) with I2C instead of BL0952 with UART on the 1PM. Comparing the other pins with 1PM, they are almost all different except for the relay and switch (binary_sensor) 2. Again, I don’t have this module but at least one person on the Tasmota thread says it is working.

Makes sense!

Alright, I think I got it working, properly. All thanks to @peterxian and his screenshot from Tasmota. Honestly, I wouldn’t have been able to decode the Tasmota template format into anything usable. This one screenshot saved my a**, so a big thank you!

The final config file will be at the bottom, but there are some things I’m not quite sure about.
First of all, the energy monitoring chip is really ADE7953, meaning I took the ESPhome config from there.

The one thing bothering me a bit is the Use with Shelly 2.5 section of the article, where it states a GPIO16 must be used in order for the device not to overheat. I know, this is not a Shelly 2.5, but I tried anyway. I was given an error, stating that GPIO16 cannot be used, due to its conflicting function. Probably a different ESP chip so … no harm done?

The other thing I’m worried about is the adc platform for the temperature reading as the compiler says it’s deprecated. See threads here and here. Neither of those, however, make any contributions to how to solve the issue. As long as it compiles, I’ll leave it there, but if you have a solution, I’m all ears.

So anyway, here’s the final config file as well as the HA screenshot.
All sensors, relays and switches behave as expected. Hope this helps someone in the future, or can be included in the ESPhome documentation.

esphome:
  name: 1p-jidelna-vypinac-2
  friendly_name: 1P Jídelna Vypínač 2

esp32:
  board: esp32-c3-devkitm-1
  flash_size: 8MB
  framework:
    type: esp-idf
    version: recommended
    sdkconfig_options:
      COMPILER_OPTIMIZATION_SIZE: y

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxxxxxxxxxxx"

ota:
  - platform: esphome
    password: "xxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "1P-Jidelna-Vypinac-2"
    password: "xxxxxxxxxxx"

captive_portal:

i2c:
  sda: GPIO6
  scl: GPIO7

sensor:
  - platform: ade7953_i2c
    irq_pin: GPIO1
    voltage:
      name: "Voltage"
      id: voltage
      icon: mdi:alpha-v-circle-outline
      device_class: voltage
    frequency:
      name: "Frequency"
      id: frequency
      accuracy_decimals: 2
      icon: mdi:cosine-wave
      device_class: frequency
    current_a:
      name: "Current A"
      id: currenta
      icon: mdi:alpha-a-circle-outline
      device_class: current
    current_b:
      name: "Current B"
      id: currentb
      icon: mdi:alpha-a-circle-outline
      device_class: current
    active_power_a:
      name: "Power A"
      id: powera
      icon: mdi:power
      device_class: power
      filters:
        - multiply: -1
    active_power_b:
      name: "Power b"
      id: powerb
      icon: mdi:power
      device_class: power
      filters:
        - multiply: -1
    update_interval: 5s
    

  # NTC Temperature
  - platform: ntc
    sensor: temp_resistance_reading
    name: "Temperature"
    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: 4



status_led:
  pin:
    number: 2
    inverted: true

output:
  - platform: gpio
    id: "relay_output1"
    pin: 5

  - platform: gpio
    id: "relay_output2"
    pin: 3

switch:
  - platform: output
    id: "relay1"
    name: "Relay1"
    output: "relay_output1"

  - platform: output
    id: "relay2"
    name: "Relay2"
    output: "relay_output2"

binary_sensor:
  - platform: gpio
    name: "Switch 1"
    pin: 18
    filters:
      - delayed_on_off: 50ms

  - platform: gpio
    name: "Switch 2"
    pin: 10
    filters:
      - delayed_on_off: 50ms

  - platform: gpio
    name: "Button"
    pin:
      number: 19
      inverted: yes
      mode:
        input: true
        pullup: true

EDIT: Updated the pins to match properly. Device output and switch #1 correspond with values 1/A and #2 with 2/B.

And thanks to you, @Karosm. I did start with the 1PM as a base. I do have another gen3 mini after all so it should’ve been obvious to start from this position.

You’re welcome.
I add a link here for others swimming in these waters. If you fluently read scripts, these might give some useful information.