Table of Contents
Home Assistant Server
By: Anastasiia Zatsepina (32265) & Ekaterina Zakharova (30909)
1. Introduction
In this project, our group explored the creation and implementation of a home automation system using a Raspberry Pi and the Home Assistant platform. The system integrates various smart devices and sensors to automate and enhance everyday home activities, focusing on practicality and ease of use.
Key components of the system include a Raspberry Pi, which serves as the central hub, and a range of smart devices such as Zigbee-based sensors, Tuya-controlled pet feeder, and lamp. These devices work together seamlessly to provide a connected and intelligent home environment.The project covers the setup and configuration of Home Assistant on the Raspberry Pi, offering a short guide to integrating and controlling various smart devices.
By using Zigbee technology, we combine motion and temperature sensors to monitor and automate home conditions. Additionally, Node-RED is utilized to create automation workflows, such as automating the pet feeder and responding to motion sensor triggers. Furthermore, the system includes the configuration of the E-mail Node in Node-RED to enable email notifications for specific events.
InfluxDB is employed for data storage and graphical representation, allowing for the visualization of sensor data and system performance over time. Overall, this project demonstrates the potential of home automation to simplify daily tasks, improve home security, and enhance the quality of life through the integration of smart technologies.
2. Materials
- Raspberry Pi 5 with installed HA
- Zigbee
- Motion and temperature/humidity sensors
- Tuya devices: pet feeder and lamp
Raspberry Pi
The Raspberry Pi is a small, affordable, and versatile single-board computer that serves as the central hub for our home automation system (Figure 2.1). Its compact size, low power consumption, and robust performance make it an ideal choice for running Home Assistant and managing various smart devices. The Raspberry Pi supports a variety of operating systems and comes with multiple interfaces, including GPIO pins, USB ports, and HDMI, making it a highly adaptable tool for numerous applications[1].
Home Assistant
Home Assistant is an open-source home automation platform that enables users to control and automate a wide range of smart devices[2]. It offers a user-friendly interface, extensive device compatibility, and powerful automation capabilities. Home Assistant can run on various hardware, including the Raspberry Pi, and supports integration with numerous smart home products and services, providing a centralized system for monitoring and controlling home environments.
| Figure 2.1 - Raspberry Pi 5 Product page | Figure 2.2 - Home assistant Installation guideline by Taycan |
Home Assistant's core components provide the foundation for integrating, controlling, and automating smart devices:
- Devices and area: Physical hardware with associated entities, providing a higher-level abstraction for managing related functions.
- Entities: function/sensor of a device. Helps to monitor physical properties of the area (Figure 2.3).
- Integrations: Modules connecting Home Assistant to various smart devices and services, expanding its capabilities.
- Automations: Custom rules and actions triggered by specific events, like turning on lights when motion is detected.
- States: The current condition or value of an entity (e.g., the temperature reading from a sensor)(Figure 2.4).
Figure 2.3 - Zigbee device: area, manufacturer and model & entities |
Figure 2.4 - Zigbee device: state |
- Add-ons: Additional applications or services like Node-RED for advanced automation, InfluxDB for data storage, and Grafana for visualization.
- Services: Actions performed on entities or devices, like turning a light on or off.
Zigbee
Zigbee is a wireless communication protocol designed for low-power, low-data-rate, and close-proximity applications (Figure 2.5). It is widely used in home automation, smart lighting, and other IoT (Internet of Things) applications[3]. Using Zigbee with a Raspberry Pi for Home Assistant involves setting up a Zigbee gateway (or hub) that connects to Raspberry Pi, allowing Home Assistant to communicate with Zigbee devices.The first step is setting up the necessary integration for zigbee.
3. Set up
- Home assistant
- Integrate own Wifi AP/Router
- Setup MQTT
- Setup Node-RED
- Setup INfluxDB
- Setup local Tuya extension
(with Pet Feeder(Tuya), Tuya lamp, Zigbee Motion + Temperature sensors as components of the system)
1)Installation of Home Assistant on Raspberry Pi
- ☝Installation guide can be found at Home Assistant Installation (guide was written using Home Assistant version 2024.5.x.)
- Credits go to Taycan.
2)Wifi AP integration
- In HA settings, select “Automatic” on both IPv4 & IPv6
- Connect to your Wifi Access point
3)MQTT setup
- Go to “Settings”→Add-ons→Add-on store→Find the “Mosquito broker” add-on and click it→Click “Install”
- How to use. The add-on has a couple of options available.
To get the add-on running:
- Start the add-on.
- Have some patience and wait a couple of minutes.
- Check the add-on log output to see the result.
Create a new user for MQTT via your Home Assistant's frontend Settings → People → Users, (i.e. not on Mosquitto's Configuration tab).
Notes:
- This name cannot be homeassistant or addons, those are reserved usernames.
- If you do not see the option to create a new user, ensure that Advanced Mode is enabled in your Home Assistant profile.
- To use the Mosquitto as a broker go to the integration page and install the configuration with one click:
- Navigate in your Home Assistant frontend to Settings → Devices & Services → Integrations.MQTT should appear as a discovered integration at the top of the page.
- Select it and check the box to enable MQTT discovery if desired, and hit submit.
- If you have old MQTT settings available, remove this old integration and restart Home Assistant to see the new one.
Node-RED & INfluxDB & Local Tuya are installed in a similar to MQTT fashion
4. Tuya devices: pet feeder, lamp
Tuya is a global IoT platform that provides smart device solutions, enabling easy integration and control of various smart products. In this project, we use Tuya-controlled pet feeder and lamp, which can be managed through the Home Assistant platform. Finally, two tuya devices were added: pet feeder and LDV_Lamp, which we can switch on/off using “controls” and check any state changes in “logbook” (Figure 4.1).
Figure 4.1 - Tuya devices: Pet Feeder and lamp |
Pet Feeder: The smart pet feeder allows for scheduled feeding times and portion control, ensuring that pets are fed on time, even when the owner is not home. It can be controlled remotely through Home Assistant, providing convenience and peace of mind. Number of portions can be changed by using the control buttom (Figure 4.2).
Figure 4.2 - Pet Feeder control |
Adding a Tuya Pet Feeder to Home Assistant (made by Taycan): https://student-wiki.eolab.de/doku.php?id=amc:ss2024:bird_feeder:ha_installation
Lamp: The Tuya smart lamp offers remote control and automation capabilities, allowing users to adjust lighting conditions based on time of day, occupancy, or other triggers. It enhances home comfort and energy efficiency. Controll buttom allows to turn on/off the lamp (Figure 4.3).
Adding a Tuya Lamp to Home Assistant
To add a Tuya lamp to Home Assistant, start by setting up a Tuya account and app. Download the Tuya Smart or Smart Life app from the App Store or Google Play, and create an account or log in if you already have one. Add the lamp to the app by putting it in pairing mode ( by turning it on and off a few times or holding a button) and following the in-app instructions.
Next, configure Home Assistant by accessing it via a web browser. Navigate to the Integrations section under Configuration and click the “+ Add Integration” button. Search for and select Tuya from the list. Enter your Tuya app credentials (email and password), select the appropriate Tuya region, and input the API key and secret from the Tuya IoT Platform.
The most challenging point in the configuration of devices is to find a local key, usually most necessary data is filled in automatically. To find the local key follow through these steps: developer tuya platform/cloud/Api explorer/device management/ query devices in project.
Home Assistant will then connect to your Tuya account and sync your devices. Ensure the Tuya lamp appears in Home Assistant by checking the Entities section under Configuration.
5. Zigbee devices: motion and temperature sensors.
This setup integrates a Zigbee motion sensor (Figure 5.1) and a temperature/humidity sensor (Figure 5.2) for smart home automation. The motion sensor is used to create scenes, such as activating a pet feeder, while the temperature/humidity sensor helps practice data collection with InfluxDB and Home Assistant (HA).
Two devices are listed: _TZ1800_fcdjzz3s TY0202, located in the living room, with 96% battery, and _TZ3000_xr3htd96 TS0201, with 100% battery (Figure 5.3). Both are integrated with Zigbee Home Automation.
The dashboard displays sensor data, including motion detection (Figure 5.4), humidity at 61.6%, and temperature at 23.9°C (Figure 5.5). Configuration settings and firmware updates are available, and the logbook records motion events and button presses.
6. Node-red: main nodes. Automatisation: pet feeder and motion sensor. E-mail Node Configuration.
Node-RED is a powerful, flow-based development tool for visual programming. Node-RED uses a visual editor to create “flows” by connecting nodes.
Node-RED excels in home automation by enabling complex workflows:
- Device Control: Manage lights, sensors, and appliances.
- Data Processing: Collect and visualize sensor data.
- Automation Logic: Implement rules for automated actions, like scheduling a pet feeder.
- Notifications and Alerts: Set up alerts via email or SMS.
- Third-Party Integration: Connect with external services like weather APIs and voice assistants.
Pet feeder and motion sensor configuration
Task: to trigger the pet feeder when motion is detected. Firstly, node-red was installed.
This Node-RED flow diagram shows a simple setup for a pet feeder system using a state node, a debug node, and a call service node (Figure 6.1).
- MotionSensor (state node): This node represents a motion sensor that detects movement. It is currently off (as indicated by the red circle and the text “off at: Jul 2, 13:51”) (Figure 6.2).
Figure 6.2 - Configuration of state node |
- debug 2: This node is connected to the MotionSensor node and is likely used to output debug information to the debug pane in Node-RED. It helps in monitoring the data being passed from the motion sensor.
- feed (call service node): This node is connected to the MotionSensor node as well and represents the pet feeder mechanism. When the motion sensor detects movement, it triggers this node to activate the feeder (Figure 6.3).
Figure 6.3 - Configuration of call service node |
The flow works as follows:
- When the MotionSensor detects motion, it sends a signal to both the debug node and the feed node.
- The debug node logs this event for monitoring and troubleshooting.
- The feed node activates the pet feeder mechanism to dispense food.
Test video with cat: https://youtube.com/shorts/Tk14my7ZAQo?feature=share
Lamp and motion sensor
The next Node-RED flow diagram (Figure 6.4) is designed to control a light based on motion detection and inactivity. The components are as follows:
- MotionSensor (state node): This node detects motion and is currently off (indicated by the red circle and “off at: Jul 2, 13:51”).
- debug 1: This node is used for debugging purposes, outputting messages to the debug pane.
- Light (call service node): This node represents a light that will be turned on when motion is detected.
- NoMotion5min: This node detects if there has been no motion for 5 minutes.
- TurnOffLightDueInactivity (call service node): This node turns off the light if no motion is detected for a certain period.
- delay 5s: This node introduces a 5-second delay before processing further actions.
Test video with cat:
Email Node Configuration
This Node-RED flow is set up to send an email notification when the state of a device changes (e.g., a lamp or pet feeder) (Figure 6.5).
- State Change Node: add a state_changed node to detect changes in a device (e.g., a lamp).
- Email Node Configuration (Figure 6.6):
- Add and configure an email node to send notifications.
- Set the recipient, SMTP server (smtp.gmail.com), port (465 for SSL or 587 for TLS), and sender's credentials (Figure 6.7).
ATTENTION: if it doesn’t work, check google account security settings!
Test video with cat: https://youtube.com/shorts/93OIb3B-sbU?feature=share
7. InfluxDB: database. Graphics
InfluxDB is a special type of database designed to handle and store data that changes over time, known as time-series data.
- Efficient Data Storage: Stores large amounts of sensor data efficiently.
- Fast Data Handling: Quickly processes and stores data from many sensors at once.
- Powerful Analysis: Easily analyze and query data to find trends and patterns.
- Great Visualization: Create real-time and historical dashboards with tools like Grafana.
- Scalable: Handles increasing amounts of data as your smart home grows.
- Automatic Data Management: Automatically manages old data to save space.
- Customizable: Tailor storage and queries to fit your specific needs.
- Strong Community Support: Lots of resources and plugins available.
- Open Source: Free to use and modify as needed.
Steps to Connect InfluxDB to Home Assistant
- Install the InfluxDB Add-on
- Start the Add-on
- Access the InfluxDB Web UI (Figure 7.1)
Figure 7.1 - InfluxDB: open WEB UI |
- Configure Home Assistant to Use InfluxDB: create the database and user in InfluxDB, after open the configuration.yaml file in HA, write configuration code (according to your data) (Figure 7.2).
Figure 7.2 - Configuration code for database InfluxDB |
For example, we can observe temperature and humidity (Figure 7.3) (data from the sensor) changing through the day and plot the diagram (Figure 7.4).
Figure 7.3 - InfluxDB: choosing values |
Figure 7.4 - InfluxDB: humidity diagram |