Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,24 @@ optional arguments:
```


## Callback to Home-Assistant MQTT integration
etpedro https://github.com/etpedro has added a sendToMQTT_HA callback script that sends the data to an MQTT server and leverages Home-Assistant MQTT Autodiscovery creating a device for each sensor under MQTT integration. Each device has 4 entities: temperature, humidity, battery percentage and battery voltage.

Replace each variable according to your environment:

`mqtt.host` - MQTT Host

`mqtt.username` - MQTT Username

`mqtt.passwd`- MQTT Password


### Home-Assistant device details:


| Configuration | Value |
| ------------- | ------------------------ |
|name | lywsd03mmc_"device_name" |
|identifiers | lywsd03mmc_"device_name" |
|model | LYWSD03MMC |
|manufacturer | Xiaomi |
17 changes: 17 additions & 0 deletions sendToMQTT_HA.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

#This script is provided by Chiunownow https://github.com/Chiunownow
#Thank you very much for providing this script
#This script is

#use e.g with that script: MySensor.sh
#!/bin/bash
#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
#$DIR/LYWSD03MMC.py -d <device> -b 1000 -r --debounce --skipidentical 50 --name MySensor --callback sendToMQTT

mosquitto_pub -h mqtt.host -p 1883 -t "homeassistant/sensor/$2_temp/config" -u mqtt.username -P mqtt.passwd -i "mibridge" -m '{"device_class": "temperature", "name": "'$2'_temp", "unique_id": "lywsd03mmc_'$2'_temp", "device": { "name":"lywsd03mmc_'$2'", "identifiers": "lywsd03mmc_'$2'", "model": "LYWSD03MMC", "manufacturer": "Xiaomi"}, "state_topic": "homeassistant/sensor/'$2'/state", "unit_of_measurement": "°C", "value_template": "{{ value_json.temperature}}","platform": "mqtt" }'
mosquitto_pub -h mqtt.host -p 1883 -t "homeassistant/sensor/$2_humi/config" -u mqtt.username -P mqtt.passwd -i "mibridge" -m '{"device_class": "humidity", "name": "'$2'_humi", "unique_id": "lywsd03mmc_'$2'_humi", "device": { "name":"lywsd03mmc_'$2'", "identifiers": "lywsd03mmc_'$2'", "model": "LYWSD03MMC", "manufacturer": "Xiaomi"}, "state_topic": "homeassistant/sensor/'$2'/state", "unit_of_measurement": "%", "value_template": "{{ value_json.humidity}}","platform": "mqtt" }'
mosquitto_pub -h mqtt.host -p 1883 -t "homeassistant/sensor/$2_battlevel/config" -u mqtt.username -P mqtt.passwd -i "mibridge" -m '{"device_class": "battery", "name": "'$2'_batt", "unique_id": "lywsd03mmc_'$2'_batt", "device": { "name":"lywsd03mmc_'$2'", "identifiers": "lywsd03mmc_'$2'", "model": "LYWSD03MMC", "manufacturer": "Xiaomi"}, "state_topic": "homeassistant/sensor/'$2'/state", "unit_of_measurement": "%", "value_template": "{{ value_json.batterylevel}}","platform": "mqtt" }'
mosquitto_pub -h mqtt.host -p 1883 -t "homeassistant/sensor/$2_battvolt/config" -u mqtt.username -P mqtt.passwd -i "mibridge" -m '{"device_class": "voltage", "name": "'$2'_volt", "unique_id": "lywsd03mmc_'$2'_volt", "device": { "name":"lywsd03mmc_'$2'", "identifiers": "lywsd03mmc_'$2'", "model": "LYWSD03MMC", "manufacturer": "Xiaomi"}, "state_topic": "homeassistant/sensor/'$2'/state", "unit_of_measurement": "v", "value_template": "{{ value_json.batteryvoltage}}","platform": "mqtt" }'
mosquitto_pub -h mqtt.host -p 1883 -t "homeassistant/sensor/$2/state" -u mqtt.username -P mqtt.passwd -i "mibridge" -m '{ "temperature": '$3', "humidity": '$4', "batteryvoltage" : '$5', "batterylevel": '$6' }'