How to Control your lights with Home Assistant


Home Assistant has over 96 different type of integrations in the light category in addition you can use switches to turn on lights, light your wall plate or a smart plug that acts as a switch to turn on a lamp. Bulbs allow you to control the colour and the brightness of the light in the room without doing electrical work. Switches allow you to control light fittings that have odd bulbs that can’t be replaced, they also give you full compatibility even when the smart devices fail. Relays can be placed in your electrical circuit to control your lights without changing bulbs or light switches.

 

What is Home Assistant?

Home Assistant is an automation platform that enables you to connect smart devices together to create automation to control your smart home. Home Assistant is free to use and you can install it yourself on a raspberry pi check price on Amazon US, on a virtual machine (VM) or buy it pre-installed with home assistant blue (around $130).

In the video below you can find out how to install home assistant on a raspberry pi 3

Bulbs

In my smart home I have three different manufactures:

Philips Hue

Lifx

Lidl

 

The main reason I have different type of bulbs is because of the discounts that were available at the time of purchase, home assistant enables you to use bulbs from different vendors without even noticing. After the initial setup they behave in the same way.

Bulb are the best option if you are renting your home or don’t want to touch electrics at all. They can be the cheapest way to start but bear this limitation in mind:

If someone turns off the light at the wall they will not work!

Bulb offer also different light brightness and colour options which can add the wow factor 🙂

Main difference is Zigbee vs Wi-Fi

WiFi Bulbs

WiFi Bulbs your your access point normally located in your home router to make a connection to your home network and sometimes the internet itself. Each bulb as an ip address assigned to it. These bulbs require no gateway to work. You are limited by the distance between your WiFi router and the bulb and your coverage in general.

I have a Lifx WiFi colour bulb and it has been working fine without any issues.

Zigbee Bulbs

These bulbs use the Zigbee protocol to interact with each other. All communication between these bulbs and other devices happens through a gateway. This gateway represents another cost normally between (£20 – £80) depending on the vendor.

I use a Conbee II stick which you can integrate into Home Assistant thanks to deCONZ. I have several videos on my channel demonstrating this:

 

 

Switches

Switches are the best solution if you own your home and you are ok with doing electrical work, I hired a professional electrician as I was already doing some work in my home. He installed them for about £15 per switch.

 

These switches completely replace your existing, and they are in one gang, two gang or three and even more.

In my example I needed a neutral wire at the switch to achieve this, now in the market there are other options that don’t require it, check your own installation.

Switches can be cost effective if you have a strange light fixing that would cost a lot of money to get a smart equivalent option. One of my switches in the Kitchen controls 4 downlight, 6 ceiling lights and 1 main light. All of them can now be controlled in home assistant for just £30

I use a Sonoff light switch which you can see installed here:

 

Relays

There is one example in my outdoor light porch that I used a Shelly 1 Device relay hidden within the light porch fitting itself. The Shelly device connects over WiFi with home assistant to allow you to turn on / off the lights and set automation.

Do not attempt wiring a shelly device unless you are competent in doing so. This is a wiring diagram below:

Shelly devices are normally around £15-20 each.

 

 

shelly wiring diagram

 

Configuration in Home Assistant

Each integration has a different configuration step in this integration page from the home assistant guide you can find the latest information for the integration that you wish to configure.

Nowadays many configurations are auto discoverable and with a couple of clicks you are ready to go.

Philips Hue, Lifx & Shelly are an example of this.

Lights in home assistant can be found as entities. An entity is a representation of an object in home assistant. It would be formatted in this way:

light.kitchen_cupboard

The Light integration allows you to track and control light bulbs, you can call actions to turn on with a light.turn_on and turn off with a light.turn_off.

By adding them to the dashboard you are able to control them with a click of a button or tap on the mobile app.

You can toggle a light that would change the state regardless of the previous state.

If you bulb is compatible you are able to set brightness levels and colour temperatures.

 

Convert Switches into Lights

Add the following in the configuration.yaml file

Replace the entity_id with the switch, you can find the name in the integration tab or the developer tools. The new name will be the name you give in my example Downstairs Loo.

So I would find the new light as: light.downstairs_loo as spaces are not allowed in entity names.

light:
- platform: switch
  name: Downstairs Loo
  entity_id: switch.shelly1_loo

 

Automations in Home Assistant

I made a video on my Youtube Channel that explains these automation in detail, here you can find the code from my home assistant automation files.

Turn on Lights at Sunset

#Generated by UI
- id: '1611350199523'
  alias: Turn on lights at sunset
  description: ''
  trigger:
  - platform: sun
    event: sunset
  condition: []
  action:
  - service: light.turn_on
    data: {}
    entity_id: light.hue_play_1
  - service: switch.turn_on
    data: {}
    entity_id: switch.sonoff_inspiration_room
  mode: single

Turn on Lights at Specific Time (Alarm)

Before you can do this automation you will need to create a helper from the configuration tab. In my example I’m using a Date and Time helper. Give the helper a name and use it in the automation.

#Generated by UI
- id: '1611349622762'
  alias: Turn lights on at specific time
  description: ''
  trigger:
  - platform: time
    at: input_datetime.alarm
  condition: []
  action:
  - service: light.turn_on
    data: {}
    entity_id: light.hue_play_1
  mode: single

Turn on Lights when arriving at home

#Generated by UI
- id: '1611350337486'
  alias: Turn on Lights when arriving at home
  description: ''
  trigger:
  - platform: zone
    entity_id: person.natureboss
    zone: zone.home
    event: enter
  condition: []
  action:
  - service: light.turn_on
    data: {}
    entity_id: light.front_porch
  - service: light.turn_on
    data: {}
    entity_id: light.hallway_1
  mode: single

Motion Activated Lights

alias: Turn on light strip when there is motion in the kitchen

trigger:
  platform: state
  entity_id: binary_sensor.kitchen_motion_sensor
  to: 'on'
condition:
    condition: numeric_state
    entity_id: sensor.kitchen_motion_light_level
    below: 80
action:
    - service: light.turn_on
      entity_id: light.kitchen_lightstrip
      data:
         color_name: orange
         brightness: 255
         entity_id: light.kitchen_lightstrip
    - service: switch.turn_on
      entity_id: switch.sonoff_kitchen_downlights
      
    - service: switch.turn_on
      entity_id: switch.xmas_tree

Sync Lights Together

The goal of this automation is to sync bulbs and use them in tandem. This mirroring is useful if the bulbs are controlled by apps outside of home assistant.

Home Assistant is tracking a change of state and then updates them accordingly. You can mirror any common attribute you can find them in the developer’s tool.


#Turn on Lidl Lamps and Match State & Brightness

alias: Sync Lidl bulbs to Hue Lamp
trigger:
  platform: state
  entity_id: light.hue_white_candle_2

# turn lidl 1 on to same brightness level
action:
  service: light.turn_on
  data_template:
    entity_id: light.lidl_lamp1
    brightness: "{{ trigger.to_state.attributes.brightness }}"

#Turn on Lidl Lamps and Match Colour State & Brightness

alias: Sync Lidl bulbs to Hue Lamp
trigger:
  platform: state
  entity_id: light.living_2

# turn lidl 1 on to same colour & brightness level
action:
  - service: light.turn_on
    data_template:
      entity_id: light.lidl_lamp1
      brightness: "{{ trigger.to_state.attributes.brightness }}"
      rgb_color: "{{ trigger.to_state.attributes.rgb_color }}"
  - service: light.turn_on
    data_template:
      entity_id: light.lidl_lamp2
      brightness: "{{ trigger.to_state.attributes.brightness }}"
      rgb_color: "{{ trigger.to_state.attributes.rgb_color }}"

 

Gio

Gio loves rabbits, smart home tech, WWII, travelling to Thailand & my favourite pizza is margherita with parma ham!

Recent Posts