Sebastian

Home Automation III – The atmospheric bed light

Put to the test – The self-developed node in your own home automation

In the first part of the series, you have laid the foundations to be able to implement a home automation system yourself. The second part serves as an introduction to a possible framework to integrate your own sensors and actuators in this automation with relatively manageable effort.For the third and, for the time being, last part of this series, you build your own control board for lighting applications, program it and see for inspiration how it could be used in practice.

The project

Time required: 5h (advanced)

You need this:

  • Understanding Part I and Part II
  • LED strip, various options available
    • up to three PWM outputs
    • up to two outputs for e.g. smart pixels (WS2812B)
  • Switches/control elements
  • various components
    • D1-Mini
    • 1x TXS0102
    • 2x 0.1 uF (0603)
    • TVS diode
    • Thermal fuse
    • Fuse
    • Per PWM channel: 1x MCP1415, 1x 10 kOhm (0603), 1x 100 Ohm (0603), 1x 1 uF (0603), 1x NMOS (TO-252) e.g. IRLR8726
    • Per smart pixel channel: 1x 10 kOhm (0603), 1x 2n7002 (SOT-23), 1x PMOS (TO-252) e.g. DMP3028
    • Per input: 1x 10 kOhm (0603), possibly additional resistors for voltage dividers
  • Some LED strips, including WS2812B, RGB LEDs or monochrome
  • Soldering station and accessories (tweezers and side cutters) for minimum sizes VSSOP-8
  • the circuit board (plus Gerber and Drill file in the download)
  • Assembly diagram (“InteractiveBom.html”), code and other files [download]

EzLight – Range of functions and overview

For lighting control systems, you can buy many different products from many manufacturers. What is usually missing is the possibility to modify or adapt them to your own needs.

The EzLight-Board is supposed to be a “One-Size-Fits-All” solution by being modular and based on a controller that is intensively used in the DIY-community.

Let’s start with the overview right away with the core component, the ESP8266, which is plugged onto the motherboard in the form of a D1 Mini.
This saves you the cost and effort of assembling the PCB.
You can choose whether you want to connect the lighting control to the home automation system via WiFi or simply operate it in stand-alone mode.
Programming can be carried out using all the usual methods, from the Espressif SDK and Arduino to practical frameworks such as PlatformIO and ESPHome.

Three GPIOs are provided for manual interaction with the controller. Two of them (pins D0 and D8) serve purely as digital signals for e.g. buttons, switches or rotary encoders.
The third GPIO A0 can optionally be used as an analogue input, allowing the use of digital potentiometers or various sensors.
It is of course also possible to use these pins as output, but please note the maximum current that each output can provide.

There are two different types of outputs that can be used for lighting control. Firstly, there are three PWM outputs that can be configured either in a group for e.g. an RGB light chain or individually for three monochromatic light chains.

The second type is intended for bus-controlled lights such as WS2812B. Two strings can be operated independently of each other.
The TXS0102 level converter enables the 3.3 V controller to communicate stably with the 5 V tolerant LEDs.
In order to minimise the quiescent current, one MOSFET per string is located in the supply voltage feed as an isolating switch.

Each power output can be supplied from its own power source, which does not limit the options for the LEDs used (important: GND is merged, so they have the same reference potential).
A constant current control is not provided.

The Gerber files can be found above under “The Project” in the download.

The light show begins

The lighting of the bed consists of two elements, a reading light along the headrest and atmospheric background lighting along the underside of the bed edge.
In this example, you therefore only need to equip one PWM and one WS2812B output (PWM1 and WSLED1 assemblies).

As you have probably already guessed, you will use ESPHome to program the controller. On the one hand you want to be able to control it via the Home Assistant Server, but you also want to have a button for switching the individual lights on and off without a smartphone.

The download attached above under “The Project” includes a generic config file for ESPHome. There all elements of the hardware are pre-configured. For the bed lighting, you can take this template and delete the unnecessary nodes and add further functions.

The file “bedlight.yaml” represents my configuration, which I will now briefly present in parts.
At the very top, you will find the option of simply substituting names so that you do not have to get involved in several places.

The ESPHome configuration node should be correct without further adjustments, just make sure that your “secret.yaml” is filled with the correct credentials (there is a template for this in the attached files as well).

In the node Binary Sensors you can define buttons, switches and if necessary their effect.
In case of Bedlight the node looks like this:

binary_sensor:
  - platform: gpio
    id: button_2
    pin:
      number: D0
      inverted: False
      mode: INPUT
    internal: True
    on_multi_click:
        - timing:
            - ON for 0.1s to 0.5s
            - OFF for at least 0.6s
          then:
            - light.toggle: monochrom_1
        - timing:
            - ON for 0.1s to 0.5s
            - OFF for at most 0.4s
            - ON for 0.1s to 0.5s
          then:
            - if:
                condition:
                - light.is_on: ws_led_1
                then:
                - light.turn_off: ws_led_1
                else:
                - light.addressable_set:
                    id: ws_led_1
                    red: 0%
                    green: 0%
                    blue: 80%
                - light.turn_on: ws_led_1
    on_press:
        - delay: 1s
        - while:
            condition:
              and:
                - light.is_on: monochrom_1
                - binary_sensor.is_on: button_2
            then:
              - light.dim_relative:
                  id: monochrom_1
                  relative_brightness: -2%
                  transition_length: 0.1s
              - delay: 0.1s

The push-button connected to D0 is configured here. The “internal” variable means that the status of the push-button is not transmitted to Home Assistant.

In the sub-node “on_multi_click” you define the behaviour. For example, if the button is pressed briefly (between 0.1 and 0.5s) and then released, the status of output “monochrome_1” is toggled.
In other words: we switch the reading light on and off.

With a double click the underbody light (ws_led_1) is switched on and off. If the reading light is too bright, the brightness can be dimmed by holding down the push button. This function is defined in “on_press”.

With these few lines you have implemented a relatively complicated operating concept and can control the lights!

In the next nodes the lights are defined. As already mentioned it is possible to use one of the two options for the PWM outputs:

light:
    # Comment out if not needed
  - platform: monochromatic
    id: monochrom_1
    name: ${pwmlight_1_name}
    output: pwm_1
    internal: False
    # Comment out if not needed
  - platform: monochromatic
    id: monochrom_2
    name: ${pwmlight_2_name}
    output: pwm_2
    internal: False
    # Comment out if not needed    
  - platform: monochromatic
    id: monochrom_3
    name: ${pwmlight_3_name}
    output: pwm_3
    internal: False

or

#light:
  - platform: rgb
    id: rgb_1
    name: ${rgblight_name}
    red: pwm_1
    green: pwm_2
    blue: pwm_3
    internal: False

The WS2812B also offers a number of customisation options.

Do you want to add your own lighting effects? With the “effects” node and the documentation this is no problem.

light:
  - platform: fastled_clockless
    chipset: WS2812B
    name: ${smartledlight_1_name}
    num_leds: 60
    rgb_order: GRB
    id: ws_led_1
    pin: D1
    power_supply: power_supply_ws_led_1
    effects:
      - random
      - addressable_flicker

At the end, further elements are defined, e.g. the assignment of pins to the outputs and switching off the supply voltage for WS2812B by the power supply node.

The result

Once both the hardware and the firmware have been prepared and the LED strips have been installed and wired, all that is missing is

esphome bedlight.yaml run

and the controller is already programmed.

Last but not least you configure Home Assistant and add an ESPHome integration with EzLight and the show can start:

Leave a Reply

Your email address will not be published. Required fields are marked *