This is an old revision of the document!


Home Assistant using MQTT

Student: Frâncu Andrei
Video:
Project archive:

1. Objective

The main objective of this project is the implementation of a home assistant based on MQTT. The main hardware component is the Raspberry Pi board which will host the Home Assistant server along with the Mosquitto broker and will run the Zigbee2MQTT gateway application and the automation scripts. The principal features are the automation of smart plugs to turn on/off at the desired hours, a wake-up light using smart lights and different environment presets to set the desired light and music (ex. workout, party, study). All smart devices can also be controlled manually from the Home Assistant web server or mobile application.

*Note: Home Assistant is an open-source software for home automation and throughout this documentation it is referred to using uppercase initials or the HA acronym. The lower case notation: “home assistant” refers to the scope of this project.

2. Hardware description & implementation

  • Raspberry Pi 4B
    • This the main hardware component of the project. It is used to host the Home Assistant server and the Mosquitto broker and to run the Zigbee2MQTT gateway application and the automation scripts.

 Raspberry Pi 4B Board

  • Sonoff Zigbee Dongle
    • The dongle is used as a hardware gateway, allowing the control of the Zigbee smart devices using MQTT.

 Sonoff Zigbee Dongle

  • Smart devices
    • 2 x Sonoff S26 smart plug

 Sonoff S26 smart plug

  • 2 x Ikea Tradfri LED E27 bulbs

 Ikea Tradfri LED E27 bulbs

  • Sony Bluetooth speaker
    • The speaker is used for the environment preset feature of the home assistant.

 Sony Bluetooth speaker

  • Implementation:

ADD HARDWARE PIC

3. Software description & implementation

Eclipse Mosquitto is an open source message broker that implements the MQTT protocol. The role of the broker is to route the published messages to the subscribed clients.

Home Assistant is an MQTT supervisor. It offers a visual interface for the state of the integrated smart devices and updates it accordingly, when a message is published on the corresponding topic. All the devices can be grouped and accessed through a customizable dashboard. The Home Assistant software also allows the users to create automations using the application. In this project, HA is only used as a visual interface and to activate the different environment presets.
ADD HA DASHBOARD PIC

The widgets that Home Assistant offers to customize your dashboard are called cards. Each card can have one or more devices attached to it. To activate the environment presets, I created a virtual switch device that publishes an MQTT message on a given topic when toggled and attached this entity to a button card.

ADD BUTTON CARD AND YAML CODE PIC

Zigbee2MQTT is a nodejs Gateway application that connects Zigbee networks to MQTT networks. It allows the usage of a single unified bridge for all the connected Zigbee devices instead of each vendor's bridge. It currently supports 2640 devices from 351 different vendors.

Eclipse Paho MQTT is a Python library that provides a client class which allows the user to connect to a broker and publish and subscribe on different topics. In this project I've used paho-mqtt to implement all my automation scripts:

  • The turn smart plugs on/off scripts are simple scripts that create a client which publishes “ON”/“OFF” on the smart plug state topic. The scripts are ran using the cron job scheduler at the given hours (i.e. in the morning and at night).
  • The wake-up light script increments the value of the published LED brightness every minute in order to create a sunrise effect. After the maximum brightness value is reached the user has to manually turn of the light from the HA application, similar to an alarm clock. The script is started using the cron scheduler, some time in the morning and it waits until there is one hour to sunrise to publish the first brightness value.
  • The environment preset scripts implement a client that waits for a message on a topic corresponding to each preset. After receiving it, the on_message callback is invoked which publishes a value for the LED brightness and color and opens a YouTube radio page, depending on activated environment preset.

ADD CODE FOR SCRIPTS

4. Challenges

scheduler ⇒ device blocking
20 msgs buffer

5. Conclusions

6. Resources

iothings/proiecte/2022/home_assistant_using_mqtt.1674140663.txt.gz · Last modified: 2023/01/19 17:04 by andrei.francu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0