Code works when connected via FTDI, but not when connected to main power?

Hi,

I have a shelly 1 mini gen3 running the following yaml

esphome:
  name: "shelly-1-mini-gen3"
  friendly_name: "Shelly 1 Mini Gen3"

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

wifi:
  ap:

logger:

api:

ota:
  - platform: esphome
  - platform: web_server

time:
  - platform: homeassistant

captive_portal:

sensor:
  - platform: ntc
    sensor: temp_resistance_reading
    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: temp_resistance_reading
    sensor: temp_analog_reading
    configuration: DOWNSTREAM
    resistor: 10kOhm
  - platform: adc
    id: temp_analog_reading
    pin: GPIO3
    attenuation: 12db

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

switch:
  - platform: output
    id: "relay"
    name: "Relay"
    output: "relay_output"

binary_sensor:
  - platform: gpio
    name: "Switch"
    pin: 10
    on_press:
      then:
        - switch.toggle: "relay"
    filters:
      - delayed_on_off: 50ms

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

status_led:
  pin:
    number: 0
    inverted: true

It works fine when connected via ftdi (shelly—ftdi–usb–laptop). I see the AP and I can connect to it.

But when I connect it to mains power the LED starts blinking rapidly and the AP isn’t being connected.

Is there any way I can debug this? My understanding is that I can’t read the serial output when the shelly is connected to mains.

I can’t see any wifi details.

You don’t necessarily need ssid details in config, but I would add them if it was me.

Do the logs say its connecting to wifi when plugged into USB? If not just add the wifi details.

Your understanding can save your life.
Shelly logic gnd is typically bonded to mains live.

1 Like

I have removed some of the lines in hopes of making it easier to see the problem:

esphome:
  name: "shelly-1-mini-gen3"
  friendly_name: "Shelly 1 Mini Gen3"

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

wifi:
  ap:

logger:

api:

ota:
  - platform: esphome

time:
  - platform: homeassistant

captive_portal:



status_led:
  pin:
    number: 0
    inverted: true

With this code the shelly creates an AP and I can use the captive portal to add the shelly to my wifi, but only when the connected via FTDI.

When I connect the shelly via mains the led flashes very quickly and no AP is created.

@Hellis81 , @Arh Shouldn’t the esp create an AP even when it is powered by mains?

It should, but it takes a while.

Does it start flashing quickly right away or first slowly?

It flashes quickly (and continuously) straight away, but only when connected to mains.

It works when connected to usb (and flashes slowly), but as @Hellis81 points out, it takes a while.

I’ve cut the yaml down to this, showing the same issue

esphome:
  name: "shelly-1-mini-gen3"
  friendly_name: "Shelly 1 Mini Gen3"

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


status_led:
  pin:
    number: 0
    inverted: true

Is there any way to read serial output safely while it is connected to mains?

Battery powered laptop with plastic body is relatively safe.
Completely safe is opto-isolated usb-serial converter.
Just don’t touch the converter when powered from mains. And remember not to connect shelly 3.3V line.
https://www.ebay.com/itm/203731465896

Did you try without status_led?

This sounds dangerous. It’s not worth risking your life over.

That’s a great idea, thank you!

I’ll get one and give it a try.

Just to be sure: I need to connect rx, tx and gnd from the shelly to the uart, right?

Regarding the status_led: if I remove that I’ll have no way of knowing if there is an error? Or do you mean remove the status_led and add wifi back?

Is it worth the trouble, maybe your shelly has some hw-problem? You understand that there will be mains live on that converter?

Yes.

No-way. The case is just so weird, If that status_led is blinking by esphome, it means that esphome is running. Since it doesn’t have any configurations, what could give an error state that doesn’t exist while usb powered?
Just to exclude the possibility that the led is blinking by some boot loop, not from status_led…

ps. If you decide to go with optoisolated converter, battery powered laptop would still be good option. There’s never guarantee that chinese converter is properly made.

I’d rather not use mains either, that’s more of a last resort thing.

I removed status_led but the blinking persists.

blinking.mp4 [optimize output image]

Sorry about the quality, getting it below 3MB wasn’t easy.

Is there maybe some residual shelly programming on the chip?

This seems to be the closest match, but I have no idea what to do about it, if it even is that.

My guess would be power issue. If there’s no stable 3.3V rail Esp could go in endless boot-reset loop.

But you showed ESP-Home yaml. IF it has been flashed with ESP-Home then nothing on the Shelly page will help you. It will only confuse you.

Are you sure you flashed the device?

I’ll try a different shelly 1 mini and see hot it goes, thanks!

@Hellis81, yes, I am sure I have flashed the shelly with esphome. Otherwise it wouldn’t show an AP when powered via USB.

A shelly with stock firmware will also create an AP when it’s not connected to a network.
What is the name of the AP?

If I remember correctly it was shelly-1-mini-gen3 when flashed with the yaml above, or esphome-XXXX when flashing via web.esphome.io

So, it pains me say this, but it seems to have been a hardware issue. Bought a new mini, flashed my config. Success on first try…

I spent 2 weeks on this, but I am happy it is over. THANK YOU everybody who tried to help!