Skip to content

A lighweight MQTT python script for toggling a Zigbee switch based on a Zigbee remote switch

License

Notifications You must be signed in to change notification settings

voblers/mqtt-remote-switch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQTT Toggle Switch Automation

This repository contains a Python script and a Dockerfile to create a Docker image for a simple MQTT toggle switch automation. The application uses the Paho MQTT library to interact with an MQTT broker and toggle a switch based on incoming messages from a remote switch.

I have developed a simple application to ensure smooth and uninterrupted operation between a wall switch and a remote switch. Binding them together via Zigbee is not possible, and using a Home Assistant automation introduces the risk of automation not working during updates or system failures. This script runs on the same machine as the Zigbee network, minimizing downtime risks.

Table of Contents

Prerequisites

Ensure you have Docker installed on your system.

Docker Image

The Docker image is configured to run the MQTT Toggle Switch application. It includes the necessary dependencies and sets up the environment for the Python script.

To build the Docker image:

docker build -t mqtt-toggle-switch .

To run the Docker container:

docker run -e MQTT_USERNAME=<your_username> -e MQTT_PASSWORD=<your_password> -e MQTT_REMOTE_TOPIC=<remote_topic> -e MQTT_SWITCH_TOPIC=<switch_topic> mqtt-toggle-switch

Usage

The ToggleSwitch.py script subscribes to specified MQTT topics and toggles a switch based on incoming messages. It continuously listens for messages in the MQTT broker and reacts accordingly.

Configuration

The behavior of the MQTT Toggle Switch can be customized using environment variables in the Dockerfile. Here are the available configuration options:

  • MQTT_HOSTNAME: MQTT broker hostname (default: mqtt).
  • MQTT_PORT: MQTT broker port (default: 1883).
  • MQTT_USERNAME: MQTT broker username (required).
  • MQTT_PASSWORD: MQTT broker password (required).
  • MQTT_REMOTE_TOPIC: MQTT topic to subscribe to for remote actions (comma-separated if multiple).
  • MQTT_REMOTE_ACTION: Comma-separated list of remote actions to trigger the switch.
  • MQTT_SWITCH_TOPIC: MQTT topic to publish switch actions (comma-separated if multiple).
  • MQTT_SWITCH_ACTION: JSON payload to send when toggling the switch.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A lighweight MQTT python script for toggling a Zigbee switch based on a Zigbee remote switch

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published