-
Notifications
You must be signed in to change notification settings - Fork 0
/
registerDevice.sh
29 lines (24 loc) · 1.63 KB
/
registerDevice.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
if [$# -ne 4];
then echo "Incorrect number of parameters. Usage: registerDevice.sh mqtthost user psw devicename"
exit 2
fi
host=$1
user=$2
psw=$3
device=$4
#config
t1="homeassistant/sensor/"
#temp
topic=$t1$device"/temperature/config"
state=""
echo $topic
mosquitto_pub -h $host -t $topic -r -u $user -P $psw -m '{ "device_class": "temperature", "name": "'$device' Température", "state_topic": "xiaomi/sensor/'$devi0ce'/state", "frc_upd": true, "uniq_id": "'$device'_Temperature", "unit_of_measurement": "°C", "value_template": "{{ value_json.temperature }}", "device": { "identifiers": [ "'$device'" ], "name": "'$device' sensors", "model": "Xiaomi Temp V2", "manufacturer": "Xiaomi" } }'
#hum
topic=$t1$device"/humidity/config"
echo $topic
mosquitto_pub -h $host -t $topic -r -u $user -P $psw -m '{"device_class": "humidity", "name": "'$device' Humidité", "state_topic": "xiaomi/sensor/'$device'/state", "frc_upd": true, "uniq_id": "'$device'_Humidity", "unit_of_measurement": "%", "value_template": "{{ value_json.humidity }}", "device": { "identifiers": [ "'$device'" ], "name": "'$device' sensors", "model": "Xiaomi Temp V2", "manufacturer": "Xiaomi" } }'
#batt.
topic=$t1$device"/battlevel/config"
echo $topic
mosquitto_pub -h $host -t $topic -r -u $user -P $psw -m '{"device_class": "battery", "name": "'$device' Battery Level", "state_topic": "xiaomi/sensor/'$device'/state", "frc_upd": true, "uniq_id": "'$device'_BattLevel", "unit_of_measurement": "%", "value_template": "{{ value_json.batterylevel }}", "device": { "identifiers": [ "'$device'" ], "name": "'$device' sensors", "model": "Xiaomi Temp V2", "manufacturer": "Xiaomi" } }'