Package: hass-mqtt-things
Home Assistant MQTT ThingsPython library for rapid integration of Things with Home Assistant through MQTT.DemonstrationIf you have a Home Assistant instance reachable, and have a MQTT in place
(with discovery activated), you can easily use this library and the provided
examples show you how to proceed.From the source codeA quick way of starting from scratch (by cloning this project and creating a
virtual environment) is shown below:$gitclonehttps://github.com/alexbarcelo/hass-mqtt-things.git
Cloninginto'hass-mqtt-things'...
remote:Enumeratingobjects:(...)(...)$cdhass-mqtt-things
$python3-mvenvvenv
$sourcevenv/bin/activate(venv)$pipinstall--upgradepip
Collectingpip(...)Installingcollectedpackages:pip(...)(venv)$pipinstall-e.
Obtainingfile:(...)(...)Successfullyinstalledgetmac-0.8.3hass-mqtt-things-0.3.0paho-mqtt-1.6.1(venv)$exportMQTT_HOST="hassio.local"(venv)$exportMQTT_USERNAME="user"(venv)$exportMQTT_PASSWORD="password"(venv)$cdexamples(venv)$./interactive_switch.py
Enteringaninfiniteloop,Ctrl+Cmultipletimestoexit.
Connectedwithresultcode0Togglingstate.Previousstate:False
Togglingstate.Nextstate:True(...adinfinitum)NOTE: I have put an explicit upgrade for thepippackage because I am using the "new"
setup.cfg approach, which doesn't work with certain old versions.You will need to change theexportlines and adapt them to your MQTT setup
(set up your host, username and password information).Once you have followed the above steps, a newAwesomest Switchshould have appeared
and it will toggle every 5 seconds.With PyPI packagesAssuming you are in a proper environment (e.g. a Pythonvirtual environment)
you can easily install this package and try a demo from theexamplesfolder:$pipinstallhass-mqtt-things
Collectinghass-mqtt-thingsDownloadinghass_mqtt_things-0.2.0-py3-none-any.whl(10kB)(...)Successfullyinstalledgetmac-0.8.3hass-mqtt-things-0.2.0paho-mqtt-1.6.1
$curl-Ohttps://raw.githubusercontent.com/alexbarcelo/hass-mqtt-things/main/examples/interactive_switch.py
$exportMQTT_HOST="hassio.local"$exportMQTT_USERNAME="user"$exportMQTT_PASSWORD="password"$chmod+xinteractive_switch.py
$./interactive_switch.py
Enteringaninfiniteloop,Ctrl+Cmultipletimestoexit.
Connectedwithresultcode0Togglingstate.Previousstate:False
Togglingstate.Nextstate:True(...adinfinitum)You will need to change theexportlines and adapt them to your MQTT setup
(set up your host, username and password information).Once you have followed the above steps, a newAwesomest Switchshould have appeared
and it will toggle every 5 seconds.More examplesCheck theexamples folder. You will find some more examples there.Use casesThis library is aimed to Python developers that are using Home Assistant for their
home automation projects and wants to be more agile in their deployment. The foundation
for this project is theMQTT Discoverymechanism of Home Assistant.Some use cases where this library can become handy:GPIO control for a Raspberry Pi.Monitor something on your desktop PC (temperature, mount points, whether a certain application is running...).Management of serial connections (for example: video projectors with serial input).Alarm control panels on a Raspberry Pi.At this moment both the Switch and Light component are done. I plan to add all
devices that are supported by the MQTT Discovery mechanism, but my personal use
cases will drive the roadmap (unless there are Pull Requests or specific
petitions in this repository).