added lines for additional sensor
[vaillant-thermostat] / temp2.sh
1 #!/bin/sh
2
3 # sudo apt-get install jq
4 # ln -s `pwd`/temp2.sh /var/www/html/temp2.sh 
5 # ln -s /dev/shm/temp2.png /var/www/html/temp2.png 
6 # ln -s /dev/shm/temp2-gray.png /var/www/html/temp2-gray.png 
7 #
8 # install as cgi-script and invoke to get png use http://localhost/temp2.sh?gray for kindle grayscale output
9
10 # use as http://localhost/temp2.sh?t=6h to show last 6h instead of default 48h
11
12 INTERVAL=`echo $QUERY_STRING | grep -i 't=[0-9]*h' | sed 's/.*t=\([0-9]*h\).*/\1/'`
13 test -z "$INTERVAL" && INTERVAL=48h
14
15 LINES=0
16 echo $QUERY_STRING | grep -i 'lines=' >/dev/null && LINES=1
17
18
19 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"value\" FROM \"mqtt_consumer\" WHERE time > now() - $INTERVAL AND \"topic\"='stat/boiler/DS18B20/temperature'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/DS18B20-temperature
20 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"value\" FROM \"mqtt_consumer\" WHERE time > now() - $INTERVAL AND \"topic\"='stat/boiler/DHT22/temperature'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/DHT22-temperature
21 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"value\" FROM \"mqtt_consumer\" WHERE time > now() - $INTERVAL AND \"topic\"='stat/boiler/DHT22/humidity'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/DHT22-humidity
22
23 #curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"id\" = '5'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/rtl_433-temperature
24 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '172'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-172-temperature
25 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '75'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-75-temperature
26 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '141'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-141-temperature
27 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '183'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-183-temperature
28
29
30 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT mean(\"value\"),spread(\"value\") FROM \"mqtt_consumer\" WHERE time > now() - $INTERVAL AND \"topic\"='stat/boiler/DS18B20/temperature'"  | jq '.results[0].series[0].values[0][1,2]' > /dev/shm/temperature.mean.spread
31 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT mean(\"value\"),spread(\"value\") FROM \"mqtt_consumer\" WHERE time > now() - $INTERVAL AND \"topic\"='stat/boiler/DHT22/humidity'"  | jq '.results[0].series[0].values[0][1,2]' > /dev/shm/humidity.mean.spread
32
33 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"id\" = '5'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/rtl_433-humidity
34 #curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"id\" = '9'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-humidity
35 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '172'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-172-humidity
36 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '75'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-75-humidity
37 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"humidity\",\"channel\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL AND \"topic\"='rpi2/rtl_433/influx' AND \"rid\" = '141'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' | tr -d '\\"' > /dev/shm/rtl_433-9-141-humidity
38
39 GRAY=`echo $QUERY_STRING | grep -i gray | wc -l`
40
41 cd /home/pi/vaillant-thermostat/
42 gnuplot -e "t_mean=`head -1 /dev/shm/temperature.mean.spread`;t_spread=`tail -1 /dev/shm/temperature.mean.spread`;h_mean=`head -1 /dev/shm/humidity.mean.spread` ; h_spread=`tail -1 /dev/shm/humidity.mean.spread` ; gray=$GRAY ; lines=$LINES ; interval=\"$INTERVAL\"" temp2.gnuplot
43
44 if [ "$GRAY" = 1 ] ; then
45         convert /dev/shm/temp2.png -gravity center -extent 600x800 -colorspace Gray /dev/shm/temp2-gray.png
46         GRAY="-gray"
47 else
48         GRAY=""
49 fi
50
51 set > /dev/shm/temp2.cgi.vars
52
53 lines_checked=""
54 test "$LINES" = 1 && lines_checked="checked"
55
56 if echo $HTTP_USER_AGENT | grep Mozilla > /dev/null ; then
57         echo "Content-type: text/html\r\n\r\n"
58         cat << __HTML__
59 <body>
60 <form method="get" action="/temp2.sh" style="position: fixed; top: 0; left: 0">
61 <input type=submit name="t" value="48h">
62 <input type=submit name="t" value="24h">
63 <input type=submit name="t" value="12h">
64 <input type=submit name="t" value="6h">
65 <input type=submit name="t" value="1h">
66 <input type=checkbox name="lines" $lines_checked> <!-- $LINES -->
67 </form>
68 <img src="/temp2.png">
69 </body>
70 __HTML__
71         exit 0
72 fi
73
74 echo "Location: $REQUEST_SCHEME://$SERVER_NAME:$SERVER_PORT/temp2$GRAY.png"
75 echo
76
77 exit 0
78
79 montage /dev/shm/[1-3].png -tile 1x3 -geometry +0+0 /tmp/m1.png
80 convert /tmp/m1.png -gravity center -extent 600x800 /tmp/m1.pgm
81 convert /tmp/m1.png -gravity center -extent 600x800 -colorspace Gray /tmp/m1.gray.png
82 display /tmp/m1.pgm
83
84 echo Location: http://192.168.3.2/m1.gray.png
85 echo
86