Winter is coming - Build your own "smart" bed warmer

How to build a smart bed warmer with Home Assistant.

Winter is coming - Build your own "smart" bed warmer
I have taken feedback and built the timer into ESPHome config: smart bed heater update

I have build a smart bed warmer years ago and thought it is worth sharing this silly idea. It is worth noting, that this will highly increase the acceptance factor in your household for your significant other if he or she is always cold. That way you can justify more silly home automation projects.

I am using the following components:

  • Home Assistant
  • Aqara Button (I am using the Zigbee2MQTT project with a CC2530 router to create the Zigbee network)
  • bed warmer/heater
  • Some sort of smart socket (in my case Sonoff Basic)

Finding the right bed warmer/heater

You need a bed warmer that will not turn itself off automatically after a fixed time. We want to control that our self. Just research this in the product description, comment ratings, or ask the manufacturer for your product of choice.

I just found a random one on amazon which has a physical switch to turn it off, level 1 and level 2. After some experimentation, I decided to use level 2 because this will heat up the bed way faster than level 1.

Deploy smart socket and switch

Now we need to put the smart socket near your bed, connect this guy with your bed warmer and make your bed. In my case, it was a Sonoff basic which I build some time ago. But you can take any smart socket which is compatible with Home Assistant.

Sonoff basic

After that, I placed an Aqara switch behind the bed frame. This is just for having easy access to toggle the smart socket. Mostly smart sockets are not in reach when you are being comfy in your bed.

Aqara switch on the back of the bed frame

You can use whatever switch you like which is the good thing about Home Assistant. It is flexible to your liking and does not force you into a vendor ecosystem.

Software with ESPHome and Home Assistant YAML

Now comes the software part. Do not worry, it is easy to set up.

ESPHome config for the Sonoff basic

This config is basically the same which is documented for the Sonoff Basic on the ESPHome website:

# bedheater
  name: sonoff_basic_05
  platform: ESP8266
  board: esp01_1m

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

# Enable logging

# Enable Home Assistant API
  reboot_timeout: 15min


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

  - platform: gpio
    name: "sonoff_basic_05_relay"
    pin: GPIO12
    id: relay
      - light.turn_on: led
      - light.turn_off: led

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

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

Home Assistant configuration

When I turn on the switch.bettheizung_relay (sorry for the German wording here) I will start a timer for 1 hour. After the timer has ended stop the switch.bettheizung_relay and also reset the timer.


      name: "Timer Bettheizung"
      duration: "01:00:00"
      icon: mdi:timer
    - alias: "Start timer for bedheater"
        platform: state
        entity_id: switch.bettheizung_relay
        from: "off"
        to: "on"
      condition: []
        - service: timer.start
          entity_id: timer.bed_heater

    - alias: "Stop bed heater after timer ended"
        platform: event
        event_type: timer.finished
          entity_id: timer.bed_heater
      condition: []
        - service: switch.turn_off
          entity_id: switch.bettheizung_relay

    - alias: "Reset timer when bed heater turns off"
        platform: state
        entity_id: switch.bettheizung_relay
        to: "off"
      condition: []
        - service: timer.cancel
          entity_id: timer.bed_heater
Home Assistant config for the bed heater

Switch config

The Aqara button was configured to toggle the switch.bettheizung_relay on a single button press. Just for easy on and off switching. Sometimes 30 minutes will make you more than toasty.

This is fine: burning building with dog

Suggestion for improvement

This works great for the past couple of years. But I always wanted to improve this by moving the timer logic from Home Assistant to the ESPHome based Sonoff basic. That way the device would always turn itself off after a certain time by itself and would not rely on Home Assistant. Home Assistant only would be used for connecting the bed heater relay with some sort of switch.

If you have an idea of how to accomplish this with ESPHome please let me know.