-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepever.tracert.to.domoticz.sh
executable file
·163 lines (147 loc) · 9.83 KB
/
epever.tracert.to.domoticz.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
#
# epever.tracert.to.domoticz.sh
#
# Tested on : EpEver Tracer 3210AN 30A MPPT Solar Controller
# Date : 12-10-2020
# Version : 00,00.00,000.1
#
# Created by ILoveIOT 2020"
#
#
####################################################################################################################################
# INFO="This script will execute the /root/scripts/epevertracer/epever.tracer.php file put the output to a file,
# get the value's from the output file, show them on console if needed, and send them to Domoticz, this is super simple, easy too change.
# Many thanks to Toggio (https://github.com/toggio/PhpEpsolarTracer)
# For console use : /root/scripts/epevertracer/epever.tracert.to.domoticz.sh
# For crontab use : /root/scripts/epevertracer/epever.tracert.to.domoticz.sh >> /dev/null 2>&1
# For all the info : php /root/scripts/epevertracer/example_cli.php
# 1. Change the serial port /root/scripts/epevertracer/epever.tracer.php line 26 ('/dev/ttyVIRT0')
# 2. Change the Domoticz IP & Port (see below)
# 3. Add/Change the acording Domoticz IDX's (see below)
# 4. Optional : Change the working directory, where you wanna place the files
# 5. Optional : If you need more info from the controller compare epever.tracer.php vs example_cli.php
# 6. Optional : Maybe make 2 cronjobs, with no sunhours just poll once a hour, with sun every min."
####################################################################################################################################
# Working directory, place where all epever tracer file's are
WORKINGDIR="/app/epever-metrics-for-domoticz"
# Domoticz IP address
DOMOTICZIP="dz-insecure.hs.mfis.net"
DOMOTICZPORT="80"
### PV Array
## Domoticz dummy Voltage
PVARRAYVOLTAGEIDX="590"
## Domoticz dummy 1 fase AMP
PVARRAYCURRENTIDX="591"
## Domoticz dummy Electricity (instant and counter) (change item, utility, item, change, Choose delivery and Energy read: Computed)
PVARRAYPOWERIDX="592"
## Domoticz dummy temp
#PVARRAYTEMPIDX="289"
### Battery
# Domoticz dummy Voltage
PVBATTERYVOLTAGEIDX="586"
PVBATTERYSOCIDX="587"
# Domoticz dummy 1 fase AMP
BATTERYCHARGINGCURRENTIDX="593"
# Domoticz dummy Electricity (instant and counter) (change item, utility, item, change, Choose delivery and Energy read: Computed)
#BATTERYCHARGINGPOWERIDX="292"
### Consumption and Production Metrics (kWh)
# Domoticz custom sensor (Axis kWh)
GENERATEKWHTODAYIDX="594"
# Domoticz custom sensor (Axis kWh)
#GENERATEKWHTOTALIDX="295"
# Domoticz custom sensor (Axis kWh)
GENERATEKWHMONTHIDX="595"
# Domoticz custom sensor (Axis kWh)
GENERATEKWHYEARIDX="596"
# Domoticz custom sensor (Axis kWh)
CONSUMEDENERGYTODAYIDX="597"
# Domoticz custom sensor (Axis kWh)
CONSUMEDENERGYTHISMONTHIDX="598"
# Domoticz custom sensor (Axis kWh)
CONSUMEDENERGYTHISYEARIDX="599"
# Domoticz custom sensor (Axis kWh)
#CONSUMEDENERGYTOTALIDX="303"
### Load
# Domoticz dummy 1 fase AMP
LOADCURRENTIDX="600"
# Domoticz dummy Electricity (instant and counter) (change item, utility, item, change, Energy read: Computed)
LOADPOWERIDX="601"
CHARGERTEMPIDX="602"
####################################################################################################################################
# The txt output file from reading from the solar controller
OUTPUTFILE="$WORKINGDIR/epever.output.txt"
# setup tcp backed virtual serial port
#socat pty,link=/dev/ttyVIRT0,raw tcp:192.168.1.140:8899,retry,forever,interval=5 &
socat pty,link=/dev/ttyVIRT0,raw,nonblock tcp:192.168.1.140:8899,forever &
sleep 1s
while true; do
# Generate the txt file with controller output (https://github.com/toggio/PhpEpsolarTracer)
/usr/bin/php $WORKINGDIR/epever.tracer.php > $OUTPUTFILE
# Getting the value's from the output file, and make them readable, so delete the C/V/A/W/kWh letters
CHARGERTEMP=`cat $OUTPUTFILE | sed -n 14p | awk '{print $4}' | sed 's/.$//' | sed 's/.$//'`
PVARRAYVOLTAGE=`cat $OUTPUTFILE | sed -n 4p | awk '{print $5}' | sed 's/\V//g'`
PVARRAYCURRENT=`cat $OUTPUTFILE | sed -n 5p | awk '{print $5}' | sed 's/\A//g'`
PVARRAYPOWER=`cat $OUTPUTFILE | sed -n 6p | awk '{print $5}' | sed 's/.$//'`
GENERATEKWHTODAY=`cat $OUTPUTFILE | sed -n 32p | awk '{print $5}' | sed 's/.$//' | sed 's/.$//' | sed 's/.$//'`
GENERATEKWHMONTH=`cat $OUTPUTFILE | sed -n 33p | awk '{print $6}' | sed 's/.$//' | sed 's/.$//' | sed 's/.$//'`
GENERATEKWHYEAR=`cat $OUTPUTFILE | sed -n 34p | awk '{print $6}' | sed 's/.$//' | sed 's/.$//' | sed 's/.$//'`
GENERATEKWHTOTAL=`cat $OUTPUTFILE | sed -n 35p | awk '{print $5}' | sed 's/.$//' | sed 's/.$//' | sed 's/.$//'`
BATTERYVOLTAGE=`cat $OUTPUTFILE | sed -n 7p | awk '{print $4}' | sed 's/.$//'`
BATTERYSOC=`cat $OUTPUTFILE | sed -n 16p | awk '{print $4}' | sed 's/.$//'`
BATTERYCHARGINGCURRENT=`cat $OUTPUTFILE | sed -n 8p | awk '{print $5}' | sed 's/.$//'`
BATTERYCHARGINGPOWER=`cat $OUTPUTFILE | sed -n 9p | awk '{print $5}' | sed 's/.$//'`
LOADCURRENT=`cat $OUTPUTFILE | sed -n 11p | awk '{print $4}' | sed 's/.$//'`
LOADPOWER=`cat $OUTPUTFILE | sed -n 12p | awk '{print $4}' | sed 's/.$//'`
CONSUMEDENERGYTODAY=`cat $OUTPUTFILE | sed -n 28p | awk '{print $5}' | sed 's/.$//' | sed 's/.$//' | sed 's/.$//'`
CONSUMEDENERGYTHISMONTH=`cat $OUTPUTFILE | sed -n 29p | awk '{print $6}' | sed 's/.$//' | sed 's/.$//' | sed 's/.$//'`
CONSUMEDENERGYTHISYEAR=`cat $OUTPUTFILE | sed -n 30p | awk '{print $6}' | sed 's/.$//' | sed 's/.$//' | sed 's/.$//'`
CONSUMEDENERGYTOTAL=`cat $OUTPUTFILE | sed -n 31p | awk '{print $5}' | sed 's/.$//' | sed 's/.$//' | sed 's/.$//'`
if ([ "$CHARGERTEMP" ] && [ "$CHARGERTEMP" != th ]); then
# Display the main value's to console with clear value's
echo "-------------------------------------------------------"
echo "CHARGERTEMP = $CHARGERTEMP °C"
echo "PVARRAYVOLTAGE = $PVARRAYVOLTAGE V"
echo "PVARRAYCURRENT = $PVARRAYCURRENT A"
echo "PVARRAYPOWER = $PVARRAYPOWER W"
echo "GENERATEKWHTODAY = $GENERATEKWHTODAY kWh"
echo "GENERATEKWHMONTH = $GENERATEKWHMONTH kWh"
echo "GENERATEKWHYEAR = $GENERATEKWHYEAR kWh"
echo "GENERATEKWHTOTAL = $GENERATEKWHTOTAL kWh"
echo "BATTERYVOLTAGE = $BATTERYVOLTAGE V"
echo "BATTERYSOC = $BATTERYSOC %"
echo "BATTERYCHARGINGCURRENT = $BATTERYCHARGINGCURRENT A"
echo "BATTERYCHARGINGPOWER = $BATTERYCHARGINGPOWER W"
echo "LOADCURRENT = $LOADCURRENT A"
echo "LOADPOWER = $LOADPOWER W"
echo "CONSUMEDENERGYTODAY = $CONSUMEDENERGYTODAY kWh"
echo "CONSUMEDENERGYTHISMONTH = $CONSUMEDENERGYTHISMONTH kWh"
echo "CONSUMEDENERGYTHISYEAR = $CONSUMEDENERGYTHISYEAR kWh"
echo "CONSUMEDENERGYTOTAL = $CONSUMEDENERGYTOTAL kWh"
echo "-------------------------------------------------------"
# Some dummy value for Domoticz energy total
DUMMYVALUE="1"
# Send the value's to Domoticz
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$CHARGERTEMPIDX&nvalue=0&svalue=$CHARGERTEMP" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$PVARRAYVOLTAGEIDX&nvalue=0&svalue=$PVARRAYVOLTAGE" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$PVARRAYCURRENTIDX&nvalue=0&svalue=$PVARRAYCURRENT" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$PVARRAYPOWERIDX&nvalue=0&svalue="$PVARRAYPOWER";"$DUMMYVALUE"" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$PVBATTERYVOLTAGEIDX&nvalue=0&svalue=$BATTERYVOLTAGE" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$PVBATTERYSOCIDX&nvalue=0&svalue=$BATTERYSOC" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$BATTERYCHARGINGCURRENTIDX&nvalue=0&svalue=$BATTERYCHARGINGCURRENT" >> /dev/null 2>&1
#curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$BATTERYCHARGINGPOWERIDX&nvalue=0&svalue="$BATTERYCHARGINGPOWER";"$DUMMYVALUE"" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$GENERATEKWHTODAYIDX&nvalue=0&svalue=$GENERATEKWHTODAY" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$GENERATEKWHMONTHIDX&nvalue=0&svalue=$GENERATEKWHMONTH" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$GENERATEKWHYEARIDX&nvalue=0&svalue=$GENERATEKWHYEAR" >> /dev/null 2>&1
#curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$GENERATEKWHTOTALIDX&nvalue=0&svalue=$GENERATEKWHTOTAL" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$LOADCURRENTIDX&nvalue=0&svalue=$LOADCURRENT" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$LOADPOWERIDX&nvalue=0&svalue="$LOADPOWER";"$DUMMYVALUE"" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$CONSUMEDENERGYTODAYIDX&nvalue=0&svalue=$CONSUMEDENERGYTODAY" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$CONSUMEDENERGYTHISMONTHIDX&nvalue=0&svalue=$CONSUMEDENERGYTHISMONTH" >> /dev/null 2>&1
curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$CONSUMEDENERGYTHISYEARIDX&nvalue=0&svalue=$CONSUMEDENERGYTHISYEAR" >> /dev/null 2>&1
#curl -i -s "http://$DOMOTICZIP:$DOMOTICZPORT/json.htm?type=command¶m=udevice&idx=$CONSUMEDENERGYTOTALIDX&nvalue=0&svalue=$CONSUMEDENERGYTOTAL" >> /dev/null 2>&1
else
echo "Received empty values from serial adapter. Not updating domoticz..."
fi
sleep 10s
done