Shelly 1PM?

Hello,

anyone already flashed a Shelly 1PM device with ESPhome?
I ordered 1Pm because of additional security features (overheat, overload protection).

I plan to use it for my garden irrigation (just switch on/off) by mqtt. After shelly device, placing a 240V -> 12v adapter -> switch on/off a magnetic valve.

Any experience would be fine - or is this devcie same as the Shelly1 ?

Thanks in advance,
Ralf

I don’t own one, but from my understanding, it’s the same as a Shelly 1, but with the energy monitoring features of the shelly 2. So I imagine a combination of those two bits should work.

Thanks for teh note, will try and give feedback.

/ Ralf

Why flashing with ESPHome? There is nice custom component to integrate Shelly (all types) with HA: https://github.com/StyraHem/ShellyForHASS
I hope it will be integrated someday with HA :slight_smile:

1 Like

Thanks for this tipp! Didn‘t saw it Till now. Will try.

/Ralf

I don’t have any Shelly products, but if I did I’d flash them with ESPHome even though there’s a custom component that can talk to them locally. I don’t want these devices talking to the cloud at all. Plus I’d bet that ESPHome is a lot more customizable.

Don’t get me wrong, I really like ESPHome. And I have a lot of devices using this.
I also have some shellys flashed with ESPHome, and it is really customizable.

But If you don’t have ESPHome installed yet, or don’t know how to flash devices. This sounds like a nice solution.
Also for the shelly roller shutter looks like it is better than the ESPHome cover version. I have a shelly 2.5 for my roller shutter to test, but didn’t try ESPHome on it. The shelly has autocalibration based on energy usage I think?

About the talking to the cloud: that’s what a firewall is for. :wink:

@Ralf Did you have any luck with this?

Hello

no, i changed to a Sonoff device.
Once having time i will try again.

/ Ralf

Hello!
Does anybody know if it is possible to monitor power consumption with shelly 1PM in Homeassistant in any way? Regardless of firmware installed?

Thank you
Z

I’m thinking of getting some Shelly’s. Flashing looks to be no problem, but doesn’t the Shelly firmware have the possibility set it to MQTT mode that disables the Cloud functionality? If that’s the case there is no need to flash it with custom firmware.

Have anyone tested it with MQTT? Is it completely off the cloud when running it on MQTT?

Yes, in order to use MQTT it HAS to be disconnected from Shelly Cloud. That is how i am using 4 shellys, and they work great. There is a ton of functionality with the stock shelly firmware so i have not had the need to flash them.

1 Like

Just wanted to share my esphome file. It’s calibrated by me according to frenck’s guide… It may need some calibration for you. I haven’t tried if the button sensor is working yet and I just remembered that it also got a temperature sensor. I will update with a fix for this later…

# From Tasmota template
# "NAME":"Shelly 1PM","GPIO":[0: Led1i,0,0,0,4: D_SENSOR_SWITCH,5: BL0937 CF,0,0,0,0,0,15: Relay1,0],"FLAG":2,"BASE":18}

substitutions:
  plug_name: "shelly1pm"

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

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  domain: !secret domain

  manual_ip:
    static_ip: 10.222.50.198
    gateway: 10.222.50.1
    subnet: 255.255.255.0
    dns1: 10.222.50.1
    
# Enable logging
logger:
  level: VERBOSE

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

ota:
  password: !secret password
  
time:
  - platform: homeassistant
    id: homeassistant_time

switch:
  - platform: gpio
    name: "${plug_name}_switch"
    icon: "mdi:power-socket-eu"
    pin: GPIO15
    id: relay

sensor:
  - 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: "${plug_name}_power"
      unit_of_measurement: W
      id: "${plug_name}_power"
      icon: mdi:flash-circle
      accuracy_decimals: 0
      filters:
      # Map from sensor -> measured value
      - calibrate_linear:
          - 0.0 -> 1.0
          - 110.33186 -> 20.62
          - 131.01909 -> 24.32
          - 341.33920 -> 62.08
          - 5561.41553 -> 1000.0
          - 2975.51221 -> 535.7
          - 9612.66309 -> 1720.0
          - 14891.35352 -> 2679.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: 3s

binary_sensor:
  # Binary sensor for the button press
  - platform: gpio
    name: button
    pin:
      number: GPIO4
      inverted: true
    on_press:
      - switch.toggle: relay

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

Thanks a lot @Anders_Karlstrom!
Your config helped me with my shelly-1pm.

How did you find the GPIO15?
Over at esphome they just name " GPIO4" for the relay.

Any progress regarding the temperature sensor? Would be awesome to have!

Regards!
Brandon

I looked at the tasmota config.
The temperature sensor were a bit more complicated. I think i will need to write some logic and push it to esphome to make it work. I don’t really know when I got time for it. I will make a feature request for it, maybe someone else got time :slight_smile:

1 Like

watching :nerd_face:

Thermistor seems to be working here. I predicted the componentry would be similar to the Shelly 2.5, so I copied the thermistor part from my shelly 2.5 config and it seems to also work for the shelly 1pm. Luckily the ESP8266 doesn’t have many analog inputs (one to be exact), and it’s likely manufacturers have saved by using the same components for the thermistor divider on all their products. So it was an easy guess. I haven’t frozen it or caught it on fire, or otherwise calibrated it, but it seems reasonable hovering around 37C after warming up on my desk, and jumping up when I heat it with a blow dryer.

I haven’t hooked it up to mains voltage to calibrate it yet, and the power reading seems to be floating around 37-40W (this could be from floating nodes in the circuit due to not being wired up). The LED is correct, OTA works (didn’t with the PWM led config above), and not sure if the relay works until I wire it up. If it does, the relay is super duper quiet because I can’t hear it click when I toggle it (at least compared to my Shelly 2.5 relay’s).

substitutions:
  name: "garage_lights"
  friendly_name: "Garage Lights"

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

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

# Enable logging
logger:

api:
  password: !secret garage_lights_password

ota:
  password: !secret ota_password

switch:
  - platform: gpio
    name: "${friendly_name} Switch"
    icon: "mdi:power-socket-us"
    pin: GPIO15
    id: relay
    
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}_power"
      icon: mdi:flash-circle
      accuracy_decimals: 0
      filters:
      # 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
    
  # NTC Temperature
  - platform: ntc
    sensor: ${name}_resistance_sensor
    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
  - platform: resistance
    id: ${name}_resistance_sensor
    sensor: ${name}_source_sensor
    configuration: DOWNSTREAM
    resistor: 32kOhm
  - platform: adc
    id: ${name}_source_sensor
    pin: A0
    update_interval: 10s

binary_sensor:
  - platform: status
    name: "${friendly_name} Status"
  # Binary sensor for the button press
  - platform: gpio
    name: "${friendly_name} Button"
    pin:
      number: GPIO4
      inverted: true

status_led:
  pin: GPIO0

Got it wired up today and all is working well; current, voltage, relay, input switch, and temperature!

The calibration of the power sensor is way off, showing 700W for what should be a <100W or so load. I’ll be calibrating this with my diy ‘killer watts’ meter, but otherwise consider this a working shelly 1pm config. Regardless, the sensor is responding properly, so calibration is all that is needed here.

I included some small automations to make the existing toggle style wall switch behave like a standard wall switch (up=on, down=off). I also have node red doing some additional automations based on motion, luminance, and switch position, but that’s out of the scope of this post. Hope this helps someone down the line!

# Shelly 1pm Example#############################

substitutions:
  name: "garage_lights"
  friendly_name: "Garage Lights"

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

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

# Enable logging
logger:

api:
  password: !secret garage_lights_password

ota:
  password: !secret ota_password

switch:
  - platform: gpio
    name: "${friendly_name} Relay"
    icon: "mdi:power-socket-us"
    pin: GPIO15
    id: relay
    
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}_power"
      icon: mdi:flash-circle
      accuracy_decimals: 0
      filters:
      #Reading -> actual
      - calibrate_linear:
          - 2.5 -> 0.16
          - 747.0 -> 125.0
          - 1409.0 -> 237.0
          - 2663.0 -> 444.0
          - 8600.0 -> 1390.0
      - lambda: if (x <= 6.0) return 0; else return (x - 6);
    update_interval: 10s
    
  # NTC Temperature
  - platform: ntc
    sensor: ${name}_resistance_sensor
    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
  - platform: resistance
    id: ${name}_resistance_sensor
    sensor: ${name}_source_sensor
    configuration: DOWNSTREAM
    resistor: 32kOhm
  - platform: adc
    id: ${name}_source_sensor
    pin: A0
    update_interval: 10s

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

[edit: Got my calibration done… added it to this config. Incidentally, that’s the farthest off from calibration I’ve ever seen a sensor… not that it means anything, but usually output values are within a few 10% before calibrating, not ~800% off as in this case. Either way, a linear calibration does look valid for the sensor (roughly the same 8x factor across the range).]

1 Like

@truglodite Thanks for your config. Finally able to calibrate the temperature sensor. I tried it without the ntc platform which wasn’t that clever :stuck_out_tongue:

Thats because of the relativly high shunt resistor value compared to the Sonoff’s (which are used for the default values in ESPHome). Higher Shunt Resistor value means higher accuracy when measuring the power consumtion but also higher heat dissipation which is why the shelly overheat when having >1000W for longer time. (Didn’t verify myself but read it)

I tried to implement a logic to turn off the relay when a cricical temperatur was reached. Not perfect since it still turns on the switch for at least 100ms. Maybe I can do something better with template switches and lambdas.

# Overheat Protection
interval:
  - interval: 100ms
    then:
      if:
        condition:
          and:
            - sensor.in_range:
                id: temperature
                above: 60.0
            - switch.is_on: relay
        then:
          - switch.turn_off: relay