Shelly 1PM?

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.