Thank you @BenoitS for the great integration. You saved me countless hours!
I am not really familiar with HA (as I just moved from OpenHAB) but I wanted to share the following steps I used to create an Addon from this project to automatically run the python scripts. I am most likely not following any best practice or anything but this works for me…
- SSH to HA (or use Samba)
- Create a new folder under /addons called HAAddOnDiematic_to_MQTT
- Within that folder, add a new file called DockerFile and containing the following
ARG BUILD_FROM
FROM $BUILD_FROM
# Install requirements for add-on
RUN \
apk add --no-cache \
python3
RUN python3 -m ensurepip
#RUN pip3 install --no-cache --upgrade pip setuptools
RUN pip3 install pytz
RUN pip3 install paho-mqtt
# Copy data for add-on
COPY run.sh /
RUN chmod a+x /run.sh
COPY src/ /
CMD [ "/run.sh" ]
- Add a new file called config.yaml containing the following:
name: "Diematic 3"
description: "Diematic 3"
version: "1.0.0"
slug: "diematic_3"
init: false
arch:
- aarch64
- amd64
- armhf
- armv7
- i386
startup: before
- Add a new file called run.sh and containing the following:
#!/usr/bin/with-contenv bashio
python3 Diematic32MQTT.py
-
copy the “src” folder of @BenoitS project
-
in the “src/conf” folder, update the logging.conf file as follows (this is to output the log in stdout so that it shows in the HA addon logs):
[loggers]
keys=root
[logger_root]
level=WARNING
#handlers=timedRotatingFileHandler
handlers=streamHandler
[formatters]
keys=timedRotatingFormatter
[formatter_timedRotatingFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=
[handlers]
#keys=timedRotatingFileHandler
keys=streamHandler
[handler_timedRotatingFileHandler]
class=handlers.TimedRotatingFileHandler
formatter=timedRotatingFormatter
args=('./log/log.out', 'W6', 1, 5, None, False, False)
[handler_streamHandler]
class=StreamHandler
formatter=timedRotatingFormatter
args=(sys.stdout,)
-
Optional: update the polling period in the Diamatic32MQTT.conf file to 60 (every 10 seconds was too frequent in my case and made the connection crash from time to time).
-
Once this is done, restart HA and this new local “Addon” should show up. The Addon can then be installed and started.
Hope this helps.
Note: as a side unrelated note, it took me a while to figure out that the BrokerHost is core-mosquitto and not localhost…