Part 4 of Creating your Interactive Smart Home Floor Plan

Home Assistant Automation Lights Sensors Dashboard Zigbee Bluetooth Layout

This episode is going to focus on integrating your smart equipment into HA and understanding how it is referenced/used. Make sure to follow along, because in the next episode we'll finally be able to put all this together and create our workable dashboard layout.

While there are multiple ways to integrate equipment, most will only work when integrated in a particular way. The info I'll share on this page will be generic or specific to what I have, and I'll trust to your own research skills for how to work with anything you have and I don't cover below.

If at any point you need to reference the previous episodes of the series, they can be found on this page.

What you need to continue

You've gone through and installed or enabled (at minimum):

  1. HACS
  2. VSCode (called Studio Code Server)
  3. Samba
  4. Maria DB (recommended, not required)

You will also need:

  • Your smart equipment

Moving your images into HA

HA will need to access and read all the floorplan images you've created. To achieve this, we'll move them into a folder in HA.

  • Using SMB, access your HA folders and select config > www
  • Create a new folder called floorplan and copy your images into it

Let's add some smart lights

I have lights which primarily use one of the following two types of connection method:

  1. WiFi
  2. Zigbee

Generally you'll find that if lights connects via WiFi, the integration method in HA is similar regardless of brand/model. Those that connect via Zigbee will also integrate in similar ways to each other.

Additionally, you may have lights which connect using either of those protocols, but connect to a hub (normally from the same manufacturer as the lights you have). If that's the case, you'll want to connect the hub to HA rather than the individual light.

💡
I won't be covering Hub integrations, but they're pretty straightforward and well documented

WiFi Integration

The process for connecting your WiFi-enabled lights to HA is a little more in depth than with Zigbee or Z-Wave. Normally:

  1. Power on the light/bulb
  2. Open the manufacturer's app on your mobile device (check the packaging for QR codes/site addresses which show you how to download these)
  3. Follow the steps in the app to discover your smart bulb
  4. You will normally be asked to select which home WiFi to connect the bulb to, give your bulb a name, and which group or room to add your bulb to. Names and groups are at your discretion (though Bedroom 1, Bedroom 2, and a group called Bedroom etc. per room seems pretty logical for most cases) however make sure you connect to the same network your HA instance is on

Once you've done that, head over to HA, and you will need to do one of two things. Either:

  1. A notification will pop up which essentially says that HA has discovered the device and is asking you to configure it (image above, I don't have any active notifications which is why mine is cobbled together)
  • Click the notification and it will take you to the Devices & Services screen, with your pending integration visible top left

Or:

2. You will need to manually find the integration

For (2) above, you'll likely need to do something like:

  • Go to Settings > Devices & Services
  • Click the ADD INTEGRATION button bottom right
  • In the popup, search for and then select your integration, then follow the on-screen instructions

Most integrations walk you through what to do. Although Sengled has an integration listed, this redirects you to documentation which explains how to manually set up the integration from a github repo. I'm not going to do the whole thing, but it's the documentation is clear:

  • Installation is via HACS
  • There are a couple of lines of code to add to the configuration.yaml via Studio Code Server

Zigbee Integration

This is more straightforward, though you do need a Zigbee coordinator (such as a dongle or Sky Connect).

  • If you haven't already, head over to Settings > Devices & Services, then ADD INTEGRATION and select Zigbee Home Automation (also referred to online as ZHA)

Once the coordinator has been configured:

  • Supply power to your Zigbee-enabled light bulb which should automatically make it discoverable (check your smart light's documentation if you're not sure about this)
  • Back in Devices & Services click ADD INTEGRATION. You should now have an option to Add Zibgee device at the top
  • Click it to take you to the next screen which will search for your device
  • You should see the service discover, handshake and add your device
  • Once added, your devices will show up under your Zigbee integration

Congrats, you've now got some lights set up

Controlling and naming your lights/entities

The following is the same regardless of whether you've added a device via WiFi, Zigbee, Bluetooth or some other protocol:

  • Click into one of your lights from the Devices tab
  • Click the pencil icon at (1) and rename your device
  • It should ask you if you want all entities to reflect this, I normally want this
  • Note that at (2) you have a toggle control to turn your light on and off
  • Clicking the bulb icon or the name at (2) will open more fine control of that bulb, depending on what its capabilities are, and will also give you additional settings options
  • Click the cog button top right
  • This gives you various options to rename the light, change the icon used for the entity, and rename the Entity ID
  • You can also enable/disable, hide/make visible and use the device area for this entity
💡
Entity IDs follow a set pattern: domain.device_name. This domain is how HA knows what the entity is, so you'll see things such as light.dining_room, sensor.bedroom_temperature and device_tracker.mobile_app. The domain is very important, so don't change the light portion of the Entity ID above

Grouping lights together

Groups are a great way to have multiple lights in one area, room, floor or home react to a single switch, command or automation. Think about the rooms you have and the smart lights you have in those rooms to figure out how best to group them. When you're ready:

  • Head over to Settings > Devices & Scenes
  • Click Helpers at the top right
  • Click CREATE HELPER bottom right, select Group in the options list popup, then Light group
  • On the next screen, name your group and add the Member devices/entities

Add your sensors to HA

Again there's no single way to do this, it very much depends on what you've got.

ESPHome and ESP32 with temperature/light sensors

As mentioned in Part 1, I use a Dallas temperature sensor and a BH1750 light sensor with an ESP32.

The below link has additional information and links on how to get started.

ESPhome
Integration for your ESP boards

Bluetooth sensors

If you have sensors which communicate via Bluetooth (such as the LD2410B Presence and Motion sensor) you will need to make sure your system supports Bluetooth, either natively or with a dongle (again see notes on this in Part 1). You add the Bluetooth integration in the same way as any other integration - ADD INTEGRATION and search for Bluetooth.


Creating our sensors to tell the different times of day

We require these software sensors to automatically change your dashboard image to the correct times of day. There are a number of ways to do this.

Using Helpers

Probably the way people like the most is to use the HA gui to make multiple binary_sensor helpers:

  • Go to Settings > Devices & Services then click Helpers top right
  • Select CREATE HELPER in the bottom right corner, then choose Times of the Day Sensor
  • Name it Morning and add your On and Off times
  • Click Submit then do the same for Afternoon, Evening and Night
  • Click into your Overview dashboard and you should see a section called Binary Sensors with your newly created times of day sensors, with the correct one set to On
💡
One issue with this method is that it doesn't take into account the changing times for sunrise and sunset. I want my images to change based on those rather than always be at 6pm on a certain day. If you're the same, use this next method to create your daytime states

Creating a binary sensor template

  • In HA, open Studio Code Editor
  • Add a file to the root config level and call it sensors.yaml
  • Copy and paste the below code into it
- platform: template
  sensors:
    time_of_day:
      friendly_name: "Time of Day"
      value_template: >-
        {% if is_state('binary_sensor.morning','on') %}
          Morning
        {% elif is_state('binary_sensor.afternoon','on') %}
          Afternoon
        {% elif is_state('binary_sensor.evening','on') %}
          Evening
        {% else %}
          Night
        {% endif %}
  • Add another file to the same config directory, and call it binary_sensors.yaml
  • Copy paste the below code into it:
- platform: tod
  name: Morning
  after: sunrise
  before: "12:00"
- platform: tod
  name: Afternoon
  after: "12:00"
  before: "17:00"
- platform: tod
  name: Evening
  after: "17:00"
  before: "19:00"
- platform: tod
  name: Night
  after: sunset
  after_offset: "-01:30"
  before: sunrise

This makes use of a built-in HA entity sun.sun which will automatically update sunrise and sunset times in your locality

  • Change the times as makes sense for you and your part of the world
  • The after_offset tells the sensor that Night starts 1h30m before sunset

We need to now tell our HA configuration.yaml to use these new sensor files:

  • Select configuration.yaml in Studio Code Server
  • Where it has automation: !include automations.yaml towards the top, add the following two lines:
binary_sensor: !include binary_sensor.yaml
sensor: !include sensor.yaml

Finally:

  • Head over to Developer Tools, make sure YAML is selected in the top ribbon, then click ALL YAML CONFIGURATION
💡
This will restart only those items relying on yaml rather than the full HA configuration/service/app

Now if you go to your Overview tab, you'll see that you have the same as before, but this time the night and morning sensors will change depending on sunset and sunrise times.


Nearly there!

So we've added lights. We've added sensors. We've added whatever we've got, we know their names and their Entity IDs.

Part 5, Episode 5: The Dashboard Strikes Back is on its way...


Part 5 of 5: Creating your Interactive Smart Home Floorplan
We’ve created our images. We’ve set up our smart devices, sensors and integrations. Now we pull it together into one, cohesive dashboard.
Part 3: Build an Interactive Floor Plan for Home Assistant
In this episode I walk you through converting your Sweet Home 3D renders into workable layers using GIMP and exporting them for use in HA
Part 2: Your personalized, interactive smart-home floorplan
In this part of the series you’ll create your layouts, 3D renders and lighting states in preparation to edit them
Home Assistant - First Steps After Installation
A handy collection of services you will need to install on your Home Assistant (HASS) instance - from SSH to automatic backups in the cloud