Hello, I’m using a shelly EM flashed with esphome to control a contactor in my electric panel. I want to delay switching on the contactor in case of a power outage so I set switch restore_mode: ALWAYS_OFF and
on_boot:
priority: 300
then:
- delay: 30s
- switch.turn_on: relay
But there is a problem, when updating shelly firmware the relay turns off. I want the relay to be off on boot only after a power outage not a reboot. So i tried this, but doesn’t work:
on_shutdown:
priority: 800
then:
- lambda:
relay->set_restore_mode(SWITCH_ALWAYS_ON);
Here is the full yaml:
esphome:
name: contor-em
on_boot:
priority: 300
then:
- delay: 30s
- switch.turn_on: relay
on_shutdown:
priority: 800
then:
- lambda:
relay->set_restore_mode(SWITCH_ALWAYS_ON);
esp8266:
board: esp01_1m
early_pin_init: false
# Enable logging
logger:
# Enable HA API
api:
encryption:
key: "redacted"
# Enable OTAs
ota:
password: "redacted"
# Sync RTC with HA
time:
- platform: homeassistant
timezone: Europe/Bucharest
# Wi-Fi Setup
wifi:
ssid: IOT
password: redacted
power_save_mode: LIGHT
# Enable fallback hotspot (captive portal) in case Wi-Fi connection fails
ap:
ssid: shelly-em AP
password: "12345678"
captive_portal:
i2c:
sda: GPIO12
scl: GPIO14
sensor:
- platform: ade7953_i2c
irq_pin: GPIO13
voltage:
name: Contor Voltage
id: voltage
current_a:
name: Contor Phase 1 Current
id: current_phase_1
current_b:
name: Contor Phase 2 Current
id: current_phase_2
active_power_a:
name: Contor Phase 1 Power
id: power_phase_1
filters:
- lambda: if (x <= 0.0) return 0; else return x * 1.156612516;
active_power_b:
name: Contor Phase 2 Power
id: power_phase_2
filters:
- lambda: if (x <= 0.0) return 0; else return x * 1.156612516;
update_interval: 5s
- platform: template
name: Contor Total Power
id: total_power
state_class: measurement
device_class: power
lambda: return id(power_phase_1).state + id(power_phase_2).state;
update_interval: 5s
unit_of_measurement: W
- platform: total_daily_energy
name: Contor Phase 1 Energy
id: energy_phase_1
power_id: power_phase_1
filters:
# Multiplication factor from W to kWh is 0.001
- multiply: 0.001
unit_of_measurement: kWh
- platform: total_daily_energy
name: Contor Phase 2 Energy
id: energy_phase_2
power_id: power_phase_2
filters:
# Multiplication factor from W to kWh is 0.001
- multiply: 0.001
unit_of_measurement: kWh
- platform: template
name: Contor Total Energy
id: total_energy
state_class: total_increasing
device_class: energy
lambda: return id(energy_phase_1).state + id(energy_phase_2).state;
unit_of_measurement: kWh
- platform: template
name: Contor Total Current
id: total_current
state_class: measurement
device_class: current
lambda: return id(current_phase_1).state + id(current_phase_2).state;
update_interval: 5s
unit_of_measurement: A
- platform: template
name: Contor Phase 1 Apparent Power
id: apparent_power_phase_1
state_class: measurement
device_class: power
lambda: return id(current_phase_1).state * id(voltage).state;
update_interval: 5s
unit_of_measurement: VA
- platform: template
name: Contor Phase 2 Apparent Power
id: apparent_power_phase_2
state_class: measurement
device_class: power
lambda: return id(current_phase_2).state * id(voltage).state;
update_interval: 5s
unit_of_measurement: VA
- platform: template
name: Contor Total Apparent Power
id: apparent_total_power
state_class: measurement
device_class: power
lambda: return id(apparent_power_phase_1).state + id(apparent_power_phase_2).state;
update_interval: 5s
unit_of_measurement: VA
- platform: template
name: Contor Phase 1 Power Factor
id: power_factor_phase_1
state_class: measurement
device_class: power_factor
lambda: return id(power_phase_1).state / id(apparent_power_phase_1).state;
accuracy_decimals: 3
update_interval: 5s
unit_of_measurement: "%"
- platform: template
name: Contor Phase 2 Power Factor
id: power_factor_phase_2
state_class: measurement
device_class: power_factor
lambda: return id(power_phase_2).state / id(apparent_power_phase_2).state;
accuracy_decimals: 3
update_interval: 5s
unit_of_measurement: "%"
- platform: template
name: Contor Total Power Factor
id: total_power_factor
state_class: measurement
device_class: power_factor
lambda: return id(total_power).state / id(apparent_total_power).state;
accuracy_decimals: 3
update_interval: 5s
unit_of_measurement: "%"
status_led:
pin:
number: GPIO0
inverted: yes
switch:
- platform: gpio
name: Contactor
pin: GPIO15
id: relay
restore_mode: ALWAYS_OFF
- platform: restart
name: Reboot
text_sensor:
- icon: mdi:application-braces-outline
platform: version
name: ESPHome Ver