-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeye2mqtt2homeassist.sh
80 lines (70 loc) · 2.34 KB
/
deye2mqtt2homeassist.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# dirty hack to make the MQTT messages sent by deye2mqtt.sh known to Home Assistant.
# Basically sends some MQTT messages to the Mosquitto broker that make Home Assistant auto-detect
# the information submitted by deye2mqtt.sh
#
# This will allow you to integrate your Deye Inverter's information into a Home Assistant installation
# via MQTT.
#
# Hacked together by Niels Ott <[email protected]>
# Use at own risk. License is GPL v3.
# This program may blow up your cat.
#
IDENTIFIER="hostname_of_my_deye_inverter"
TOPIC="mywizardcastle/power/deye/current"
BROKER="hostname_or_ip_of_my_mqtt_broker" # for most people: localhost
device="\"device\":{
\"identifiers\":\"${IDENTIFIER}\",
\"name\":\"${IDENTIFIER} Deye Inverter\",
\"model\":\"Deye Inverter MQTT Adapter Hack\",
\"manufacturer\" : \"DrNI\"
}
"
JSON="
{
\"name\": \"Current Power Output\",
\"unit_of_measurement\":\"W\",
\"device_class\" : \"power\",
\"state_class\" : \"measurement\",
\"unique_id\" : \"deye_inverter_${IDENTIFIER}_cpo\",
\"schema\": \"state\",
\"state_topic\": \"${TOPIC}\",
\"value_template\": \"{{ value_json.current_power_output.value }}\",
${device}
}
"
T="homeassistant/sensor/${IDENTIFIER}/${IDENTIFIER}_current_power_output/config"
J=$(echo "$JSON" | tr '\n' ' ' | sed 's/ */ /g' )
echo "$J" | mosquitto_pub -h "$BROKER" -r -l -t "$T"
JSON="
{
\"name\": \"Yield Today\",
\"unit_of_measurement\":\"kWh\",
\"device_class\" : \"energy\",
\"state_class\" : \"total\",
\"unique_id\" : \"deye_inverter_${IDENTIFIER}_yt\",
\"schema\": \"state\",
\"state_topic\": \"${TOPIC}\",
\"value_template\": \"{{ value_json.yield_today.value }}\",
${device}
}
"
T="homeassistant/sensor/${IDENTIFIER}/${IDENTIFIER}_yield_today/config"
J=$(echo "$JSON" | tr '\n' ' ' | sed 's/ */ /g' )
echo "$J" | mosquitto_pub -h "$BROKER" -r -l -t "$T"
JSON="
{
\"name\": \"Total Yield\",
\"unit_of_measurement\":\"kWh\",
\"device_class\" : \"energy\",
\"state_class\" : \"total_increasing\",
\"unique_id\" : \"deye_inverter_${IDENTIFIER}_ty\",
\"schema\": \"state\",
\"state_topic\": \"${TOPIC}\",
\"value_template\": \"{{ value_json.total_yield.value }}\",
${device}
}
"
T="homeassistant/sensor/${IDENTIFIER}/${IDENTIFIER}_total_yield/config"
J=$(echo "$JSON" | tr '\n' ' ' | sed 's/ */ /g' )
echo "$J" | mosquitto_pub -h "$BROKER" -r -l -t "$T"