Hi all!
Recently I flashed one of my (many) Sonoff S26 smart plugs with ESPHome. Great fun - managed to do it by holding probes on the 4 contact points by hand
One thing I missed from the Sonoff functionality was the idea of âinchingâ - where you can set a delay on the plug itself to turn off automatically. Yes, easy enough to do in HA itself, but having it built into the plug gives you confidence in case of network outage etc that itâll definitely get turned off.
Anyway after some fiddling I have it working, but itâs not very pretty. Mostly because the âinching timeâ entity comes up in HA as ânumber.xxxxâ not âsmartplug.xxxxâ so I had to use a vertical stack card to put the two together. Any ideas to improve this would be welcome!
Hereâs the ESPHome code:
esphome:
name: smartplug1
platform: ESP8266
board: esp01_1m
board_flash_mode: dout
status_led:
pin:
number: GPIO13
inverted: false
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "xxxxxxxxxx"
ota:
password: "xxxxxxxxxxx"
wifi:
power_save_mode: light
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Smartplug1 Fallback Hotspot"
password: "xxxxxxxxxx"
captive_portal:
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
name: "smartplug1 Button"
on_press:
- switch.toggle: relay
- platform: status
name: "smartplug1 Status"
sensor:
- platform: wifi_signal
name: "smartplug1 WiFi Signal"
update_interval: 60s
number:
- platform: template
id: inching_on_time
name: "Inching on time"
optimistic: true
restore_value: true
initial_value: 60
min_value: 1
max_value: 120
step: 1
unit_of_measurement: minutes
entity_category: config
mode: slider
switch:
- platform: gpio
name: "smartplug1 Relay"
pin: GPIO12
id: "relay"
on_turn_on:
then:
- switch.turn_on: relay
- delay: !lambda 'return id(inching_on_time).state * 60000;'
- switch.turn_off: relay
- platform: restart
name: "smartplug1 Restart"
And hereâs the lovelace card:
type: vertical-stack
cards:
- type: entities
entities:
- switch.smartplug1_relay
- type: entities
entities:
- number.inching_on_time