No project description provided
Project description
Table of Contents
hass-mqtt-devices
A python 3 module that takes advantage of HA(Home Assistant('s MQTT discovery protocol to create sensors without having to define anything on the HA side.
Using MQTT discoverable devices lets us add new sensors and devices to HA without having to restart HA. This module includes scripts to make it easy to create discoverable devices from the command line if you don't want to bother writing python.
Supported Types
Binary Sensors
Usage
from hass_mqtt_devices.sensors import BinarySensor
# Create a settings dictionary
#
# Mandatory Keys:
# mqtt_server
# mqtt_user
# mqtt_password
# device_id
# device_name
# device_class
#
# Optional Keys:
# mqtt_prefix - defaults to homeassistant
# payload_off
# payload_on
# unique_id
configd = {
"mqtt_server": "mqtt.example.com",
"mqtt_prefix": "homeassistant",
"mqtt_user": "mqtt_user",
"mqtt_password": "mqtt_password",
"device_id": "device_id",
"device_name":"MySensor",
"device_class":"motion",
}
mysensor = BinarySensor(settings=configd)
mysensor.on()
mysensor.off()
Devices
Usage
from hass_mqtt_devices.device import Device
# Create a settings dictionary
#
# Mandatory Keys:
# mqtt_server
# mqtt_user
# mqtt_password
# device_id
# device_name
# device_class
# unique_id
#
# Optional Keys:
# client_name
# manufacturer
# model
# mqtt_prefix - defaults to homeassistant
configd = {
"mqtt_server": "mqtt.example.com",
"mqtt_prefix": "homeassistant",
"mqtt_user": "mqtt_user",
"mqtt_password": "mqtt_password",
"device_id": "device_id",
"device_name":"MySensor",
"device_class":"motion",
"manufacturer":"Acme Products",
"model": "Rocket Skates",
}
device = Device(settings=configd)
# You can add more than one metric to a device
device.add_metric(
name="Left skate thrust",
value=33,
configuration={"name": f"Left Skate Thrust"},
)
device.add_metric(
name="Right skate thrust",
value=33,
configuration={"name": f"Right Skate Thrust"},
)
# Nothing gets written to MQTT until we publish
device.publish()
# If we add a metric using the same name as an existing metric, the value is updated
device.add_metric(
name="Right skate thrust",
value=99,
configuration={"name": f"Right Skate Thrust"},
)
device.publish()
Scripts Provided
hass_mqtt_devices creates the following helper scripts you can use in your own shell scripts.
hmd
A gitlike command, you can hmd create binary sensor
and it'll find and run hmd-create-binary-sensor
and pass it all the command line options.
hmd create binary sensor
Create/Update a binary sensor and set its state.
Usage: hmd create binary sensor --device-name mfsmaster --device-id 8675309 --mqtt-user HASS_MQTT_USER --mqtt-password HASS_MQTT_PASSWORD --client-name inquisition --mqtt-server mqtt.unixorn.net --metric-name tamper --device-class motion --state off
hmd create device
Create/Update a device and set the state of multiple metrics on it.
Usage: hmd create device --device-name coyote --device-id 8675309 --mqtt-user HASS_MQTT_USER --mqtt-password HASS_MQTT_PASSWORD --mqtt-server mqtt.example.com --model 'Rocket Skates' --manufacturer 'Acme Products' --metric-data '{"name":"Left Rocket Skate","value":93}' --metric-data '{"name":"Right Rocket Skate","value":155}' --unique-id 'hmd-26536'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hass_mqtt_devices-0.2.1.tar.gz
.
File metadata
- Download URL: hass_mqtt_devices-0.2.1.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.13 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa0e47670536c7858883dbc083bf656dfa06949870ab8c03ecf00ce0d9f46179 |
|
MD5 | ffbfe12b8c84664e4827badd3ca428c2 |
|
BLAKE2b-256 | 94ed5e2046a9e22daab9681258cf270e4d4b47026b602bd8b7ac11a1330466d9 |
File details
Details for the file hass_mqtt_devices-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: hass_mqtt_devices-0.2.1-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.9.13 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ba739b1e57f3706fb95fba260003fde7f72c34fbd1c8f074769ee34b48e91bd |
|
MD5 | 3f036c9e7ef330744a3d5ec164fb342c |
|
BLAKE2b-256 | 236cfb85abfb6c4cb4efaeea082d95d9242533fc08267e4204947e6d77b981cb |