Hi
As with all shelly’s in the house this one was flashed with ESPHome. I bought this new Shelly Plus 2PM to replace a Shelly 2.5 with two channels (They seem to fail after a year or two). I have configured the device according to the example on esp devices but have trouble with some things.
Whats working well:
Relays
WiFi
Whats not working:
Temperature reads 166 deg at cold boot and jumps up to 174 and then stays there. Documentation says its not perfectly calibrated but this very far off
Getting No readings at all (Unknown) from current and voltage sensors
The button on the device does not work. In fact it reports that it is pressed all the time. Every 30s it quickly reports off and then back to on. I tried changing the update_interval for the ADC and that affected this behaviour on the input button. (Setting it to 5s made the input flip quickly every 5s instead) Strange!
What I have not tried yet:
Switch Inputs
There seems to be very little info about this device with ESPHome out there and I’m wondering if maybe there is some updated hardware as the configuration seems to work so badly for me. Any ideas / Any more of you out there using this device with ESPHome?
Oh, sorry, i overlooked your link…
Well, only faulty shelly comes to my mind, since i have 5 shelly 2.5 (covers) and one shelly plus 1PM on esphome and all work perfectly…
A little update for you guys here on my problem. Not a faulty device. I got myself another shelly plus 2pm and backed up the stock firmware on it and then flashed it on the device I tried with ESPHome. The shelly now works reporting current, voltage etc. So… what conclusion should one draw from that then!
I didn’t calibrate any of NTC’s. “Rough estimate” is ok for me, as i need only coarse information and i think that it shows pretty ok - it showed 50-70 without any power save, with power save to light temp is some 10 degrees lower.
Here’s my complete code. i use “common” yaml’s - inside i have code, which is common for all my models (also included below). file “common_led_inverse.yaml” is only for LED indication of connetion status: lit when no connection, slow equal flashing when connected only to wifi and only short pulse every 5s when connected to HA.
buttons SW1 and SW2 work in a way: up-stop-up-stop…, or down-stop-down-stop…, while on-case button works open-stop-close-stop…
Name strings (and comments) are in Slovenian, i translated all major things to english…
globals:
- id: stevec
type: int
initial_value: "0"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
#power_save_mode: none
manual_ip:
static_ip: ${wifi_ip_modula}
gateway: 192.168.0.1
subnet: 255.255.255.0
dns1: 192.168.0.1
dns2: 192.168.0.1
logger:
tx_buffer_size: 256
logs:
switch: info
#API povezava s HA aplikacijo
api:
password: !secret ota_password
#OTA posodobitev FW na daljavo
ota:
password: !secret ota_password
web_server:
port: 80
auth:
username: !secret ota_username
password: !secret ota_password
# preverjanje povezave API --> HA in samodejni RESET modula
interval:
- interval: 60s
then:
if:
condition:
not:
api.connected:
then:
- logger.log: HA prekinjen(2)!
- delay: 50s
- if:
condition:
api.connected:
then:
logger.log: HA povezan(3)!
else:
button.press: ${device_name}_reboot
button:
- platform: template
name: "${prijazno_ime} WiFi rescan"
on_press:
lambda: |-
if (wifi::global_wifi_component->wifi_rssi() < -50) {
// PATCH: Reset old priorities for known networks
for (auto &scan : wifi::global_wifi_component->get_scan_result()) {
if (wifi::global_wifi_component->has_sta_priority(scan.get_bssid())) {
wifi::global_wifi_component->set_sta_priority(scan.get_bssid(), 0);
}
}
// Rescan
wifi::global_wifi_component->start_scanning();
}
- platform: restart
id: ${device_name}_reboot
name: "${device_name} reboot "
sensor:
# PAZI! NE obračaj, ker drugače ne dela monitoring!!------------------------ WiFi
- platform: wifi_signal
name: ${prijazno_ime} WiFi
update_interval: 60s
internal: false
# interni senzor za generacijo prijaznega prikaza UPTIME časa,
# senzor za prikaz je pri "text_sensor"
- platform: uptime
id: ${device_name}_uptime_internal
update_interval: 60s
internal: true
on_raw_value:
then:
- text_sensor.template.publish:
id: ${device_name}_uptime
state: !lambda |-
int seconds = round(id(${device_name}_uptime_internal).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? String(days) + "d " : "") +
(hours ? String(hours) + "h " : "") +
(minutes ? String(minutes) + "m " : "") +
(String(seconds) + "s")
).c_str();
switch:
#Switch WiFi connected LED
- platform: gpio
pin: ${connected_pin}
id: ${device_name}_wifi_api_connected
internal: true
text_sensor:
#---------------------------------------------------------------- WIFI info
- platform: wifi_info
ip_address:
name: ${prijazno_ime} IP
internal: false
mac_address:
name: ${prijazno_ime} MAC
internal: false
bssid:
name: ${prijazno_ime} BSSID
internal: false
#senzor za prikaz prijaznega UPTIME časa
- platform: template
name: ${prijazno_ime} Uptime
id: ${device_name}_uptime
icon: mdi:clock-start
finally, common/common_led_inverse.yaml. Here it depends how led is connected (positive or negative). If flashing is reversed all “on” and “off” commands must be reversed.
# in order this to work SWITCH sensor MUST be defined in common.yaml file!!
interval: # verzija wifi=on: 500ms, api=on: 5s pulz
- interval: 1s
then:
if:
condition:
wifi.connected:
then:
- switch.turn_on: ${device_name}_wifi_api_connected
- if:
condition:
api.connected:
then:
- lambda: |-
id(stevec) +=1;
if (id(stevec) > 4) {
id(stevec) = 0;
id(${device_name}_wifi_api_connected).turn_off();}
- delay: 50ms
- switch.turn_on: ${device_name}_wifi_api_connected
else:
- delay: 500ms
- switch.turn_off: ${device_name}_wifi_api_connected
else:
- switch.turn_off: ${device_name}_wifi_api_connected
This is for Shelly 2.5PM, which i also mentioned in my above post…
but, even if your model is esp32 can’t be much different, just initial lines (first couple) are to be replaced with ones for esp32, all other is pretty much same, except check if gpio’s are at different numbers.
@djlujo : first i flashed via USB UART, yes. All other updates go via OTA.
shelly 2.5PM module has pins on the back for UART connection. Just DON’T connect to 230V at first flashing via UART!!! Use external 3.3V for first flashing.
anyone got wifi channel working on the shelly 2pm plus? I seem to be getting compilation errors:
/config/esphome/shelly-plus-2pm.yaml:191:14: error: 'WiFi' was not declared in this scope
lambda: return WiFi.channel();
^~~~
*** [/[data/shelly-plus-2pm/.pioenvs/shelly-plus-2pm/src/main.o](http://data/shelly-plus-2pm/.pioenvs/shelly-plus-2pm/src/main.o)] Error 1
I’m suspecting this potentially has to do with the board type (esp32doit-devkit-v1) somehow?
I spend countless hours/days to figure out how to use ESPHome on Shelly single core ESP32 devices (yes there is a solution using ESP-IDF as mentioned above but without the Arduino framework).
Here is the solution for those who are strugling to have ESPhome running using the Arduino framework on single core ESP32 using the Transmota plafromio fork for Arduino:
Hi Phisson!
Do you mind sharing the info how to backup the Shelly Plus 2PM stock firmware again?
I just bought one and like to have a backup before start playing with Esphome on it.