A Practical Guide To Home Automation Using Open Source Tools
A Practical Guide To Home Automation Using Open Source Tools
com
A practical guide to
home automation using
open source tools
OPENSOURCE.COM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ABOUT OPENSOURCE.COM
What is Opensource.com?
STEVE OVENS
CHAPTERS
while I constantly learned and attempted new things, got in bed? All of these data points are of limited use on their
used to using the Tasmota interface. After a while, as the own, but together, you can use them to set the brightness of
number of devices grew, this method of managing things be- a light at dusk, turn a fan on because it’s above 26ºC (80ºF)
came untenable and did not scale well at all. in the room, but don’t turn on Steve’s desk lamp because
I began to poke around to learn how other people were his side of the bed is occupied.
managing their “smart homes.” Let’s be honest; at this point, If you can imagine it, you can accomplish it using Home
it wasn’t a smart home as much as a small but growing num- Assistant and the right sensor inputs.
ber of lights we could remotely control.
The big open source projects in this area are openHAB [11] Sustainable and open source
and Home Assistant [12]. This series won’t compare them in One thing I like about Home Assistant is that it seems
any manner. Partly, it’s because I am not qualified for this, as to be reaching a critical mass of adoption from various
I have only been using Home Assistant for the last year or vendors. But more important to me is that the company
so, but also because for me to feel comfortable making such behind it, Nabu Casa [13], creates a focal point for the
a comparison, I would have to set up openHAB as a drop-in community. The company hired developers directly from
replacement and, frankly, I have too much invested in Home the community, and it does not penalize you if you don’t
Assistant to explore this avenue. pay a monthly fee. The revenue Nabu Casa generates
comes from value-added items, like being able to access
About Home Assistant your local Home Assistant easily and from anywhere in
You may be wondering what Home Assistant is and what it the world.
has to offer. Imagine a house that reacts to its inhabitants, like This is important because it means that there is a path
in sci-fi movies. Perhaps you have a couple of bedside lamps, forward for the project, and it has a sustainable income for
a TV, some floor lighting, a fan, and a few other gizmos in your future development. Unlike “open core” models, Home As-
bedroom. As you walk into the bedroom, the lights turn on. sistant is fully open source, which means that if the commu-
Big deal, you say; we have had this technology for some time. nity disagrees strongly enough with Nabu Casa’s direction,
Of course, you are right. But what if it’s late and your signifi- it could fork Home Assistant at its current state and take a
cant other is already in bed? You might be in for a rather cold divergent path. Because my family has chosen to make this
greeting if the lights come on as you enter the bedroom. Yikes! piece of software integral to how we interact with our devic-
What if, instead, when you walk into the room at night, es, that Home Assistant has a revenue stream and is fully
the floor LED lights turn on to a soft glow—enough so that open source are invaluable to me.
you can move around without killing yourself but not bright In the next article, I will discuss some of the common stan-
enough to wake a sleeping partner. You climb into bed, and dards for IoT devices as well as the benefits of local control.
a few minutes later, the floor lighting turns off. This is what Future articles will walk through the basics of installing Home
Home Assistant can do for you. Assistant, setting up essential add-ons (e.g., MQTT), Node-
“But wait!” I hear you screaming at your monitor. “I can RED, the Community Store, making backups, and more.
just ask Alexa or Google to turn off my lights for me.” You’re In the meantime, comment or tweet [14] at me if you would
correct again, of course. However, what happens when like to explore something specific in-depth. If I have used it,
these services suffer some sort of disruption? Also, you may I can talk about it.
need to consider how loudly you need to speak to trigger
the listening device. And remember that thing I said about Links
privacy? Do you really want these big companies to learn [1] https://www.home-assistant.io/
your habits? Even discarding the privacy issue, consider that [2] https://opensource.com/article/19/3/home-lab
others may use your home as well. This means visitors need [3] https://www.plex.tv/
to know what commands you have available for controlling [4] https://opensource.com/article/19/1/manage-your-media-
your smart devices. kodi
Lots of “smart” products on the market can set timers, [5] https://nextcloud.com/
schedules, and scenes, but none of them can really react [6] https://selfhosted.show/
to any given situation. This is where a home automation hub [7] https://tasmota.github.io/docs/
like Home Assistant comes into play. [8] https://esphome.io/
At its core, Home Assistant is software that helps centralize [9] https://cloudfree.shop/
all of the sensors, gizmos, and gadgets you have in your home. [10] https://shelly.cloud/
With all of these products working together in concert, you can [11] https://www.openhab.org/
set all kinds of conditions that would not otherwise be possible. [12] https://opensource.com/article/18/3/smart-home-assistant
Has someone entered the room? Is it a certain time of the [13] https://www.nabucasa.com/
day? Is the room warmer than a certain value? Is someone [14] https://twitter.com/linuxovens
Cloud connectivity
Most devices you can buy today are tied to some type of
cloud service. While the cloud brings a certain level of con-
venience, it also opens a host of problems. For starters,
there are privacy issues related to a company having access
to your personal habits—when you are home, what shows
you watch, what time you go to bed, etc. Although most peo-
ple are not as concerned about these issues as I am, privacy
should still be a consideration, even if it is a small one.
Cloud access also creates issues around being reliant on
something outside your control. In 2019, Sonos came under
fire for remotely bricking [2] older smart speakers. Speak-
ers usually continue to work for years after their warranty (Amazon screenshot by Steve Ovens, CC BY-SA 4.0)
ends; in fact, they usually function until they physically break.
There’s also the case of Automatic, which produced a cloud- Some of these decisions are purely financial, but there are
based car tracker. When it announced in May 2020 that it more than a few anecdotal cases where a company blocks a
would be shutting down [3] its services, it advised customers person’s access to a device they purchased simply because
to “please discard your adapter by following standard elec- they did not like what the user said [7] about them. How crazy
tronic recycling procedures.” is that?
Being dependent on a third-party provider for critical func- Another consideration with cloud connectivity is a de-
tionality can come back to bite you. IFTTT [4], a popular ser- vice’s responsivity if its signals must travel from your home
vice for programming events based on external conditions, to a cloud server (which may be halfway around the world)
recently altered its free plan’s terms and conditions [5] to and then back to the device. This can lead to a two-second
severely limit the number of events you can create—from (or more) delay on any action. For some people, this is not
an unlimited number to three. This is even though IFTTT a deal-breaker. For others, that delay is unbearable.
charges device manufacturers for certification with its sys- Finally, what happens if there is an internet outage? While
tem, which allows products like Meross smart bulbs [6] to most modern home internet connections are quite reliable,
proudly display their compatibility with IFTTT. they do happen. Some large [8], well-known cloud service
Local control
There are several ways you can regain control over your
smart devices. Commercially, you could try something like
Hubitat [10], which is a proprietary platform that emphasizes
local control. I have no experience with these devices, as I
don’t like to rely on an intermediary.
In my home, I standardized on WiFi (although I may branch (© 2015 HiveMQ, reused with permission)
out to Zigbee [11] in the future) and Home Assistant [12]. Us-
ing WiFi means I need to buy or make my devices based on • Q
oS 1: The message is posted, and the broker replies
their compatibility with alternative open source firmware, such once the message is received. Multiple messages can be
as Tasmota [13] or ESPHome [14]. I admit that neither of these sent before the broker replies. For example, if you are try-
options is “plug-and-play friendly” unless you buy devices from ing to raise the projector’s brightness, multiple brightness
sources like Shelly [15], which is very friendly to the community, bars may be inadvertantly adjusted before the broker tells
or CloudFree [16], which has Tasmota installed by default. the sender to stop publishing messages.
(As a small aside, I have both flashed my own devices and
purchased them from CloudFree. There are some savings
with the DIY approach, but I buy pre-flashed devices for my
father’s house because this eliminates a lot of hassle.)
I won’t go into more detail about alternative firmware, how
to flash it, and so on. I simply want to introduce you to the
idea that there are options for local control.
In this series, I will use Home Assistant’s Mosquitto MQTT [5] https://ifttt.com/plans
broker [22] add-on. Most of my devices use MQTT; however, [6] https://www.amazon.ca/meross-Dimmable-Equivalent-
I do have a couple of non-critical Tuya devices that require Compatible-Required/dp/B07WN2J3C7
a cloud account. I may replace them with locally controllable [7] https://www.techrepublic.com/article/iot-company-bricks-
ones in the future. customers-device-after-negative-review/
[8] https://www.theverge.com/2020/9/28/21492688/microsoft-
Wrapping up outlook-office-teams-azure-outage-down
Home Assistant is a large, wonderful piece of software. It is [9] https://www.cnn.com/2020/08/30/tech/internet-outage-
complex in some areas, and it will help you to be familiar with cloudflare/index.html
these fundamental technologies when you need to trouble- [10] https://hubitat.com/
shoot and coordinate your setup. ]11] https://zigbeealliance.org/
In the next article, I will talk about the “big three” wireless [12] https://www.home-assistant.io/
protocols that you are likely to encounter in smart devices: [13] https://tasmota.github.io/docs/
Zigbee, Z-Wave, and WiFi. Don’t worry—I’m almost done [14] https://esphome.io/
with the underlying theories, and soon I’ll get on with install- [15] https://shelly.cloud/
ing Home Assistant. [16] https://cloudfree.shop/
[17] https://en.wikipedia.org/wiki/API
Links [18] https://en.wikipedia.org/wiki/MQTT
[1] https://opensource.com/article/20/11/home-assistant [19] https://www.youtube.com/watch?v=NjKK5ab0-Kk
[2] https://www.bbc.com/news/technology-51768574 [20] https://www.hivemq.com/tags/mqtt-essentials/
[3] https://www.cnet.com/roadshow/news/automatic- [21] https://www.hivemq.com/blog/mqtt-essentials-part-6-mqtt-
connected-car-service-dead-may-coronavirus/ quality-of-service-levels/
[4] https://ifttt.com/ [22] https://mosquitto.org/
by a single entity, all devices are guaranteed to work togeth- employee, you won’t be able to understand each other. Both
er. There is one standard and one implementation. This of you can speak and hear each other, but the meaning will
means that you never have to worry about which device you be lost.
buy from which manufacturer; they will always work. Similarly, the Zigbee standard allows all devices on a Zig-
Z-Wave operates in the 0.9GHz spectrum, which means bee network to “hear” each other, but different implemen-
it has the largest range of the popular protocols. A central tations mean they may not “understand” each other. Fortu-
hub is required to coordinate all the devices on a Z-Wave nately, more often than not, your Zigbee devices should be
ecosystem. Z-Wave operates on a mesh network [6] to- able to interoperate. However, there is a non-trivial chance
pology, which means that every device acts as a poten- that your devices will not be able to understand each other.
tial repeater for other devices. In theory, this allows a When this happens, you may end up with multiple networks
much greater coverage area. Z-Wave limits the number that could interfere with each other.
of “hops” to 4. That means that, in order for a signal to Like Z-Wave, Zigbee employs a mesh network topology
get from a device to a hub, it can only travel through four but has no limit to the number of “hops” devices can use
devices. This could be a positive or a negative, depending to communicate with the hub. This, combined with some
on your perspective. tweaks to the standard, means that Zigbee theoretically can
On the one hand, it reduces the ecosystem’s maximum support more than 65,000 devices on a single network.
latency by preventing packets from traveling through a sig-
nificant number of devices before reaching the destination. Pros:
The more devices a signal must go through, the longer it can • Open standard
take for devices to become responsive. • Form mesh network
On the other hand, it means that you need to be more • Low-powered and can be battery powered
strategic about providing a good path from your network’s • Can support over 65,000 devices
extremities back to the hub. Remember, the lower frequen- • Can communicate faster than Z-Wave
cy that enables greater distance also limits the speed and
amount of data that can be transferred. This is currently not Cons:
an issue, but no one knows what size messages future smart • No guaranteed compatibility
devices will want to send. • Can form separate mesh networks that interfere with
each other
Pros: • Uses the oversaturated 2.4GHz spectrum
• Z
-Wave compatibility guaranteed • Transmits only 10 to 30 meters
• F
orm mesh network
• L
ow powered and can be battery powered Pick your protocol
• M
esh networks become more reliable with more devices Perhaps you already have some smart devices. Or maybe
• U
ses 0.9GHz and can transmit up to 100 meters you are just starting to investigate your options. There is a lot
• L
east likely of the three to have signal interference from to consider when you’re buying devices. Rather than focus-
solid objects or external sources ing on the lights, sensors, smart plugs, thermometers, and
the like, it’s perhaps more important to know which protocol
Cons: (WiFi, Z-Wave, or Zigbee) you want to use.
• C
losed protocol Whew! I am finally done laying home automation ground-
• C
osts the most work. In the next article, I will show you how to start the ini-
• M
aximum of four hops in the mesh tial installation and configuration of a Home Assistant virtual
• C
an support up to 230 devices per network machine.
• U
ses 0.9GHz, which is the slowest of all protocols
Links
Zigbee [1] https://opensource.com/article/20/11/cloud-vs-local-home-
Unlike Z-Wave, Zigbee [7] is an open standard. This can be automation
a pro or a con, depending on your perspective. Because it is [2] https://opensource.com/article/20/11/home-assistant
an open standard, manufacturers are free to alter the imple- [3] https://www.smartthings.com/
mentation to suit their products. To borrow an analogy from [4] https://en.wikipedia.org/wiki/Wi-Fi
one of my favorite YouTube channels, The Hook Up [8], Zig- [5] https://www.z-wave.com/
bee is like going through a restaurant drive-through. Having [6] https://en.wikipedia.org/wiki/Mesh_networking
the same standard means you will always be able to speak [7] https://zigbeealliance.org/
to the restaurant and they will be able to hear you. Howev- [8] https://www.youtube.com/channel/
er, if you speak a different language than the drive-through UC2gyzKcHbYfqoXA5xbyGXtQ
First-time setup
You should now be able to access the HA interface by point-
ing a browser to http://homeassistant.local:8123. How-
ever, this relies on your router to support automatic DNS
registration. You can also access the webpage via its IP. In
(Steve Ovens, CC BY-SA 4.0) my case, that’s http://192.168.122.90:8123.
This brings up another screen with several options. Find Clicking on the Check Configuration button will check all
Advanced Mode and make sure it is toggled on. the HA configuration files for syntax errors. If it finds no er-
rors, you will see a message in green that says Configura-
tion Valid!
Looking ahead
Now that HA is set up and configured, you are ready to
start really digging into it. In future articles, I will explain
how to:
The next step is to choose the radio type, using the infor- You can name the device(s) and assign an area (if you set
mation in the DigiBlur tutorial. In this case, the radio is an them up).
EZSP radio:
Later, I’ll come back to using this integration. I’ll also get
into how to use this device in automation flows. But now, I
will show you how to add functionality to Home Assistant to
make your life easier.
There are all kinds of HA add-ons, ranging from Android that’s external to the HA machine, I find low value in doing
debugging (ADB) tools to MQTT brokers to the Visual Stu- this. Since I am using MQTT just to communicate with my
dio Code editor. With each release, the number of add- IoT devices, and HA is the primary method of coordinating
ons grows. Some people make HA the center of their local that communication, there is a low risk in having these com-
system, encompassing DHCP, Plex, databases, and other ponents vertically integrated. If HA is offline, the MQTT bro-
useful programs. In fact, HA now ships with a built-in media ker is almost useless in my arrangement.
browser for playing any media that you expose to it.
I won’t go too crazy in this article; I’ll show you some of the Install community add-ons
basics and let you decide how you want to proceed. Home Assistant has a prolific community and passionate de-
velopers. In fact, many of the “community” add-ons are de-
Install official add-ons veloped and maintained by the HA developers themselves.
Some of the many HA add-ons are available for installation For my needs, I install:
right from the web UI, and others can be installed from alter-
native sources, such as Git.
To see what’s available, click on the Supervisor menu on
the left panel. Near the top, you will see a tab called Add-on
store.
NodeRED is my preferred automation flow-handling solu- Don’t forget to start the plugin.
tion. Although HA has some built-in automation, I find a visu- Most add-ons follow a similar procedure, so you can use
al flow editor is preferable for some of the logic I use in my this approach to set up other add-ons.
system.
Wrapping up
Configure add-ons Whew, that was a lot of screenshots! Fortunately, when you
Some add-ons (such as File Editor) require no configuration are doing the configuration, the UI makes these steps rela-
to start them. However, most—such as Node-RED—require tively painless.
at least a small amount of configuration. Before you can start At this point, your HA instance should be installed with
Node-RED, you will need to set a password: some basic configurations and a few essential add-ons.
In the next article, I will discuss integrating custom Internet
of Things (IoT) devices into Home Assistant. Don’t worry; the
fun is just beginning!
Links
[1] https://opensource.com/article/20/11/home-assistant
[2] https://opensource.com/article/20/11/cloud-vs-local-home-
automation
[3] https://opensource.com/article/20/11/home-automation-
part-3
[4] https://opensource.com/article/20/12/home-assistant
[5] https://sonoff.tech/product/smart-home-security/zbbridge
[6] https://www.digiblur.com/2020/07/how-to-use-sonoff-
zigbee-bridge-with.html
(Steve Ovens, CC BY-SA 4.0) [7] https://tasmota.github.io/docs/
IMPORTANT: Many people will abstract passwords through [8] https://opensource.com/article/20/11/cloud-vs-local-home-
the secrets.yaml file. This does not provide any additional automation
security other than not having passwords in the add-on con- [9] https://opensource.com/article/20/11/wireless-protocol-
figuration’s YAML. See the official documentation [11] for home-automation
more information. [10] https://en.wikipedia.org/wiki/MQTT
In addition to the password requirement, most of the add- [11] https://www.home-assistant.io/docs/configuration/secrets/
ons that have a web UI default to having the ssl: true option
set. A self-signed cert on my local LAN is not a requirement,
so I usually set this to false. There is an add-on for Let’s
Encrypt, but dealing with certificates is outside the scope of
this series.
After you have looked through the Configuration tab,
save your changes, and enable Node-RED on the add-on’s
main screen.
- platform: mqtt
state_topic: "MainHallway/state/DOOR"
name: "FrontDoor"
qos: 1
payload_on: "open"
payload_off: "closed"
device_class: door
The /config/binary_sensor.yaml file tate_topic, as the name implies, is the topic where the
• s
After you name your file in configuration.yaml, you’ll have device’s state is published. This means anyone subscribed
to create it. In the File Editor, click on the folder icon again. to the topic will be notified any time the state changes. This
There is a small icon of a piece of paper with a + sign in its path is completely arbitrary, so you can name it anything
center. Click on it to bring up this dialog: you like. I tend to use the convention location/state/ob-
ject, as this makes sense for me. I want to be able to
reference all devices in a location, and for me, this layout is
the easiest to remember. Grouping by device type is also a
valid organizational layout.
There are a few things to note here. First, as the sensor data
(Steve Ovens, CC BY-SA 4.0)
is stored in a time-based data store, every reading has a
• q os, short for quality of service, refers to how an MQTT cli- Time entry. Second, there are two different sensors attached
ent communicates with the broker when posting to a topic. to this output. This is because I have both a DHT11 tem-
• payload_on and payload_off are determined by the firm- perature sensor and a BH1750 light sensor attached to the
ware. These sections tell Home Assistant what text the same ESP8266 chip. Finally, my temperature is reported in
device will send to indicate its current state. Celsius.
• device_class: There are multiple possibilities for a device Hopefully, the Home Assistant definitions will make a
class. Refer to the Home Assistant documentation [13] little more sense now. value_json is just a standard name
for more information and a description of each type given to any JSON object ingested by Home Assistant. The
available. format of the value_template is value_json.<compo-
nent>.<data point>.
The /config/sensor.yaml file
This file differs from binary_sensor.yaml in one very For example, to retrieve the dewpoint:
important way: The sensors within this configuration
file can have vastly different data inside their payloads. value_template: '{{ value_json.DHT11.DewPoint}}'
Take a look at one of the more tricky bits of sensor data,
temperature. While you can dump this information to a file from within
Home Assistant, I use Tasmota’s Console to see the data it
Here is the definition for my DHT temperature sensor: is publishing. (If you want me to do an article on Tasmota,
please let me know in the comments below.)
- platform: mqtt As a side note, I also keep tabs on my local Home Assistant
state_topic: "Steve_Desk_Sensor/tele/SENSOR" resource usage. To do so, I put this in my sensor.yaml file:
name: "Steve Desk Temperature"
value_template: '{{ value_json.DHT11.Temperature }}' - platform: systemmonitor
resources:
- platform: mqtt - type: disk_use_percent
state_topic: "Steve_Desk_Sensor/tele/SENSOR" arg: /
name: "Steve Desk Humidity" - type: memory_free
value_template: '{{ value_json.DHT11.Humidity }}' - type: memory_use
- type: processor_use
You’ll notice two things right from the start. First, there are
two definitions for the same state_topic. This is because While this is technically not a sensor, I put it here, as I think
this sensor publishes three different statistics. of it as a data sensor. For more information, see the Home
Second, there is a new definition of value_template. Assistant’s system monitoring [14] documentation.
Most sensors, whether custom or not, send their data in-
side a JSON payload. The template tells Home Assistant The /config/input_boolean file
where the important information is in the JSON file. The This last section is pretty easy to set up, and I use it for a
following shows the raw JSON coming from my home- wide variety of applications. An input boolean is used to track
made sensor. (I used the program jq to make the JSON the status of something. It’s either on or off, home or away,
more readable.) etc. I use these quite extensively in my automations.
kitchen_override: Wrapping up
name: kitchen In this article, I looked at the YAML configuration files and
kitchen_fan_override: added a few custom sensors into the mix. You are well on
name: kitchen_fan the way to getting some functioning automation with Home
laundryroom_override: Assistant and Node-RED. In the next article, I’ll dive into
name: laundryroom some basic Node-RED flows and introduce some basic
bathroom_override: automations.
name: bathroom Stick around; I’ve got plenty more to cover.
hallway_override:
name: hallway Links
livingroom_override: [1] https://opensource.com/article/21/1/home-automation-5-
name: livingroom homeassistant-addons
ensuite_bathroom_override: [2] https://opensource.com/article/20/11/home-assistant
name: ensuite_bathroom [3] https://opensource.com/article/20/11/cloud-vs-local-home-
steve_desk_light_override: automation
name: steve_desk_light [4] https://opensource.com/article/20/11/home-automation-
projector_led_override: part-3
name: projector_led [5] https://opensource.com/article/20/12/home-assistant
[6] https://tasmota.github.io/docs/
project_power_status: [7] https://esphome.io/
name: 'Projector Power Status' [8] https://create.arduino.cc/projecthub/Niv_the_anonymous/
tv_power_status: esp8266-beginner-tutorial-project-6414c8
name: 'TV Power Status' [9] https://www.home-assistant.io/docs/mqtt/broker
bed_time: [10] https://www.home-assistant.io/integrations/binary_sensor/
name: "It's Bedtime" [11] https://opensource.com/article/20/11/cloud-vs-local-home-
automation
I use some of these directly in the Lovelace UI. I create little [12] https://www.home-assistant.io/lovelace/
badges that I put at the top of each of the pages I have in the UI: [13] https://www.home-assistant.io/integrations/binary_sensor/
[14] https://www.home-assistant.io/integrations/systemmonitor
your daily backups for two weeks, four weekly backups, and of the disk and the size of the backup. I recommend keep-
perhaps four monthly backups. This, in my opinion, is overkill ing at least four backups on your machine if you can afford
for Home Assistant after you have a stable setup. You’ll have the space.
to choose the level of precision you need. I take a backup
before I make any change to the system. This gives me a
known-good situation to revert to.
Create snapshots
Great, so how do you create a snapshot in Home Assistant?
The Snapshots menu resides inside the Supervisor tab on
the left-size panel.
You can retrieve these files from Home Assistant with File
Browser if you set up the Samba share extension.
Save these files somewhere safe. The name you give the
backup is contained in the metadata inside Home Assis-
tant, and the file names are randomly generated. After I
copy them to a different location, I usually rename them
because when I test the restoration process on a different
machine, the new file name does not matter.
My homelab strategy
I run my Home Assistant instance on top of KVM on a Linux
host. I have had a few requests to go into a little more detail
on this, so feel free to skip past this section as it’s not directly
related to HA.
Due to the nature of my job, I have a fairly large variety
of hardware, which I use for a homelab [8]. Sometimes this
is because physical hosts are easier to work with than VMs
for certain clustering software. Other times, this is because
I keep workloads isolated to specific hardware. Either way,
this means I already have a certain amount of knowledge
built up around managing and dealing with KVM. Not to
(Steve Ovens, CC BY-SA 4.0)
mention the fact that I run almost exclusively open source
Any component you install in Home Assistant will populate software (with a few exceptions). Here is a basic layout of
in this menu. Choose a name for your backup and click my homelab:
Create. This will take some time, depending on the speed
Wrapping up
Backups are essential when you’re using Home Assistant,
as it is a critical component of your infrastructure that al-
ways needs to be functioning. Small downtime is accept-
able, but the ability to recover from a failure quickly is
crucial. Granted, I have found Home Assistant to be rock
solid. It has never failed on its own; any problems I have
had were external to HA. Still, if you are going to make HA
a central part of your house, I strongly recommend putting
a good backup strategy in place.
Links
[1] https://opensource.com/article/21/1/home-automation-5-
homeassistant-addons
[2] https://opensource.com/article/21/1/home-assistant-6-
custom-sensors
[3] https://opensource.com/article/20/11/home-assistant
[4] https://opensource.com/article/20/11/cloud-vs-local-home-
automation
[5] https://opensource.com/article/20/11/home-automation-
part-3
(Steve Ovens, CC BY-SA 4.0)
[6] https://opensource.com/article/20/12/home-assistant
When you get into creating Node-RED automations (in the [7] https://linux.die.net/man/5/magic
next article), I suggest you keep your own notes. I take a [8] https://opensource.com/article/19/3/home-lab
screenshot of the flow, write a brief description, so I know [9] https://spideroak.com/
what I was attempting to achieve, and dump the flow to [10] https://wiki.js.org/
JSON (for brevity, I omitted the JSON from this screenshot):