Shelly 1PM?

Here is a sample Shelly 1PM entities list:


As you can see, current or voltage are not available.

I flashed shelly1pm with sonoff tasmota.i think it works fine.

I have connected CF1 to GPIO14 and SEL to GPIO12.
What would be the correct configuration? I think mA may have started working but not voltage…

@alferboy I have since replaced my 1pm’s with 2.5’s, which have a different sensor. So I am not setup to test this, but referring to the esphome docs it appears my originally posted config above may be incorrect… Try using the config posted on the info page instead:

sensor:
  - platform: hlw8012
    sel_pin: 5
    cf_pin: 14
    cf1_pin: 13
    current:
      name: "HLW8012 Current"
    voltage:
      name: "HLW8012 Voltage"
    power:
      name: "HLW8012 Power"
    energy:
      name: "HLW8012 Energy"
    update_interval: 60s

Also note at the bottom of the page there is a section about a “Permanent SEL Pin” hardware variant, which only has measurement mode available (likely power only). I suppose if you have a 1pm that has the pullup, you could find out how to remove it from the board to allow all 3 measurement modes.

@truglodite,

That was my base to add current and voltage, but according to the pins used as in https://github.com/arendst/Tasmota/issues/5716 (GPIO12 and GPIO14). There is no pull-up a.
I’ve connected those wires but it seems maybe something’s mixed up on the voltage/current (they seem maybe “swapped”).

With a 4w led bulb I was getting:

[19:32:32][D][hlw8012:063]: Got power=29.0W, current=21.7A
[19:32:42][D][hlw8012:063]: Got power=29.0W, current=21.7A
[19:33:02][D][hlw8012:071]: Got power=27.9W, voltage=1.5V
[19:33:12][D][hlw8012:071]: Got power=29.0W, voltage=1.6V
[19:33:32][D][hlw8012:063]: Got power=29.0W, current=21.7A
[19:33:42][D][hlw8012:063]: Got power=29.0W, current=21.7A
[19:34:02][D][hlw8012:071]: Got power=29.0W, voltage=1.6V
[19:34:12][D][hlw8012:071]: Got power=29.0W, voltage=1.5V
[19:34:32][D][hlw8012:063]: Got power=27.9W, current=21.8A

I changed the voltage divider so that voltage would go to around 230V and got (same wiring - check the power increase):

[19:35:22][D][hlw8012:071]: Got power=4282.2W, voltage=238.1V
[19:35:32][D][hlw8012:071]: Got power=4440.8W, voltage=231.8V
[19:35:52][D][hlw8012:063]: Got power=4282.2W, current=21.9A
[19:36:02][D][hlw8012:063]: Got power=4440.8W, current=21.9A
[19:36:22][D][hlw8012:071]: Got power=4440.8W, voltage=231.8V
[19:36:32][D][hlw8012:071]: Got power=4440.8W, voltage=231.8V
[19:36:52][D][hlw8012:063]: Got power=4440.8W, current=21.9A
[19:37:02][D][hlw8012:063]: Got power=4440.8W, current=21.9A
[19:37:22][D][hlw8012:071]: Got power=4282.2W, voltage=231.8V
[19:37:32][D][hlw8012:071]: Got power=4440.8W, voltage=238.1V
[19:37:52][D][hlw8012:063]: Got power=4282.2W, current=21.9A
[19:38:02][D][hlw8012:063]: Got power=4440.8W, current=21.9A
[19:38:22][D][hlw8012:071]: Got power=0.0W, voltage=75.2V
[19:38:32][D][hlw8012:071]: Got power=475.8W, voltage=87.7V
[19:38:52][D][hlw8012:063]: Got power=317.2W, current=21.7A
[19:39:02][D][hlw8012:063]: Got power=317.2W, current=21.7A
[19:39:22][D][hlw8012:071]: Got power=0.0W, voltage=81.5V
[19:39:32][D][hlw8012:071]: Got power=317.2W, voltage=68.9V
[19:39:52][D][hlw8012:063]: Got power=0.0W, current=21.7A
[19:40:02][D][hlw8012:063]: Got power=317.2W, current=21.6A
[19:40:22][D][hlw8012:071]: Got power=317.2W, voltage=87.7V
[19:40:32][D][hlw8012:071]: Got power=0.0W, voltage=75.2V
[19:40:52][D][hlw8012:063]: Got power=317.2W, current=21.7A

When voltage is belows 100v is when I turn off the relay. Yet current is always fixed, leading me to believe that they are somehow exchanged. Perhaps the sel pin needs invertion? very odd…

Reading that, my understanding is that the 1pm has some disconnected pins. It looks like Vorta came up with a hack that requires soldering 2 wires on the esp chip. That could be translated to esphome configs easily, but would still require the soldering.

Now, the “proof”:
Consider the “sent watts” as correct (they are pretty close).
Look at when I change the 4w bulb for a 2000w heater…
Takes a few seconds for the value to raise but when it does the “current” stays the same, and the “voltage” increases.
I think the “sel” pin needs inversion. I see no option for that…

[19:57:09][D][sensor:092]: 'Test Shelly1PM Current': Sending state 21.65142 mA with 2 decimals of accuracy
[19:57:09][D][sensor:092]: 'Test Shelly1PM Power': Sending state 5.06800 W with 0 decimals of accuracy
[19:57:09][D][sensor:092]: 'shelly1pm_test Energy': Sending state 0.54017 E with 1 decimals of accuracy
[19:57:11][D][sensor:092]: 'Test Shelly1PM WiFi Signal': Sending state -67.00000 dB with 0 decimals of accuracy
[19:57:14][D][hlw8012:063]: Got power=29.0W, current=21.6A
[19:57:14][D][sensor:092]: 'Test Shelly1PM Current': Sending state 21.60797 mA with 2 decimals of accuracy
[19:57:14][D][sensor:092]: 'Test Shelly1PM Power': Sending state 4.69646 W with 0 decimals of accuracy
[19:57:14][D][sensor:092]: 'shelly1pm_test Energy': Sending state 0.58039 E with 1 decimals of accuracy
[19:57:19][D][sensor:092]: 'Test Shelly1PM Power': Sending state 4.69646 W with 0 decimals of accuracy
[19:57:19][D][sensor:092]: 'shelly1pm_test Energy': Sending state 0.62062 E with 1 decimals of accuracy
[19:57:24][D][hlw8012:071]: Got power=29.0W, voltage=1.6V
[19:57:24][D][sensor:092]: 'shelly1pm_test Voltage': Sending state 1.55282 V with 1 decimals of accuracy
[19:57:24][D][sensor:092]: 'Test Shelly1PM Power': Sending state 4.69646 W with 0 decimals of accuracy
[19:57:24][D][sensor:092]: 'shelly1pm_test Energy': Sending state 0.66084 E with 1 decimals of accuracy
[19:57:29][D][hlw8012:071]: Got power=29.0W, voltage=1.6V
[19:57:29][D][sensor:092]: 'shelly1pm_test Voltage': Sending state 1.55282 V with 1 decimals of accuracy
[19:57:29][D][sensor:092]: 'Test Shelly1PM Power': Sending state 4.69646 W with 0 decimals of accuracy
[19:57:29][D][sensor:092]: 'shelly1pm_test Energy': Sending state 0.70107 E with 1 decimals of accuracy
[19:57:34][D][sensor:092]: 'Test Shelly1PM Power': Sending state 4.69646 W with 0 decimals of accuracy
[19:57:34][D][sensor:092]: 'shelly1pm_test Energy': Sending state 0.74129 E with 1 decimals of accuracy
[19:57:39][D][hlw8012:063]: Got power=24.8W, current=21.6A
[19:57:39][D][sensor:092]: 'Test Shelly1PM Current': Sending state 21.61666 mA with 2 decimals of accuracy
[19:57:39][D][sensor:092]: 'Test Shelly1PM Power': Sending state 3.95338 W with 0 decimals of accuracy
[19:57:39][D][sensor:092]: 'shelly1pm_test Energy': Sending state 0.77577 E with 1 decimals of accuracy
[19:57:41][D][adc:056]: 'shelly1pm_test_source_sensor': Got voltage=0.46V
[19:57:41][D][sensor:092]: 'shelly1pm_test_source_sensor': Sending state 0.45508 V with 2 decimals of accuracy
[19:57:41][D][resistance:037]: 'shelly1pm_test_resistance_sensor' - Resistance 5118.8Ω
[19:57:41][D][sensor:092]: 'shelly1pm_test_resistance_sensor': Sending state 5118.76953 Ω with 1 decimals of accuracy
[19:57:41][D][ntc:026]: 'Test Shelly1PM Temperature' - Temperature: 43.9°C
[19:57:41][D][sensor:092]: 'Test Shelly1PM Temperature': Sending state 43.89619 °C with 1 decimals of accuracy
[19:57:44][D][hlw8012:063]: Got power=0.0W, current=21.6A
[19:57:44][D][sensor:092]: 'Test Shelly1PM Current': Sending state 21.63694 mA with 2 decimals of accuracy
[19:57:44][D][sensor:092]: 'Test Shelly1PM Power': Sending state 0.00000 W with 0 decimals of accuracy
[19:57:44][D][sensor:092]: 'shelly1pm_test Energy': Sending state 0.77577 E with 1 decimals of accuracy
[19:57:49][D][sensor:092]: 'Test Shelly1PM Power': Sending state 0.00000 W with 0 decimals of accuracy
[19:57:49][D][sensor:092]: 'shelly1pm_test Energy': Sending state 0.77864 E with 1 decimals of accuracy
[19:57:55][D][hlw8012:071]: Got power=2465.9W, voltage=66.0V
[19:57:55][D][sensor:092]: 'shelly1pm_test Voltage': Sending state 66.03566 V with 1 decimals of accuracy
[19:57:55][D][sensor:092]: 'Test Shelly1PM Power': Sending state 442.37036 W with 0 decimals of accuracy
[19:57:55][D][sensor:092]: 'shelly1pm_test Energy': Sending state 4.20353 E with 1 decimals of accuracy
[19:58:00][D][hlw8012:071]: Got power=9973.3W, voltage=256.8V
[19:58:00][D][sensor:092]: 'shelly1pm_test Voltage': Sending state 256.78717 V with 1 decimals of accuracy
[19:58:00][D][sensor:092]: 'Test Shelly1PM Power': Sending state 1790.68835 W with 0 decimals of accuracy
[19:58:00][D][sensor:092]: 'shelly1pm_test Energy': Sending state 18.05535 E with 1 decimals of accuracy
[19:58:05][D][sensor:092]: 'Test Shelly1PM Power': Sending state 2245.45312 W with 0 decimals of accuracy
[19:58:05][D][sensor:092]: 'shelly1pm_test Energy': Sending state 35.42400 E with 1 decimals of accuracy
[19:58:10][D][hlw8012:063]: Got power=12383.4W, current=20.8A
[19:58:10][D][sensor:092]: 'Test Shelly1PM Current': Sending state 20.77366 mA with 2 decimals of accuracy
[19:58:10][D][sensor:092]: 'Test Shelly1PM Power': Sending state 2223.53223 W with 0 decimals of accuracy
[19:58:10][D][sensor:092]: 'shelly1pm_test Energy': Sending state 52.62313 E with 1 decimals of accuracy
[19:58:10][I][ota:046]: Boot seems successful, resetting boot loop counter.
[19:58:11][D][sensor:092]: 'Test Shelly1PM WiFi Signal': Sending state -69.00000 dB with 0 decimals of accuracy
[19:58:15][D][hlw8012:063]: Got power=12356.5W, current=20.8A
[19:58:15][D][sensor:092]: 'Test Shelly1PM Current': Sending state 20.79973 mA with 2 decimals of accuracy
[19:58:15][D][sensor:092]: 'Test Shelly1PM Power': Sending state 2218.70215 W with 0 decimals of accuracy
[19:58:15][D][sensor:092]: 'shelly1pm_test Energy': Sending state 69.78490 E with 1 decimals of accuracy
[19:58:20][D][sensor:092]: 'Test Shelly1PM Power': Sending state 2217.58765 W with 0 decimals of accuracy
[19:58:20][D][sensor:092]: 'shelly1pm_test Energy': Sending state 86.93806 E with 1 decimals of accuracy
[19:58:25][D][hlw8012:071]: Got power=12325.4W, voltage=314.2V
[19:58:25][D][sensor:092]: 'shelly1pm_test Voltage': Sending state 314.15973 V with 1 decimals of accuracy
[19:58:25][D][sensor:092]: 'Test Shelly1PM Power': Sending state 2213.12915 W with 0 decimals of accuracy
[19:58:25][D][sensor:092]: 'shelly1pm_test Energy': Sending state 104.05675 E with 1 decimals of accuracy
[19:58:29][D][hlw8012:071]: Got power=12329.6W, voltage=313.9V
[19:58:29][D][sensor:092]: 'shelly1pm_test Voltage': Sending state 313.91455 V with 1 decimals of accuracy
[19:58:29][D][sensor:092]: 'Test Shelly1PM Power': Sending state 2213.87231 W with 0 decimals of accuracy
[19:58:29][D][sensor:092]: 'shelly1pm_test Energy': Sending state 121.18116 E with 1 decimals of accuracy
[19:58:34][D][sensor:092]: 'Test Shelly1PM Power': Sending state 1804.80688 W with 0 decimals of accuracy
[19:58:34][D][sensor:092]: 'shelly1pm_test Energy': Sending state 135.14217 E with 1 decimals of accuracy
[19:58:39][D][hlw8012:063]: Got power=0.0W, current=21.9A
[19:58:39][D][sensor:092]: 'Test Shelly1PM Current': Sending state 21.85420 mA with 2 decimals of accuracy
[19:58:39][D][sensor:092]: 'Test Shelly1PM Power': Sending state 0.00000 W with 0 decimals of accuracy
[19:58:39][D][sensor:092]: 'shelly1pm_test Energy': Sending state 135.14217 E with 1 decimals of accuracy
[19:58:41][D][adc:056]: 'shelly1pm_test_source_sensor': Got voltage=0.37V
[19:58:41][D][sensor:092]: 'shelly1pm_test_source_sensor': Sending state 0.37207 V with 2 decimals of accuracy
[19:58:41][D][resistance:037]: 'shelly1pm_test_resistance_sensor' - Resistance 4066.4Ω
[19:58:41][D][sensor:092]: 'shelly1pm_test_resistance_sensor': Sending state 4066.44019 Ω with 1 decimals of accuracy
[19:58:41][D][ntc:026]: 'Test Shelly1PM Temperature' - Temperature: 51.0°C
[19:58:41][D][sensor:092]: 'Test Shelly1PM Temperature': Sending state 50.95559 °C with 1 decimals of accuracy
[19:58:44][D][hlw8012:063]: Got power=0.0W, current=21.9A
[19:58:44][D][sensor:092]: 'Test Shelly1PM Current': Sending state 21.89186 mA with 2 decimals of accuracy
[19:58:44][D][sensor:092]: 'Test Shelly1PM Power': Sending state 0.00000 W with 0 decimals of accuracy
[19:58:44][D][sensor:092]: 'shelly1pm_test Energy': Sending state 135.14217 E with 1 decimals of accuracy
[19:58:49][D][sensor:092]: 'Test Shelly1PM Power': Sending state 0.00000 W with 0 decimals of accuracy
[19:58:49][D][sensor:092]: 'shelly1pm_test Energy': Sending state 135.14217 E with 1 decimals of accuracy
[19:58:54][D][hlw8012:071]: Got power=0.0W, voltage=0.0V
[19:58:55][D][sensor:092]: 'shelly1pm_test Voltage': Sending state 0.00000 V with 1 decimals of accuracy
[19:58:55][D][sensor:092]: 'Test Shelly1PM Power': Sending state 0.00000 W with 0 decimals of accuracy
[19:58:55][D][sensor:092]: 'shelly1pm_test Energy': Sending state 135.14217 E with 1 decimals of accuracy
[19:58:59][D][hlw8012:071]: Got power=0.0W, voltage=0.0V
[19:58:59][D][sensor:092]: 'shelly1pm_test Voltage': Sending state 0.00000 V with 1 decimals of accuracy
[19:58:59][D][sensor:092]: 'Test Shelly1PM Power': Sending state 0.00000 W with 0 decimals of accuracy
[19:58:59][D][sensor:092]: 'shelly1pm_test Energy': Sending state 135.14217 E with 1 decimals of accuracy
[19:59:04][D][sensor:092]: 'Test Shelly1PM Power': Sending state 0.00000 W with 0 decimals of accuracy
[19:59:05][D][sensor:092]: 'shelly1pm_test Energy': Sending state 135.14217 E with 1 decimals of accuracy
[19:59:10][D][hlw8012:063]: Got power=0.0W, current=22.0A
[19:59:10][D][sensor:092]: 'Test Shelly1PM Current': Sending state 21.96139 mA with 2 decimals of accuracy
[19:59:10][D][sensor:092]: 'Test Shelly1PM Power': Sending state 0.00000 W with 0 decimals of accuracy
[19:59:10][D][sensor:092]: 'shelly1pm_test Energy': Sending state 135.14217 E with 1 decimals of accuracy
[19:59:11][D][sensor:092]: 'Test Shelly1PM WiFi Signal': Sending state -61.00000 dB with 0 decimals of accuracy

@truglodite:

I did that soldering, that’s the issue. I soldered the wires as suggested.

    cf1_pin: GPIO14
    sel_pin: GPIO12

And it does get current/voltage values.
Yet, they show up as you see, seemingly swapped.

Does anyone know if this fire hazard issue related to the ade7953 in the shelly 2.5 Shelly 2.5 + ESPHome: potential fire hazard + fix | Savjee.be is all present in the Shelly 1PM and if so if the same fix applies?

To my understanding they have different chips in them. Also my ESPHome flashed shelly 1PM and same with original Shelly FW seem to be running at the same temperature (~50 degrees).

Are you having heat issues with 1PM?

Awesome, like that and while I was able to find a working config here, I always start looking at https://www.esphome-devices.com/ first.
Now I have two questions, is esphome-devices not good to start over or why do these configs not end up on that website?
Is there anything better to get things rolling with esphome and a “working” config?

I am thinking about Tasmota Device Templates Repository - Templates for Tasmota which is THE go to site for getting devices up and running with Tasmota. Lots of people buy devices because the show up there with a configuration.

Thanks for the 1PM config anyhow.

Because no one takes the time to do so… I did a few and it takes some time to do so.

Here’s my config I compiled from a few sources I found here and there. What’s added:

  • restart switch
  • wifi signal sensor
  • polynomial calibration which works for me much better than linear calibration
  • total daily energy sensor
  • overheat protection with notification
# Shelly 1PM, compiled from:
#   - https://community.home-assistant.io/t/shelly-1pm/118929/
#   - https://gitmemory.com/issue/jonathanadams/esphome-configs/96/652744282
#   - https://www.esphome-devices.com/devices/Shelly-1
#   - https://www.esphome-devices.com/devices/Shelly-25/

substitutions:
  name: "shelly1pm-vypinac-sklep-technicka"
  name_id: "vypinac_sklep_technicka"
  friendly_name: "Vypinac sklep technicka"
  
  max_temp: "70.0"

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

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

captive_portal:

# Enable logging
logger:

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

ota:
  password: !secret password

time:
  - platform: homeassistant
    id: homeassistant_time

switch:
  - platform: gpio
    name: "${friendly_name} Relay"
    icon: "mdi:electric-switch"
    pin: GPIO15
    id: relay
    restore_mode: restore_default_off
    
  - platform: restart
    name: "${friendly_name} Restart"
    
sensor:
  - platform: wifi_signal
    name: "${friendly_name} WiFi Signal"
    update_interval: 60s
    
  - platform: hlw8012
    cf_pin: GPIO05
    cf1_pin: GPIO13 # not used because it is not available on the 1PM but it is needed to compile
    sel_pin: GPIO14 # not used because it is not available on the 1PM but it is needed to compile
    power:
      name: "${friendly_name} Power"
      unit_of_measurement: W
      id: "${name_id}_power"
      icon: mdi:flash-circle
      accuracy_decimals: 1
      filters:
      # Reading from the ESPHome log (from the device) -> actual measured value (different combinations of bulbs on 3 bulb chandelier)
      # Polynomial calibration works best in my case. I created an excel graph with polynomial trend line in Excel based on the datapoints bellow and degree of 5 or 6 works best.
      - calibrate_polynomial:
          degree: 5
          datapoints:
            - 27.9 -> 5.0
            - 43.4 -> 7.0
            - 55.9 -> 10.0
            - 65.2 -> 11.0
            - 82.7 -> 15.0
            - 128.3 -> 21.0
            - 212 -> 35.0
            - 382.7 -> 60.0
            - 451 -> 75.0
            - 768.5 -> 120.0
            - 937.1 -> 150.0
            - 1217.4 -> 195.0
            - 1410.9 -> 225.0
      # 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);
    update_interval: 10s
    
  - platform: total_daily_energy
    name: "${friendly_name} Total Daily Energy"
    power_id: "${name_id}_power"
    filters:
      # Multiplication factor from W to kW is 0.001
      - multiply: 0.001
    unit_of_measurement: kW
    
  # NTC Temperature
  - platform: ntc
    sensor: "${name_id}_resistance_sensor"
    name: "${friendly_name} Temperature"
    id: "${name_id}_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: "${name_id}_resistance_sensor"
    sensor: "${name_id}_source_sensor"
    configuration: DOWNSTREAM
    resistor: 32kOhm
  - platform: adc
    id: "${name_id}_source_sensor"
    pin: A0
    update_interval: 30s

binary_sensor:
  - platform: status
    name: "${friendly_name} Status"
  
  # Binary sensor for the button press
  - platform: gpio
    name: "${friendly_name} Input"
    pin:
      number: GPIO4
    on_state:
      - switch.toggle: relay
    #on_press:
    #  - switch.turn_on: relay
    #on_release:
    #  - switch.turn_off: relay

status_led:
  pin: GPIO0
  #inverted: true

# output:
  # # Relay state led
  # - platform: esp8266_pwm
    # id: state_led
    # pin:
      # number: GPIO00
      # inverted: true

# Overheat Protection
interval:
  - interval: 100ms
    then:
      if:
        condition:
          and:
            - sensor.in_range:
                id: "${name_id}_temperature"
                above: ${max_temp}
            - switch.is_on: relay
        then:
          - switch.turn_off: relay
          - homeassistant.service:
              service: persistent_notification.create
              data:
                title: Message from ${friendly_name}
              data_template:
                message: Switch turned off because temperature exceeded ${max_temp} °C.

I’m sorry for not posting the config there, but it’s not really easy to do so and I can’t easily figure it out with time limitations on my hands.

9 Likes

Awesome, thanks for sharing your findings regarding calibration! I suspected linear was going to be a bit off… kinda surprised it lines up with 5th/6th order, but then I know nothing about the sensor.

Is anyone using this with a light switch and have it working where the relay in the shelly “follows” the switch? For example, if you turn the light or whatever it is controlling on using HA, obviously the physical switch would still be in the off position. Then if you flip the physical switch to the on position, nothing would happen until you move the physical switch to the off position. I know it might seem petty, but I like for my smart relays to follow my physical switches. I don’t want the physical switch to just be a toggle.

I tried to convert one of my shelly1PM to esphome starting with mgos2tasmota OTA. It was powered with 230v. Looking at the log, it downloaded the tasmota firmware. Then it went offline and never came back. It took it out and have been trying to get a serial connection with no luck. I use a PL2303 USB to serial thing, booting with GPIO0 grounded and not. I’ve tried TX/RX both ways using 5 different softwares with no luck. Could the ESP chip have been fried because of the alternative firmware?

EDIT: I tried esptool, and for some reason it managed to connect and flash. Problem solved.

Has anyone succeeded with the temperature sensor addon? I tried GitHub - persuader72/esphome-components: Custom esphome components but it won’t work.

This part should solve your problem. Just comment out the toggle part and uncomment the rest. Let me know if it works. Thanks!

Hi I just wanted to bump this thread.

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.

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"

When doing polynomial calibration, it’s worth checking the result with a spreadsheet. I don’t know if they use the same curve fitting algorithms as esphome, but it might receal some surprising results.