Industrial IoT (IIoT) & Edge Computing

Home Assistant - Connecting with a PLC Controller - Smart Home automation system

MSc. Matthew Kurantowicz 13 min read Updated

What Will You Find in This Article?

  • Integration of Smart Home Devices
  • Web Panel for Installation Management
  • Mobile Application for Your Smartphone
  • Communication with PLC Controllers
  • CODESYS - A Tool for Creating Control Systems
  • Configuring Modbus in Home Assistant (NodeRed)
  • Data Exchange Between CODESYS and Home Assistant

PLC Controller in Your Automation Setup

How can you automate:

  • Your home?
  • An office building?
  • The operation of renewable energy installations?

Choose the appropriate PLC controller: WAGO, Beckhoff, or another. Then launch the CODESYS environment and start programming. In addition to the user program for the PLC, you will also need to create a visualization. But what if you also need a mobile app?

PLC controllers provide visualization options, typically for HMI panels or a basic web visualization for servicing. Today, web panels (Dashboards) and mobile apps are the standard. Can you do it yourself? Yes! I have a solution for you.

I have reviewed hundreds of solutions in this area. What caught my attention is Home Assistant! It has countless integrations and easily connects to PLCs. You retrieve relevant data and build an elegant panel in your web browser, which you can also display on your smartphone.

What You Can Achieve with Home Assistant:

  • Data visualization on a web panel
  • A mobile app based on the web panel
  • Basic automation in NodeRed
  • Scripts in Python and YAML
  • Integration with popular services like Google and Apple
  • Communication with PLC controllers
  • And much more!

What Is Smart Home Integration?

Smart home integration means connecting devices from different brands and technologies into one home system that can be controlled from a single app and can run automations across all of them. Without integration, every smart device has its own app: one for the smart thermostat, one for the smart lock, one for the security camera and another for the lights. With integration, a single event, such as arriving home, can unlock the door, switch on the lights, open the garage door and set the heating.

Smart home products connect to each other in three main ways:

  • Ecosystems and voice assistants - Amazon Alexa, Google Assistant (Google Home and Google Nest devices) and Apple Home link compatible devices from many manufacturers.
  • Wireless protocols - Wi-Fi, Zigbee, Z-Wave, Bluetooth and Thread. The Matter standard was created to make smart home devices work across ecosystems.
  • A smart home hub - a central controller that speaks many protocols and runs the automations locally. Home Assistant is one of the most popular open-source smart home platforms of this kind.

For an automation engineer there is one more option that consumer guides rarely mention: a PLC controller as the core of the smart home system. This is the approach we describe in this article.

Smart Home Integration with a PLC: Why It Makes Sense

Consumer smart home products are easy to install, but most of them depend on wireless links, batteries and cloud services. A PLC works the other way around: wired inputs and outputs, deterministic logic and no dependence on the internet. Combining both gives you the best of each world:

LayerTypical devicesRole in the system
PLC (CODESYS)Wired buttons, relays, dimmers, valves, temperature sensorsReliable control logic, works even without network or internet
CommunicationModbus TCP, OPC UA, MQTTExchange of states and setpoints between PLC and Home Assistant
Home AssistantRaspberry Pi, mini PC, NAS or virtual machineDashboards, mobile app, automations, history and notifications
Smart devicesSmart thermostat, smart lock, security camera, smart doorbell, smart plugConsumer devices integrated through Home Assistant
Voice assistantsAmazon Alexa, Google Assistant, Apple HomeVoice control of entities exposed by Home Assistant

In this architecture the PLC controls everything that must always work: lighting circuits, shutters, heating zones, pumps, ventilation and the inverter logic of a renewable energy installation. Home Assistant adds the smart home technology on top: dashboards, the mobile app, voice control, notifications and integration of smart home products such as a smart doorbell, smart plugs or smart smoke and carbon monoxide detectors.

Home Assistant - A Home Automation System

Home Assistant is a popular open-source home automation system that allows device control through various communication protocols. One of these protocols is Modbus, a widely used standard for industrial communication. On the other hand, CODESYS is a development tool for creating control systems that support many protocols, including Modbus.

Home Assistant supports a wide range of devices and platforms, allowing for the integration and control of various systems in your home. Whether it’s smart bulbs, thermostats, sensors, cameras, or multimedia devices, Home Assistant offers support for many popular protocols and standards, like Zigbee, Z-Wave, Wi-Fi, Bluetooth, and MQTT. It also allows for creating advanced scenarios and automations. You can set rules and conditions that automatically trigger specific actions based on factors such as time, device status, or motion detection. For example, you can configure automatic lighting adjustment based on external light intensity or play music when you return home.

Where Can You Install Home Assistant?

Home Assistant can be installed on various platforms, providing flexibility and choice for users. Here are some popular ways to install Home Assistant:

  • PC: You can install Home Assistant on a computer running an operating system like Windows, macOS, or Linux. An official version of Home Assistant can be installed on a virtual machine or as a standalone installation.
  • Raspberry Pi: Raspberry Pi is a popular platform for installing Home Assistant. There’s an official version for Raspberry Pi that is easy to install and configure. This requires purchasing a suitable Raspberry Pi model, a microSD card, and installing Home Assistant on the memory card.
  • Docker: Home Assistant can be run in a Docker container, providing isolation and ease of management. Docker is a popular application virtualization tool that enables easy installation and updates of Home Assistant.
  • NAS (Network-Attached Storage): If you have a NAS, it might be possible to install Home Assistant on it. Some popular NAS models, like Synology or QNAP, offer dedicated app packages for Home Assistant installation.
  • Other Platforms: Home Assistant can also be installed on other platforms like Odroid, Intel NUC, and even Android devices.
Sample Home Assistant Control Panel

Example Home Assistant Control Panel

Home Assistant provides several tools for creating a panel, such as Lovelace UI, Configuration Panel, and Lovelace YAML. Lovelace UI (in current Home Assistant versions simply called dashboards) is the recommended tool and offers an interactive editor for easily creating and customizing the panel.

After choosing the panel-building tool, you can add widgets to display information and control devices. For example, you can add a lighting widget that shows the status and allows turning the lights on or off. You can also add widgets for sensors, thermostats, cameras, etc. Widgets can be grouped into different sections or cards to organize the user interface. For instance, you can create a “Living Room” card and add lighting, thermostat, and media widgets to have all these features in one place. You can arrange widgets in different layouts, such as columns, rows, or grids, to customize the panel’s appearance.

Home Assistant offers numerous customization options for the panel's look. You can change colors, fonts, backgrounds, and other visual elements to match your preferences. Icons, graphic backgrounds, and other elements can also be added to give the panel a unique character.

The Home Assistant panel can be used to trigger automations and scenarios. You can add buttons or sliders that initiate specific actions, such as enabling night mode, starting the “Home Cinema” scene, or opening/closing blinds.

Home Assistant allows access to the panel both locally and remotely. You can configure remote access to control your home from anywhere using the mobile app or web interface. Also, make sure the panel is responsive, meaning it looks good and works on various devices like phones, tablets, or computers.

CODESYS - Software for PLC Programming

CODESYS is a comprehensive and popular development environment for programming controllers and automation systems. It’s a full software package for creating, testing, and managing automation applications in industries like manufacturing, construction, or infrastructure.

The primary goal of CODESYS is to simplify the programming of PLCs (Programmable Logic Controllers), used in industrial settings to control and monitor devices and processes. CODESYS provides developers with tools for creating PLC applications, including a code editor, debugger, simulator, and visualization tools.

One of CODESYS’ main strengths is its flexibility. It supports a wide range of communication protocols, such as Modbus, EtherCAT, and OPC UA, enabling integration with various devices and systems. Additionally, CODESYS is hardware-independent and runs on multiple platforms, including different PLC controllers, PCs, operator panels, and embedded devices.

In CODESYS, we need to configure the appropriate Modbus communication protocols. Depending on the CODESYS version, this process may vary, but generally, you need to add the appropriate Modbus library to your project and configure communication parameters like the Modbus device’s IP address, communication port, register addresses, etc. Once Modbus communication is configured in CODESYS, you can read and write data from connected devices.

Connecting CODESYS - Home Assistant

To exchange data between CODESYS and Home Assistant, we will use Modbus register addresses. In CODESYS, we will write the data that we want to make available to Home Assistant into the appropriate registers. Then, in Home Assistant, we will configure entities that will read and update these registers. This can be done using YAML configuration in the Home Assistant configuration file.

Another option is to implement the connection in an additional, manually installed programming environment, namely Node-RED. Node-RED will serve as a bridge between CODESYS and Home Assistant. You will need to configure the Modbus TCP connection in Node-RED to communicate with CODESYS. Next, you will need to create flows in Node-RED that read and write data from the Modbus registers previously configured in CODESYS. Node-RED must be configured to communicate with Home Assistant, which can be achieved using the “Home Assistant Websocket” node. You will also need to create flows that read and write data to Home Assistant. We will use the “call service” node in Node-RED to send data to Home Assistant.

In the case of CODESYS, the built-in Modbus configurator is a tool that allows PLC programmers to easily set up Modbus parameters, such as transmission speed, data format, register types, device addresses, etc., without the need for additional external tools.

To sum up the two options: the YAML route uses the native Modbus integration of Home Assistant, where every coil or register becomes an entity (a switch, a binary sensor or a sensor). The Node-RED route gives you more freedom, because you can process the data in flows before it reaches Home Assistant. In both cases the CODESYS side stays the same: a Modbus TCP configuration with a clear, documented register map.

Data Transfer Between CODESYS (PLC) NodeRED - > (HomeAssistant) via Modbus Protocol

Integrating CODESYS with Home Assistant


Using the Modbus protocol opens up many possibilities for advanced home control. We can use CODESYS functions to create complex control and automation algorithms while leveraging the Home Assistant interface and functionalities for convenient home automation management.

On the graphic below, we show the visualization of a virtual home, simulated using Home I/O software, a program written in CODESYS for automating processes in our home, and a control panel accessible from both a web browser and a mobile application.

Integrating Smart Home Devices with the PLC Through Home Assistant

Once the PLC data is available in Home Assistant, every other integration in Home Assistant can interact with it. A few practical examples:

  • Smart thermostat - a Google Nest or another compatible thermostat sends the setpoint to Home Assistant, and an automation writes it to a Modbus register used by the heating control in the PLC.
  • Smart doorbell and security camera - when someone rings the doorbell after dark, Home Assistant sets a coil in the PLC that switches on the outdoor lighting, and shows the camera image on your phone.
  • Garage door - the garage door opener is controlled by a PLC output with limit switches on the inputs, and Home Assistant shows it as a cover entity with open and close buttons.
  • Smart lock - unlocking the front door can switch the PLC from away mode to home mode, which changes heating and ventilation setpoints.
  • Voice control - lights and scenes controlled by the PLC can be exposed to Amazon Alexa or Google Assistant, so a voice command ends as a Modbus write to the controller.

Home Security and the PLC

A PLC can read door and window contacts, motion detectors and smoke detectors, and Home Assistant can send notifications when something happens. However, a PLC is not a certified intrusion alarm or fire alarm system. For a home security system that protects people and property, use a certified alarm panel and integrate its status into Home Assistant or the PLC, instead of building the security logic yourself.

Pros and Cons of a PLC-Based Smart Home

  • Pros: wired and reliable control, local operation without the cloud, industrial components with a long service life, full freedom in programming the logic.
  • Cons: more planning and cabling than with wireless smart home products, and you need PLC programming skills to build and maintain it.

If you want to learn more about the protocol used in this project, read our complete guide to Modbus, and to start with the PLC side, see what CODESYS is and how it works.

Unlimited Possibilities with PLC (CODESYS) and Home Assistant

Automation spans many industries. Whether you work with smart buildings, industrial machinery, or renewable energy installations, you’ll need a reliable PLC controller and meet your clients' or boss's requirements. Market demands are changing rapidly. If you want to stay up-to-date, consider using the latest technologies in your automation projects.

Below, you’ll find a list of practical applications for the knowledge shared in this article.

Building Automation (Smart Home):

  • PLC Controller on Codesys:
    • Control program in ST language
    • Modbus or OPC UA communication
    • Data collection from sensors
    • Control over lighting, temperature, alarms, etc.
    • Management of renewable energy installations
  • Home Assistant:
    • Data visualization on a web panel (Dashboard)
    • Mobile app for Android and Apple
    • Multi-protocol communication

Renewable Energy Installations:

  • Home Assistant:
    • Mobile app for renewable energy systems
    • Integration of inverters
    • Energy storage monitoring
    • Sunlight sensors
    • Energy consumption forecasting
  • PLC Controller on Codesys:
    • Switching between on-grid and off-grid installations
    • Reading data from inverters
    • Programming in ST language

Smart Home Integration with Home Assistant and a PLC - FAQ

What is smart home integration?

It is connecting smart home devices from different manufacturers and technologies into one system, so they can be controlled from one app and work together in automations.

How do smart home products connect to each other?

Through wireless protocols such as Wi-Fi, Zigbee, Z-Wave and Thread, through ecosystems like Alexa, Google Home and Apple Home, or through a smart home hub such as Home Assistant. A PLC can join the system through Modbus TCP, OPC UA or MQTT.

Can Home Assistant communicate with a PLC?

Yes. Home Assistant has a built-in Modbus integration, and with Node-RED or MQTT you can connect it to almost any PLC that supports these protocols, including controllers programmed in CODESYS.

Why use a PLC in a smart home instead of only smart devices?

A PLC gives you wired, deterministic control that keeps working without the internet, and it can handle many inputs and outputs in one device. Smart devices and Home Assistant then add the user interface, voice control and integration with consumer products.

Create a Mobile App Together with Us

In summary, integrating CODESYS with Home Assistant using the Modbus protocol allows for advanced control system integration with a flexible home automation system. This enables the creation of intelligent solutions that combine the power of CODESYS programming with the flexibility of Home Assistant.

Thank you for reading! If you want to write the PLC side of such a project yourself, start with our Structured Text programming in CODESYS course.

Author MSc. Matthew Kurantowicz

The ControlByte team - automation engineers who teach PLC programming on real projects.

Online courses

Want to program PLCs in practice?

Siemens, CODESYS, communication and safety courses with a certificate and instructor support. Start with a free mini-course.

See courses
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare