Logo

dev-resources.site

for different kinds of informations.

Building a Smart Heater Controller with Python, Docker, and Bluetooth #1

Published at
12/28/2024
Categories
raspberrypi
python
Author
mecorre1
Categories
2 categories in total
raspberrypi
open
python
open
Author
8 person written this
mecorre1
open
Building a Smart Heater Controller with Python, Docker, and Bluetooth #1

Chapter 1: Getting Started

Why Build a Smart Heater Controller?

I recently set out to create a smart heating controller for my Terma MOA Blue heaters using Python, Docker, and Bluetooth Low Energy (BLE).

The Problem

There’s currently no native way to communicate between Home Assistant (HA) and my heaters.

The Goal

I needed precise control over the heaters for my seasonal rental property to:

  • Optimize energy consumption—Prevent guests from setting temperatures too high or leaving heaters on when they check out.
  • Remotely manage settings—Avoid costly heating bills without physically visiting the property.
  • Enable automation—Integrate with HA in the future for better scheduling and monitoring.

This post is the first chapter in a series where I’ll walk you through the process—from setting up the Raspberry Pi and Docker to writing Python scripts for direct Bluetooth control.


About the Terma MOA Blue Heaters

The Terma MOA Blue is a Bluetooth-enabled heating element designed for electric radiators and towel warmers.

Key features:

  • Multiple Modes:
    • Manual (Room Temperature)
    • Manual (Heating Element Temperature)
    • Schedules and Timers
  • Temperature Control:
    • Supports precision adjustments with 0.1°C steps.
  • Bluetooth Low Energy (BLE):
    • Allows remote control via mobile apps or custom integrations.

While these heaters work seamlessly with the manufacturer’s mobile app, I wanted more flexibility by integrating them directly into a custom Python/Docker setup.


Special Thanks to the Home Assistant Community

I want to give a big shoutout to the Home Assistant Community for laying the groundwork and sharing insights about connecting to these heaters using BLE.

Their discussions helped clarify how the Bluetooth characteristics are structured and inspired many of the techniques implemented in this project.


Project Overview

We'll cover:

  1. Setting up the Raspberry Pi with Docker.
  2. Writing a Python script using BLE to connect to the heater.
  3. Encoding and decoding temperature data and heater modes.
  4. Packaging the app in Docker for easy deployment.
  5. Planning for future features like multiple heater support and automation.

Setting Up the Raspberry Pi

I decided to use a Raspberry Pi as the central controller for this project. Here's how I set it up:

  1. Flash Raspberry Pi OS: Download and install the latest Raspberry Pi OS image.
  2. Enable SSH and Wi-Fi: Configure SSH access and Wi-Fi credentials during flashing to enable remote development.
  3. Install Docker: Docker makes deployment and testing easier.

Commands:

sudo apt update
sudo apt install -y docker.io
sudo usermod -aG docker $USER
Enter fullscreen mode Exit fullscreen mode
  1. Test Docker Installation:
docker --version
docker run hello-world
Enter fullscreen mode Exit fullscreen mode

This verifies Docker is installed and running properly.


Setting Up Git and Remote Access

To simplify updates to the code, I set up SSH keys and Git for remote access from my PC.

Key Steps:

  1. Generate an SSH key pair:
ssh-keygen -t ed25519 -C "[email protected]"
Enter fullscreen mode Exit fullscreen mode
  1. Add the public key to GitHub.
  2. Clone the repository:
git clone [email protected]:<username>/<repo>.git
Enter fullscreen mode Exit fullscreen mode

Repository Link

You can check out the full source code in my GitHub repo:

👉 GitHub - ha-hudsonread-heater-control

Feel free to fork it, suggest improvements, or report any issues!


Controlling the Heater with Bluetooth

The Terma MOA Blue heater communicates over Bluetooth Low Energy (BLE), so I used the Bleak library in Python to handle the connection.

Key features implemented so far:

  • Read and Write Temperatures: Using UUID-based characteristics.
  • Mode Control: Switching between Off, Manual (Room Temp), and Manual (Heating Element Temp).
  • Dynamic Updates: Control temperatures without affecting modes.

Current State and Next Steps

Right now, the controller can:

  • Connect to the heater.
  • Read the current temperature and target temperature.
  • Switch modes and adjust temperatures independently.

Next Steps:

  • Add support for multiple heaters.
  • Enable automation via integration with Home Assistant or similar platforms.

Follow Along

Stay tuned for Chapter 2, where I’ll dive into the Python code, explain how BLE encoding and decoding works, and share insights from debugging Bluetooth connections.

We’ll also cover manual pairing and connection commands using bluetoothctl for anyone interested in a deeper look into BLE debugging.

Don’t forget to ⭐️ the GitHub repo and let me know in the comments what features you'd like to see added next!

raspberrypi Article's
30 articles in total
Favicon
Nextcloud on Raspberry Pi - Fedora + Podman Quadlets
Favicon
Vecchio RaspberryPi, Nuova HomeLab!
Favicon
Building a Smart Heater Controller with Python, Docker, and Bluetooth #3
Favicon
Building a Smart Heater Controller with Python, Docker, and Bluetooth #2
Favicon
Building a Smart Heater Controller with Python, Docker, and Bluetooth #1
Favicon
How to Install Docker on Raspberry Pi
Favicon
How to SSH into a Raspberry Pi?
Favicon
node.js and docker on raspberry
Favicon
Open source mealie type docker container for recipes
Favicon
Deploy a Node.js Application Using MySQL and Prisma on a Raspberry Pi
Favicon
Getting started with Nix and Nix Flakes
Favicon
How to edit boot config Raspberry Pi 5 USB?
Favicon
Weather Dashboard with 5-Day Forecast and Wi-Fi Menu
Favicon
The Intelligent Disaster Management System with Alternative Energy and AI-Powered
Favicon
How I Leverage Raspberry Pi as a DevOps Engineer
Favicon
How to self-host MongoDB on a Raspberry Pi 4
Favicon
How to Turn a USB-Only Printer into a Wireless Printer Using CUPS and a Raspberry Pi
Favicon
Raspberry Pi project: Install project management software
Favicon
Running Raspberry Pi OS in a Docker Container
Favicon
The Smart House Experience: Crafting Innovation with a Raspberry Pi
Favicon
From Mobile Simplicity to Pi Complexity
Favicon
Setting Up Home Assistant on a Raspberry Pi 3 Model B
Favicon
Create an AP with Network Manager
Favicon
🏠 GPT Home 🤖💬 an Open-source Raspberry Pi Home Assistant!
Favicon
Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi
Favicon
How to Build Your Own Website with a Raspberry Pi: An Entertaining Guide
Favicon
How to self-host Postgres Database on Linux
Favicon
[K8s] A Complete Series of Articles on Kubernetes Environment Locally
Favicon
How to control a Noctua NF-A20 PWM fan from Raspberry Pi (OFF or 20%-100%)
Favicon
Rockchip SoC Roadmap for AI & Vision

Featured ones: