Shelly Plus Plug S - ESPHOME

Hi,

I have Shelly Plus Plug S for which I can’t find example for configuration code and how to flash it on site www.esphome-devices.com . It is new Shelly device which have RGB LED ring…
Can someone help me integrate it into ESPHOME to get everything work like on older devices(Shelly Plug S)?

Im open it and there is no pins to use flashtool on it(I have VoltLink CP2102N):

Product link:
https://www.shelly.cloud/en/products/shop/shelly-plus-plug-s

Thanks for help and any sugestions how to flash it with ESPHOME …

4 Likes

This is working fine:

Then you can upload esphome

Hi @mebrotus Im try this on Shelly Plus 1PM few weeks/months ago and it didn’t work so Im flash it with VoltLink …
Im try now update Plus Plug S to Tasmota and work… Now I have Tasmota on it and is detected as “ESP32-DevKit” and under information I see Chip: ESP32-U4WDH-D rev.3 Im right now flash it with esphome.

Do you maybe know some example configuration which I can use to get basic things to work(power consumption, relay, led)? Something like:

1 Like

Right now Im figure out this configuration:

substitutions:
  device_name: "Shelly Plus Plug S"
  
esphome:
  name: shelly-plus-plug-s
  friendly_name: shelly-plus-plug-s

esp32:
  board: esp32doit-devkit-v1
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Shelly-Plus-Plug-S"
    password: "testTest123"

time:
  - platform: homeassistant

output:
  - platform: gpio
    id: "relay_output"
    pin: GPIO4

switch:
  - platform: output
    id: "relay"
    name: "${device_name} Relay"
    output: "relay_output"

binary_sensor:
  - platform: gpio
    name: "${device_name} Button"
    pin:
      number: GPIO9
      inverted: yes
      mode:
        input: true
        pullup: true
    on_press:
      then:
        - switch.toggle: "relay"
    filters:
      - delayed_on_off: 5ms
 

Button on Plug now toggle relay/output… I need to add temperature, LED, power, voltage…

These is some documentation for this one.

@bkbartk Im check this page. It has been my first thing to do but can’t find it on this site… Your link is for “Shelly Plug S” which is based on esp8285. I have “Shelly Plus Plug S” which is based on ESP32…

1 Like

Sorry. I missed the fact that the new device is based on esp32.

No problem…

After further investigation temperature sensor looks like is on GPIO33 so this will show temperature:

sensor:
  # Internal NTC Temperature sensor
  - platform: ntc
    sensor: temp_resistance_reading
    name: "${device_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: "80.0"
        then:
          - switch.turn_off: "relay"  
  - platform: resistance
    id: temp_resistance_reading
    sensor: temp_analog_reading
    configuration: DOWNSTREAM
    resistor: 10kOhm
  - platform: adc
    id: temp_analog_reading
    pin: GPIO33
    attenuation: 11db
    update_interval: 10s

@DejanBukovec : Thanks, this looks good. Do you already have the Power&Voltage Sensors working?

Hi,
Im sorry but no. These 3 things has been easy to find… If I will find info which chipset is used for monitoring voltage and current it will be easier… I currently don’t have to much time to research so if someone with more time and knowledge will do it will be great…

Hi Dejan, I’ve opened up one of my Shelly Plus Plug S devices to find out what the monitoring chipset is and I think it’s a BL0937. I’ve attached some more pictures. Unfortunately, my device didn’t survive :slight_smile: but I’ve got another one to tinker with. I’m also wondering what the prefixes C, R, D and U mean that can be seen on the board. Do they somehow map to GPIO pins?


1 Like

Some more photos.






1 Like

I didn’t want to destroy mine so Im open it only half way :slight_smile:

C = Capacitor
R = Resistor
D = Diode
U = Integrated circuit

It is BL0937 so is same as it used in Shelly Plus 1PM… Now I need to find pinout for this BL0937…
Thanks for destroying your and good hint what to look :slight_smile:

I think I’m kill my device :slight_smile: Im try to use GPIO16 and GPIO17 as CF & CF1 pin and device is now offline :neutral_face: and I can’t reflash it… It power on for second and turn relay on(last state) but then imediatelly turn off relay…

What made you pick those GPIO pins?

Im make list of all possible GPIO’s and remove already used ones. But looks like this 2 are used internaly by shelly for something…
Problem is that BL0937 is on other side of board and need to remove PCB to trace physical connections… Looks like now I can dissasemble plug by destroying plastic case and leave pcb undamaged and then I can trace connections…

For further research looks like when I set
CF = GPIO5
CF1 = GPIO10

I get in HA power usage 2,5W which can be ok but voltage and amperage has not show correct values. Also Im not sure if power has been correct because connected device can have consumption up to 12W(PSU is 12V 1A)…

Actually, using these I’ve got accurate readings now:

  - platform: hlw8012
    model: BL0937
    sel_pin:
      number: GPIO19
      inverted: true
    cf_pin: GPIO10
    cf1_pin: GPIO22
    current_resistor: ${current_res}
    voltage_divider: ${voltage_div}
    change_mode_every: 1
    update_interval: 5s
    current:
      id: current
      unit_of_measurement: A
      accuracy_decimals: 3
      internal: true
    voltage:
      id: voltage
      unit_of_measurement: V
      accuracy_decimals: 1
      internal: true
    power:
      name: "${channel_1} power"
      unit_of_measurement: W
      id: power
      icon: mdi:flash-outline
      on_value_range:
        - above: ${max_power}
          then:
            - switch.turn_off: relay
            - homeassistant.service:
                service: persistent_notification.create
                data:
                  title: Message from ${device_name}
                data_template:
                  message: Switch turned off because power exceeded ${max_power} W
substitutions:
  device_name: shelly-plus-plug-s-1
  friendly_name: shelly-plus-plug-s-1
  channel_1: Relay
  max_power: "1500" # 2000
  max_temp: "65.0" # 70.0
  # Higher value gives lower watt readout
  current_res: "0.001"
  # Lower value gives lower voltage readout
  voltage_div: "1830"

Now how would we go about and figure out how to control the LED ring? GPIO3 seems to react to a monochromatic light, but only fully on or off, and only at a certain percentage :confused:

1 Like

Im remove PCB from case without damage…
It for sure use ESP32-U4WDH and BL0937.
There is 4 LED’s. Im not sure if they are RGB or each have own color… Maybe they are driven by PWM …

Looks like U0TXD and U0RXD from chip is not exposed to any pins so reflashing my device looks like will not be possible…

Got it working here

 light:
      - platform: neopixelbus
        variant: 800KBPS
        method:
          type: esp32_rmt
          channel: 0
        pin: GPIO25
        num_leds: 2
        id: rgb_light1
  
      - platform: neopixelbus
        variant: 800KBPS
        method:
          type: esp32_rmt
          channel: 1
        pin: GPIO26
        num_leds: 2

But plug reboot from time to time. Don’t know why. Memory leak probably

1 Like

I’ve noticed that addressing the RGB leds too soon in the boot cycles causes the device to reboot or become unresponsive. It might be the same as your issue @mebrotus. Fortunately, flashing the device was still possible in those cases. I’ve added a safeguard around this and created a PR in the esphome devices repo. I’ve got two devices running this config as stable as can be.
Config for Shelly Plus Plug S by bobkersten · Pull Request #370 · esphome-devices/esphome-devices · GitHub

1 Like