Automation is one of the key advantages of …. well …. home automation. As described here, we make a distinction between workflow automation (ie. user manually triggers an action that involves executing multiple actions) and self-healing automation (ie. the system triggers an action or series of actions based on environmental conditions). But how do we architect such automations? Where do we store the code and how do we manage updates?
Architecture options
There are 3 different options, given our overall design architecture:
- We can store/maintain all the automation code in Home Assistant (centralized)
- We can store each automation in the esphome device that is used to trigger it (semi-centralized)
- We can store instructions in each esphome client device to listen for automation triggers (decentralized)
Let’s look at a concrete example of 2 automations:
- The first automation will turn the RV into a movie theater. It involves lowering the blinds, turning off the lights, powering on projector and projection screen.
- The second automation, called ‘Go To Sleep’, will set up the RV in the proper state at bedtime. This again involves the blinds, lights, in addition to turning off any power hungry or loud devices.
1. Centralized in Home Assistant
Under this scenario, all intelligence (ie. automation code) resides in Home Assistant. The Home Assistant code will trigger the correct MQTT messages to generate the right action on each of the connected smart devices. The correct workflow gets triggered by the user, either through the Home Assistant UI, or through pushing the right hardware button for each automation.
2. Semi-centralized in Smart Buttons
In this case, the intelligence is implemented in each of the smart buttons who will trigger the automation. The button will send the right MQTT instructions to the MQTT Server who will relay them to the smart devices. The Home Assistant server does not play a meaningful role, other than visualizing the status of all devices and being able to trigger an automation by sending an MQTT message to one of the smart buttons.
3. Decentralized
All intelligence resides in the end points. Each end device decides which MQTT channels it subscribes to and will take the right action based on that information. For instance, the thermostat subscribes to the ‘go-to-sleep’ action but not to the ‘movie on’ action. When the ‘go-to-sleep’ action gets triggered (by the smart button or by Home Assistant), the thermostat will lower its temperature. The blinds and projection screen will both subscribe to both automations but will take different action for each automation. They will both lower when ‘movie on’ is received, but one will lower and the other one will raise when ‘go-to-sleep’ is received.
Pros and Cons
So how do we decide. Let’s look at some of the pros and cons of each solution:
Centralized Solution
Pro | Con |
---|---|
Centralized code maintenance is easier | Dependent on Home Assistant |
No need for firmware updates to update the logic | Cumbersome to centrally document every action for every device and every automation based on the state of each device |
Semi-Centralized Solution
Pro | Con |
---|---|
Not dependent on Home Assistant | Requires firmware updates to update the code |
Still easier to maintain than fully decentralized | Cumbersome to centrally document every action for every device and every automation based on the state of each device |
This assumes each automation has a hardware button associated with it. That may not always be the case. |
Decentralized Solution
Pro | Con |
---|---|
Not dependent on Home Assistant | More difficult to maintain. The logic is spread over 50+ devices |
More efficient coding because each end-point can control its state based on MQTT instructions | Requires firmware updates to update the logic |
Conflict management between different automations is easier because code is written from the perspective of the device who is taking an action. So, easier to understand and resolve. | Creating a new automation is a major pain since it would require a firmware update on each device that is impacted by the new automation. |