A simple python app running in docker for reading w1 type sensors (such as DS1822, DS18S20 & DS18B20), and publish via MQTT. Autodiscovery for Home Assistant is baked in.
The default base image is balenalib/raspberrypi3-python
, which is suitable for raspberrypi3/4:
docker-compose build
Or, specify a different base image, for example a raspberrypi zero:
docker-compose build --build-arg BASE_IMAGE=balenalib/raspberry-pi-python
You are required to specify at least two environment variables. Export these in your shell before
running the docker-compose up
command.
In the simplest configuration, an MQTT broker and an MQTT topic are required:
MQTT_HOST=<hostname or IP>
MQTT_TOPIC_ROOM=kitchen
And in Home Assistant autodiscovery mode:
MQTT_HOST=<hostname or IP>
HA_DEVICE=rpi4
HA_SENSOR_NAME='Living Room'
HA DEVICE
is required in Home Assistant to group the sensors against a device.
HA_SENSOR_NAME
is the friendly name shown in the Home Assistant UI.
NOTE: in this configuration the MQTT topic is derived from the HA_SENSOR_NAME
setting.
And to start the app:
docker-compose up
Setting the DEBUG
environment var will cause sensor readings to be published to the docker logs.
Additionally ipdb
is installed if you want to debug the python code.
The temperature/humidity messages are published on:
home/<MQTT_TOPIC_ROOM>/temperature
home/<MQTT_TOPIC_ROOM>/humidity