Skip to content

Commit

Permalink
Add support for discovering Govee water sensors to rtl_433_mqtt_hass
Browse files Browse the repository at this point in the history
  • Loading branch information
kcpants committed Aug 24, 2023
1 parent 70d84d0 commit f101632
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions examples/rtl_433_mqtt_hass.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
Running this script will cause a number of Home Assistant entities (sensors
and binary sensors) to be created. These entities can linger for a while unless
the topic is republished with an empty config string. To avoid having to
do a lot of clean up When running this initially or debugging, set this
do a lot of clean up when running this initially or debugging, set this
script to publish to a topic other than the one Home Assistant users (homeassistant).
MQTT Explorer (http://mqtt-explorer.com/) is a very nice GUI for
Expand Down Expand Up @@ -114,6 +114,25 @@
# Global mapping of rtl_433 field names to Home Assistant metadata.
# @todo - should probably externalize to a config file
# @todo - Model specific definitions might be needed
#
# The "mappings" dictionary maps fields from MQTT messages published on the rtl
# topic to MQTT devices in Home Assistant. This script compares the keys in the
# JSON payload of each MQTT message published to the rtl topic to the top-level
# keys in the "mappings" dictionary below. If a matching key is found then a new
# MQTT device is added to Home Assistant. The properties of the new device are
# defined by the second-level "config" object within the matching mapping which
# is passed directly to MQTT discovery as the payload of a device "config" topic.
# Other second-level keys within the mapping control the behavior of this script.
#
# - device_type: The MQTT entity type. Must be one of the entity integrations
# supported by MQTT discovery (see the MQTT docs for more information)
# - object_suffix: A suffix appended to the newly created entity's object_id
# - value: If specified, a key in an MQTT message is only considered a match if
# the value associated with the key in the MQTT payload is equal to this string.
# Useful if a device or sensor publishes its state within commonly used keys.
# - config: The config object defines the properties of the device added to
# Home Assistant when a match is found. More detailed information describing
# the valid fields of config objects can be found in the MQTT docs.

mappings = {
"temperature_C": {
Expand Down Expand Up @@ -660,6 +679,19 @@
}
},

"event": {
"value": "Water Leak",
"device_type": "binary_sensor",
"object_suffix": "leak",
"config": {
"name": "Water Sensor",
"device_class": "moisture",
"force_update": "true",
"payload_on": "Water Leak",
"payload_off": "Button Press"
}
},

}

# Use secret_knock to trigger device automations for Honeywell ActivLink
Expand Down Expand Up @@ -833,14 +865,14 @@ def bridge_event_to_hass(mqttc, topic_prefix, data):

# detect known attributes
for key in data.keys():
if key in mappings:
if key not in mappings or "value" in mappings[key] and mappings[key]["value"] != data[key]:
if key not in SKIP_KEYS:
skipped_keys.append(key)
else:
# topic = "/".join([topicprefix,"devices",model,instance,key])
topic = "/".join([base_topic, key])
if publish_config(mqttc, topic, model, device_id, mappings[key], key):
published_keys.append(key)
else:
if key not in SKIP_KEYS:
skipped_keys.append(key)

if "secret_knock" in data.keys():
for m in secret_knock_mappings:
Expand Down

0 comments on commit f101632

Please sign in to comment.