#!/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 )"
#./LYWSD03MMC.py -d a4:c1:38:10:88:d5 -b 1000 -r --debounce --skipidentical 50 --name MySensor -c 1 --callback sendToMQTT

mosquitto_pub -h 192.168.0.150 -p 1883 -t "homeassistant/sensor/speedtest_minivl_ping/config" -i "mibridge" -m '{"device_class": "ping", "name": "speedtest_minivl_ping", "unique_id": "speedtest_minivl_ping", "device": { "name":"speedtest_minivl_ping", "identifiers": "speedtest_minivl", "model": "SPEEDTEST", "manufacturer": "Ookla"}, "state_topic": "homeassistant/sensor/speedtest_minivl/state", "unit_of_measurement": "ms", "value_template": "{{ value_json.ping}}","platform": "mqtt" }'
#mosquitto_pub -h 192.168.0.150 -p 1883 -t "homeassistant/sensor/$2_humi/config" -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 192.168.0.150 -p 1883 -t "homeassistant/sensor/$2_battlevel/config" -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 192.168.0.150 -p 1883 -t "homeassistant/sensor/$2_battvolt/config" -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 192.168.0.150 -p 1883 -t "homeassistant/sensor/$2/state" -i "mibridge" -m '{ "temperature": '$3', "humidity": '$4', "batteryvoltage" : '$5', "batterylevel": '$6' }'
mosquitto_pub -h 192.168.0.150 -p 1883 -t "homeassistant/sensor/speedtest_minivl/state" -i "mibridge" -m '{ "ping": 11.111 }'
