ismarslomic / rpi-mqtt

Python daemon collecting RPI sensor data and publishing to MQTT and integrating with Home Assistant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Raspberry Pi - Mqtt pub/sub client

Python Modules

  • mqtt.pub - utilities for publishing Rpi sensors to MQTT topics
  • mqtt.sub - utilities for subscribing to MQTT topics
  • sensors - modules to read Rpi sensor data

Installation

# Clone this git repo
git clone https://github.com/ismarslomic/rpi-mqtt.git
cd rpi-mqtt

# Create python virtual environment (required in Bookworm)
python3 -m venv --system-site-packages .venv
source .venv/bin/activate

# Install poetry
pip3 install poetry

# Disable keyring, otherwise poetry will be hanging
keyring --disable

# Install required python packages defined in pyproject.toml
poetry install --without dev --no-root

Usage

# Run python program
cd src
python3 -m sensors.main -s /Users/john/rpi-mqtt/settings.yml

You can provide user settings by providing a settings.yml file according to the JSON schema settings.json or markdown settings.md.

Example settings.yml:

mqtt:
  # The hostname or IP address of the MQTT broker to connect to. Default 127.0.0.1.
  hostname: 127.0.0.1
  # The TCP port the MQTT broker is listening on. Default: 1883.
  port: 1883
  # Override the default sensor_name (rpi-<hostname>) with own name of sensor to be used in MQTT topic name.
  sensor_name: my-macbook

script:
  # The interval to update sensor data to MQTT broker. In seconds. Default: 60.
  update_interval: 120
  # The log level for the python script. Default: INFO.
  log_level: DEBUG

# Override default settings by enabling (true) or disabling (false) sensors you want to be published to MQTT broker
sensors:
  boot_loader: False
  cpu: True
  disk: True
  fan: False

Development

Read DEVELOPMENT.md for more information about how to contribute.

About

Python daemon collecting RPI sensor data and publishing to MQTT and integrating with Home Assistant


Languages

Language:Python 100.0%