As I found no real instructions on flashing the Shelly Plus 1 (not PM) with esphome I decided to write a small guide for everyone also being lost.
First of all i got these shellys just for visual reference:
There is unfortunately not OTA- flashing method (as of now:17.11.22) so dont just pop them into the wall for now.
What you need to flash:
- Shelly Plus 1 (obvioulsy)
- USB to UART Adapter (just google it ther are really cheap. I’ve got the CP2102 but others with 3,3V should work as well.
- Dupon Cables or matching pins sort of)
Connecting:
There is a UART Terminal on the back of the Shelly Plus 1 just flip. Be aware that the normal dupont cables won’t fit in. You could either buy a matching pin header (1.27 mm pitch 0.4 mm square pins) or like me just take the dirty way and push needles through the connector. And isolated them with some tape!
Not the most beautiful but it works
You need to connect the cables like so (RX and TX already transposed):
Credits to digiblur and his amazing breakdown of the shelly.
Check it out here: https://youtu.be/eLoOT3mXcMs?t=528
Connect the Cables like shown and also connect IO-0 to ground before connecting ur UART Adapter.
This boots the shelly into the bootloader and you are able to flash from there. The ground LED should briefly flicker two times and then stay on. If TX or RX are also flashing you are not in flashing mode.
After a few seconds you can the disconnect IO-0 from ground even if it does not make any difference if it stays connected I think.
Software prep:
Once connected. Check that you have installed the proper driver for your UART Bridge. Usually the manufacturers website helps. Just google it
Unfortunately flashing via the esphome Dashboard does not work because some library is missing (also state: 17.11.22) (edit: this is an ARM issue. Using a different machine to run HA might work. Thanks to @ddwdiot for pointing that out)
You need to install esphome on your local machine as described here: Installing ESPHome Manually — ESPHome
Generating Firmware:
Go back to your command line and generate the yaml.
type: esphome wizard your-shelly-name.yaml
Just follow the steps in the terminal output.
the device and board are esp32 and esp32doit-devkit-v1
Here is the long version:
After setting up the yaml find it on your device. (On my Mac it was under macintoshd/users/myusername)
Open it with a text editor and add the example yaml and change the passwords to your own.
Found here: Shelly Plus 1 | devices.esphome.io
Or just here:
substitutions:
device_name: "Shelly Plus 1"
# Higher value gives lower watt readout
current_res: "0.001"
# Lower value gives lower voltage readout
voltage_div: "1925"
esphome:
name: shelly-plus-1
platformio_options:
board_build.f_cpu: 160000000L
esp32:
board: esp32doit-devkit-v1
framework:
type: esp-idf
sdkconfig_options:
CONFIG_FREERTOS_UNICORE: y
CONFIG_ESP32_DEFAULT_CPU_FREQ_160: y
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ: "160"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Shelly Office Fallback Hotspot"
password: !secret ap_password
logger:
api:
password: !secret api_password
encryption:
key: !secret api_encryption_key
ota:
password: !secret ota_password
output:
- platform: gpio
id: "relay_output"
pin: GPIO26
switch:
- platform: output
id: "relay"
name: "${device_name} Relay"
output: "relay_output"
binary_sensor:
- platform: gpio
name: "${device_name} Switch"
pin: GPIO4
on_press:
then:
- switch.toggle: "relay"
filters:
- delayed_on_off: 50ms
- platform: gpio
name: "${device_name} Button"
pin:
number: GPIO25
inverted: yes
mode:
input: true
pullup: true
on_press:
then:
- switch.toggle: "relay"
filters:
- delayed_on_off: 5ms
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: GPIO32
attenuation: 11db
- platform: adc
name: "${device_name} Relay Supply Voltage"
pin: GPIO33
attenuation: 11db
filters:
- multiply: 8
status_led:
pin:
number: GPIO0
inverted: true
Flashing:
back in the command line type: esphome run your-shelly-name.yaml
This should install esphome to your shelly plus 1! Chose USB UART when it asks.
Disconnect the USB and IO-0 from ground if you haven’t already. Plug into USB again to boot the shelly.
Make sure it connects to your Wifi. If yes it should pop up in home assistants devices page as discovered.
From now on you can flash over OTA so you can install the shelly into the wall.
Flashing is then the same process of changing the yaml and running it in the terminal just chose OTA instead of USB UART.
Easy as that
Bonus: If you want to add a check if your homeassistant is reachable then add this for your switch input:
#Switch input
binary_sensor:
- platform: gpio
name: "${device_name} Switch"
pin: GPIO4
on_state:
then:
- if:
condition:
- api.connected:
then:
- switch.turn_on: "relay"
- homeassistant.service:
service: light.toggle
data:
entity_id: light.arbeitszimmer
- logger.log: "It works?"
else:
- switch.toggle: "relay"
filters:
- delayed_on_off: 50ms
for me it toggles my lights in the office via the ha service or just switches the relais if ha is not reachable.