Context
Our bodies have evolved to sleep during the night and wake-up as down starts to break. In the winter months, with sunrise happening later, most people will have to resort to alarm clocks ringing while it is still dark outside. This is a rough way to be awakened and can be depressing too. A wake-up lamp provides a more “natural” wake-up routine, simulating a sunrise by gradually increasing in brightness until full brightness, which coincides with the alarm time. This hack was inspired by a Philips product.
Hardware
The wake-up light requires a dimmable light source; being able to control the color temperature is an added bonus, but not mandatory. For this project I’m using a smart LED bulb I had a few units lying around, the Sonoff B1 from Itead.
Replacing the B1 Firmware
To control the smart bulb from Home Assistant we’ll be flashing it with ESPHome. A couple notes: it is possible to integrate the LED bulb with Home Assistant keeping the original firmware unchanged; it is also possible to use Tasmota as the final firmware or as an intermediate in order to perform the first Over the Air (OTA) flashing, and then move to ESPHome. For this project I’ve decided to go straight to ESPHome and use it as the final firmware, same as other Sonoff devices I’ve modified earlier.
Flashing with ESPHome
The Sonoff B1 does not have header pins or thru vias to simplify the serial connection required for the first re-flashing; you’ll have to either solder pins for a temporary connection, or have a steady hand for holding a pin header bar against the pads for the duration of the upload. The schema for the serial connection is depicted below:
- Note that the GPIO0 pin must be held to ground while booting in order to put the device in flash mode. It can be released after flashing is complete to allow a normal boot (and inspecting the logs)
- While flashing the bulb must not be connected to mains power; it should be powered entirely by the 3v3 line from the UART adapter
- Ensure that 3v3 power is used; feeding 5v to this device will damage it
More information about this procedure can be seen here: https://tasmota.github.io/docs/devices/Sonoff-B1/#serial-flashing
ESPHome Firmware
The following is a minimal ESPHome configuration for the Sonoff B1. For the full config used in this project refer to github here: https://github.com/heckler/esphome-device-configs/blob/master/wakeup_light_01r.yaml
esphome:
name: wakeup_light_01r
platform: ESP8266
board: esp01_1m
arduino_version: 2.4.2
wifi:
networks:
- ssid: !secret wifi_ssid_1
password: !secret wifi_password_1
ota:
safe_mode: True
password: !secret ota_password
api:
logger:
level: DEBUG
my9231:
data_pin: GPIO12
clock_pin: GPIO14
num_channels: 6
num_chips: 2
bit_depth: 8
output:
- platform: my9231
id: output_blue
channel: 0
- platform: my9231
id: output_red
channel: 1
- platform: my9231
id: output_green
channel: 2
- platform: my9231
id: output_warm_white
channel: 4
- platform: my9231
id: output_cold_white
channel: 5
light:
- platform: rgbww
name: wakeup_light_01r
red: output_red
green: output_green
blue: output_blue
cold_white: output_cold_white
warm_white: output_warm_white
cold_white_color_temperature: 6500 K
warm_white_color_temperature: 2800 K
With the config above it is already possible to connect the device to Home Assistant and have full control of its different LEDs – the B1 have independent cool and warm white LEDs, as well as a set of low power RGB LEDs
The next post(s) will deal with the automation scripts in Home Assistant to create the desired sunrise simulation tied to a specific alarm time.