-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheating-433-trig-git.sh
150 lines (128 loc) · 5.88 KB
/
heating-433-trig-git.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
#!/bin/sh
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
runcheck="`ps cax | grep heating-433 -c`"
echo $runcheck
if [ $runcheck -ge 3 ];
then
echo "running"
exit
else
:
fi
control="`cat /path/to/control/files/control.txt`"
room="`cat /path/to/control/files/room.txt`"
targettemp="`cat /path/to/control/files/targettemp.txt`"
mintemp=14
echo control - $control
#if off - turn off
if [ "$control" = "off" ];
then
echo "Heating Off"
curl -s -o /dev/null -G "http://BOILERIPADDRESS/cm" --data-urlencode "cmnd=Power OFF"
echo "off" > /path/to/control/files/state.txt
exit
else
:
fi
#if on - turn on
if [ "$control" = "on" ];
then
echo "Heating On"
curl -s -o /dev/null -G "http://BOILERIPADDRESS/cm" --data-urlencode "cmnd=Power ON"
echo "on" > /path/to/control/files/state.txt
exit
else
:
fi
#AUTO - not needed without LEDs
if [ "$control" = "auto" ];
then
:
else
:
fi
#select which room temp to use and fetch temp from db
if [ "$room" = "bedroom" ];
then
currenttemp=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from bedroom order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
elif [ "$room" = "living" ];
then
currenttemp=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from livingroom order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
elif [ "$room" = "box" ];
then
currenttemp=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from boxroom order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
elif [ "$room" = "front" ];
then
currenttemp=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from frontroom order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
elif [ "$room" = "kitchen" ];
then
currenttemp=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from kitchen order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
elif [ "$room" = "spare" ];
then
currenttemp=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from spare order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
elif [ "$room" = "attic" ];
then
currenttemp=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from attic order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
elif [ "$room" = "outside" ];
then
currenttemp=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from outside order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
elif [ "$room" = "autoroom" ];
then
currenttempliving=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from livingroom order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
currenttempbedroom=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from bedroom order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
currenttemp=$(echo "$currenttempbedroom\n$currenttempliving" | sort -n | tail -1)
elif [ "$room" = "autoaverage" ];
then
currenttempliving=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from livingroom order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
currenttempbedroom=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from bedroom order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
currenttempbox=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from boxroom order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
currenttemp=$(echo $currenttempliving $currenttempbedroom $currenttempbox | awk -v RS=' ' '{sum+=$1; count++} END{print sum/count}')
else
currenttemp=$(mysql --host=SERVERIPADDRESS --user=USERNAME --password=PASSWORD temptest -e"select temperature, unixtime from bedroom order by unixtime desc limit 1" --disable-column-names -B | cut -c 1-4)
fi
echo $room - $currenttemp
echo target - $targettemp
echo mintemp - $mintemp
arpscan="`cat /path/to/control/files/arpscan.txt`"
boost="`cat /path/to/control/files/boost.txt`"
echo boost - $boost
echo arpscan - $arpscan
#calculate whether current temp is greater than target temp
tempcalc="`echo $currenttemp'>='$targettemp | bc -l`"
currenttempround="`echo 'scale=0;' $currenttemp'/1' | bc`"
#echo $currenttempround
#if current temp is higher turn off - if current temp is lower turn on
if [ "$control" = "auto" ] && [ "$boost" = "1" ] && [ "$tempcalc" = "0" ];
then
echo "Heating On"
curl -s -o /dev/null -G "http://BOILERIPADDRESS/cm" --data-urlencode "cmnd=Power ON"
echo "on" > /path/to/control/files/state.txt
exit
elif [ "$control" = "auto" ] && [ "$currenttempround" -lt "$mintemp" ];
then
echo "Heating On"
curl -s -o /dev/null -G "http://BOILERIPADDRESS/cm" --data-urlencode "cmnd=Power ON"
echo "on" > /path/to/control/files/state.txt
echo
exit
elif [ "$control" = "auto" ] && [ "$arpscan" = "1" ];
then
echo "Heating Off"
curl -s -o /dev/null -G "http://BOILERIPADDRESS/cm" --data-urlencode "cmnd=Power OFF"
echo "off" > /path/to/control/files/state.txt
exit
elif [ "$control" = "auto" ] && [ "$tempcalc" = "1" ];
then
echo "Heating Off"
curl -s -o /dev/null -G "http://BOILERIPADDRESS/cm" --data-urlencode "cmnd=Power OFF"
echo "off" > /path/to/control/files/state.txt
exit
elif [ "$control" = "auto" ] && [ "$tempcalc" = "0" ];
then
echo "Heating On"
curl -s -o /dev/null -G "http://BOILERIPADDRESS/cm" --data-urlencode "cmnd=Power ON"
echo "on" > /path/to/control/files/state.txt
exit
fi
#test