DIY Smart Home EP3 – Smart Lighting Control in Home Assistant

Hi and welcome to episode 3 of my DIY smart home series, where I’m walking you through how to set up your own self-hosted, private, secure and feature-rich smart home! Last episode we covered how to get the software, Home Assistant, up and running, and how to connect devices like our Zigbee based Philips Hue White Ambient bulbs. This episode is all about using Home Assistant to automate our lighting, and by extension getting to know Home Assistant a little more.

Let me start with the plan – it’s a good idea to know what you want out of your smart home tech, so let me explain. I want my smart bulbs to turn on at certain times of day – like in the morning to help me wake up, and to change their colour temperature throughout the day, going from colder in the morning to warmer at night. That’s generally called circadian lighting and is something I want to get working here.

So, that’s the plan – schedules and adaptive lighting. How do we do that? Well, like many open source softwares, there are a whole host of paths we can take to get similar end results, all with varying levels of customizability, practicality and effort required to both set up and maintain. I want to start with what Home Assistant can do already – if we take a look at the dashboard, the tab called “Overview”, you’ll see this is full of almost all of the devices and sensors we have connected already.

This dashboard lets us manually control our lights – we can turn them on and off, and clicking on them lets us control both the brightness and colour temperature. But this isn’t a very pretty dashboard, and to control things like the brightness or colour temp we need to click on the light to get the popup window which isn’t great. This dashboard page is controlled by Home Assistant, and will automatically add any new devices and sensors we connect, but because it’s controlled by Home Assistant we can’t change what’s here. Now we can just take control of this dashboard by clicking on the three dots in the top right, clicking take control, then take control on the popup box, but that means we stop Home Assistant controlling it, so for now we can go to Configuration, Dashboards, then click the Add Dashboard button on the bottom right.

Give your new dashboard a name, like “Main”, pick an icon, and give it a URL, like “/main” then hit Create. Your new dashboard will be empty, so click on the three dots again, then edit dashboard. You can then hit Add Card, and pick from the myriad of options available. The “Entities” option is the one that will let you toggle individual items like lights, and see information like temperatures and humidity from my Zigbee sensors I’ll be covering in the next episode! The “Light” card will be useful here though, so click that, then select your bulb from the entities list. It might be named something like Philips LTA001 0ac03d09 – luckily you can rename it with the “Name” option, pick an icon, any themes you likely don’t have installed yet, change the hold or double tap actions if you like, then hit Save. And just like that we now have a card to let us both toggle the light on and off, and drag the brightness around easily. Sadly the colour temperature is still a click away – but we are going to automate that so it’s no big deal.

Ok, so how do we automate it? Again, there are lots of options, but I want to make this series as user-friendly as possible so as many people as possible can follow along, so we will be going with the easy option, using the Home Assistant Community Store, or HACS. To install HACS you do need to use a single command line instruction, but don’t worry it’s nice and simple. While you can go about running this instruction in a number of ways, I’m going to walk you through how the HACS website recommends you to do it, which starts with you clicking on your user profile at the bottom of the sidebar on the left.

Toggle the “Advanced Mode” to on, then head to Configuration, Add-ons, Add-on Store (bottom right), then under the “Official add-ons” heading install “Terminal & SSH”. Once it’s installed, you may need to restart Home Assistant under Configuration, Settings, Server Controls, Restart. You can then head back to the Add-ons page, click on Terminal & SSH, then “Open Web UI”. Now you can copy and CTRL+SHIFT+V the terminal command from the HACS site – or type it in manually if you can’t paste it properly. Let it install, then you will likely need to clear your browser’s cache or hard refresh – just hold your CTRL key while pressing the refresh button or the F5 key.

You can then go to Configuration, Devices & Services, Add Integration then HACS. Once it is installed, accept the usage terms, then it will prompt you for a GitHub access token. You will want to have a GitHub account anyway if you are diving into the world of open source projects so if you don’t have one go ahead and register, then click the link in the HACS window, sign in, authorise it, you may need to paste the access token in then hit Submit.

That’s HACS up and running now, it should be in the sidebar on the left so let’s head to it and take a look. Here we have two main options, Integrations and Frontend. Frontend is all the UI elements that you will see on your dashboard, whereas integrations are the backend components that can control, automate and generally make everything work. I’ll start with the integrations – specifically the one I’m interested in is called Adaptive Lighting. This is what will change the colour temperature and brightness throughout the day for us. Install it with the button on the bottom right – again you might need to restart Home Assistant, then head to Configuration and Devices & Services, click Add Integration, then Adaptive Lighting.

Select what lights you want to control, in my case I want to do different things with the bulbs so I’m just picking one at a time, then you can set them up however you like. I set the transition time to 5 seconds, increased the minimum brightness, and set the min and max colour temperatures to be just inside the maximum the bulbs can do – fully cold or fully warm is just a little much. Then hit submit and that’s it! All sorted, the lights will now automatically change colour temperature throughout the day based on the sun’s position relative to me. Excellent!

Now sadly this doesn’t let me schedule specific times I want the lights to turn on or off, so for that we need to head back to HACS. This time let’s go to the Frontend section, then the explore button on the bottom right, and find the Scheduler Card. Now this one is actually both a Frontend and Integration – hit the install button on the card, and once it’s done head to the Integrations page and search for the scheduler component and install that too. Once both are installed and likely Home Assistant restarted again, make sure to hard refresh the page with CTRL+F5 or CTRL and clicking the refresh button, then head to your dashboard we created earlier.

Hit the edit button, then add card, scroll down to find the Scheduler Card custom component and select it. Enable any of the entities you want it to have access to or to control – in our case that will just be lights for now. Then hit Save, then on the card itself hit add, select the light you want to control, click “Make Scheme”, then drag the lines to create blocks where you want them on or off, and make sure to select each block and pick which action you want it to perform during that time. You can also add conditions on the “Options” page, like the light already being on or off, and if you select more entities in the scheduler window you can even make it do things like detect when your phone is at home and only switch on when you are actually there, and a whole load of other really cool stuff too.

So, that’s a look at how to customise our lighting setup. In this episode we’ve worked through getting the community store installed, installing custom components and frontend cards, customising dashboards and setting schedules and adaptive lighting. Quite a lot actually! Next episode is all about heating – making my central heating just a little more “smart”.