Smart bed heater update

Smart bed heater update with integrated timer function in ESPHome.

Sonoff Basic
Sonoff Basic Timer Update

In my recent post about the smart bed heater I had a suggestion to move the logic for the timer from Home Assistant to the Sonoff Basic but I never looked into it because it is running reliably for years now. I think it must be something around 2018 when I build this.
Also, I am lazy. 😉

But after sharing this post on the Home Assistant Reddit someone told me it is easy to do:

Timed turn off in ESPHome is pretty straightforward - you just need to add something like

on_turn_on:
 - then:
   - delay: 30m
   - switch.turn_off: relay

to your switch component.

Comment Source

Since this seemed so easy I just tested this. The suggestion was not 100% correct but close. Here is the changed ESPHome config with the integrated time:

---
# bedheater
esphome:
  name: sonoff_basic_05
  platform: ESP8266
  board: esp01_1m

wifi:
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_password
  reboot_timeout: 15min

# Enable logging
logger:

# Enable Home Assistant API
api:
  reboot_timeout: 15min

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      then:
        - switch.toggle: relay
    name: "sonoff_basic_05_button"
  - platform: status
    name: "sonoff_basic_05_status"


switch:
  - platform: gpio
    name: "sonoff_basic_05_relay"
    pin: GPIO12
    id: relay
    on_turn_on:
      - light.turn_on: led
      - delay: 2700s
      - switch.turn_off: relay
    on_turn_off:
      - light.turn_off: led

output:
  # Register the green LED as a dimmable output ....
  - platform: esp8266_pwm
    id: basic_green_led
    pin:
      number: GPIO13
      inverted: True

light:
  # ... and then make a light out of it.
  - platform: monochromatic
    name: "sonoff_basic_05_green_led"
    output: basic_green_led
    id: led

The only change is adding the delay: 2700s  and the switch.turn_off: relay to the switch: block and then removing all the timer logic in Home Assistant. The only thing to keep in Home Assistant is now the button press action which will turn on the relay.

Now the ESPHome device (Sonoff Basic) will turn itself off after 2700 seconds which are 45 minutes. That is enough for my particular bed warmer to heat up the bed properly. Your mileage may vary.

The Power of ESPHome

Having the ability to change the device default behavior with your own firmware and without code is just awesome.

Better GIF
Better GIF (Source)

Think of it this way. When you have a smart socket from some vendor X the vendor decides what you can do with YOUR device. The vendor also could have good intentions and integrate the device with a local API in Home Assistant, no cloud needed, etc.

A non ESPHome based smart socket will most likely not allow changing the intended behavior.

With ESPHome on the other hand I can do almost whatever I want.
Heck, I could decide to switch any other relay instead of the built-in relay. The smart button could be used to do anything Home Assistant is capable of. Even delivering a pizza from Dominos 🍕.
Unfortunately, the Home Assistant Dominos integration is not available in Germany 🙁.

So check out the ESPHome project if you are thinking of buying smart devices. This could impact your decision. It sure does impact mine!

Happy automating!