--- /dev/null
+if ( gray == 1 ) {
+# set terminal pngcairo mono size 600,800
+ set terminal pngcairo color size 600,800
+} else {
+ set terminal pngcairo color size 1200,600
+}
+
+set xdata time
+set timefmt "%s"
+
+if (strlen(interval) > 2) {
+ set xtics format "%H"
+} else {
+ set xtics format "%H:%M"
+}
+
+set pointsize 0.2
+
+set output '/dev/shm/temp3.png'
+
+unset border
+
+set multiplot
+
+
+if ( gray == 1 ) {
+ set size 1, 0.5
+ set origin 0.0, 0.5
+} else {
+ set size 1.0, 0.5
+ set origin 0.0, 0.5
+}
+
+#if ( ! exists("t_mean")) {
+if (1) {
+
+t_mean=25
+t_spread=30
+
+h_mean = 50
+h_spread = 50
+
+print "using default mean and spread"
+}
+
+min_t = t_mean - ( t_spread / 2 )
+max_t = t_mean + ( t_spread / 2 )
+
+if ( ! exists("tz_secs") ) {
+ tz_secs=7200
+}
+
+set ytics nomirror
+unset y2tics
+set y2range [0:50]
+
+plot \
+ "/dev/shm/data.DHT22-t" using ($1+tz_secs):($2 > min_t && $2 < max_t ? $2 : '') with dots title "DHT22 unutra" lt rgb "#ff00ff" \
+,"/dev/shm/data.DS18B20-t" using ($1+tz_secs):($2 > min_t && $2 < max_t ? $2 : '') with dots title "DS18B20 unutra" lt rgb "#880088" \
+,"/dev/shm/data.kuhinja-t-h" using ($1+tz_secs):($2) with dots title "kuhinja" lt rgb "#ff8844" \
+,"/dev/shm/data.kupaona-t-h" using ($1+tz_secs):($2) with dots title "kupaona" lt rgb "#8888ff" \
+,"/dev/shm/data.soba-t-h" using ($1+tz_secs):($2) with dots title "soba" lt rgb "#ffcc00" \
+,"/dev/shm/data.vani-t-h" using ($1+tz_secs):($2) with dots title "vani" lt rgb "#00cc00" \
+,"/dev/shm/data.kutija-t-h" using ($1+tz_secs):($2) with dots title "kutija" lt rgb "#0088cc" \
+,"/dev/shm/boiler.d" using ($1+tz_secs):($2 > 0 ? 48 : 2) axes x1y2 with dots title "boiler on/off" lt rgb "#000000"
+
+
+if ( exists("lines") && lines == 1 ) {
+plot \
+ "/dev/shm/data.DHT22-t" using ($1+tz_secs):($2 > min_t && $2 < max_t ? $2 : '') with lines title "DHT22 unutra" lt rgb "#ff00ff" \
+,"/dev/shm/data.DS18B20-t" using ($1+tz_secs):($2 > min_t && $2 < max_t ? $2 : '') with lines title "DS18B20 unutra" lt rgb "#880088" \
+,"/dev/shm/data.kuhinja-t-h" using ($1+tz_secs):($2) with lines title "kuhinja" lt rgb "#ff8844" \
+,"/dev/shm/data.kupaona-t-h" using ($1+tz_secs):($2) with lines title "kupaona" lt rgb "#8888ff" \
+,"/dev/shm/data.soba-t-h" using ($1+tz_secs):($2) with lines title "soba" lt rgb "#ffcc00" \
+,"/dev/shm/data.vani-t-h" using ($1+tz_secs):($2) with lines title "vani" lt rgb "#00cc00" \
+,"/dev/shm/data.kutija-t-h" using ($1+tz_secs):($2) with lines title "kutija" lt rgb "#0088cc" \
+,"/dev/shm/boiler.d" using ($1+tz_secs):($2 > 0 ? 48 : 2) axes x1y2 with dots title "boiler on/off" lt rgb "#000000"
+}
+
+if ( gray == 1 ) {
+ set origin 0.0, 0.0
+} else {
+ set origin 0.0, 0.0
+}
+
+min_h = h_mean - h_spread
+max_h = h_mean + h_spread
+
+plot \
+ "/dev/shm/data.DHT22-h" using ($1+tz_secs):($2 > min_h && $2 < max_h ? $2 : '') with dots title "DHT22 unutra" lt rgb "#ff00ff" \
+,"/dev/shm/data.kuhinja-t-h" using ($1+tz_secs):($3) with dots title "kuhinja" lt rgb "#ff8844" \
+,"/dev/shm/data.kupaona-t-h" using ($1+tz_secs):($3) with dots title "kupaona" lt rgb "#8888ff" \
+,"/dev/shm/data.soba-t-h" using ($1+tz_secs):($3) with dots title "soba" lt rgb "#ffcc00" \
+,"/dev/shm/data.vani-t-h" using ($1+tz_secs):($3) with dots title "vani" lt rgb "#00cc00" \
+,"/dev/shm/data.kutija-t-h" using ($1+tz_secs):($3) with dots title "kutija" lt rgb "#0088cc" \
+,"/dev/shm/boiler.d" using ($1+tz_secs):($2 > 0 ? 48 : 2) axes x1y2 with dots title "boiler on/off" lt rgb "#000000"
+
+if ( exists("lines") && lines == 1 ) {
+plot \
+ "/dev/shm/data.DHT22-h" using ($1+tz_secs):($2 > min_h && $2 < max_h ? $2 : '') with lines title "DHT22 unutra" lt rgb "#ff00ff" \
+,"/dev/shm/data.kuhinja-t-h" using ($1+tz_secs):($3) with lines title "kuhinja" lt rgb "#ff8844" \
+,"/dev/shm/data.kupaona-t-h" using ($1+tz_secs):($3) with lines title "kupaona" lt rgb "#8888ff" \
+,"/dev/shm/data.soba-t-h" using ($1+tz_secs):($3) with lines title "soba" lt rgb "#ffcc00" \
+,"/dev/shm/data.vani-t-h" using ($1+tz_secs):($3) with lines title "vani" lt rgb "#00cc00" \
+,"/dev/shm/data.kutija-t-h" using ($1+tz_secs):($3) with lines title "kutija" lt rgb "#0088cc" \
+,"/dev/shm/boiler.d" using ($1+tz_secs):($2 > 0 ? 48 : 2) axes x1y2 with dots title "boiler on/off" lt rgb "#000000"
+}
+unset multiplot
--- /dev/null
+#!/bin/sh
+
+# sudo apt-get install jq
+# ln -s `pwd`/temp3.sh /var/www/html/temp3.sh
+# ln -s /dev/shm/temp3.png /var/www/html/temp3.png
+# ln -s /dev/shm/temp3-gray.png /var/www/html/temp3-gray.png
+#
+# install as cgi-script and invoke to get png use http://localhost/temp3.sh?gray for kindle grayscale output
+
+# use as http://localhost/temp3.sh?t=6h to show last 6h instead of default 48h
+
+INTERVAL=`echo $QUERY_STRING | grep -i 't=[0-9]*h' | sed 's/.*t=\([0-9]*h\).*/\1/'`
+test -z "$INTERVAL" && INTERVAL=48h
+
+LINES=0
+echo $QUERY_STRING | grep -i 'lines=' >/dev/null && LINES=1
+
+: >/dev/shm/curl
+
+influx_mqtt() {
+ topic=$1
+ shift
+ file=$1
+
+# echo "# $topic [$rids] -> $file"
+ cat <<__SHELL__ >> /dev/shm/curl
+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\"='$topic' $rids" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/data.$file
+__SHELL__
+}
+
+influx_rtl() {
+ file=$1
+ shift;
+ rids=`echo $* | sed -e 's/\([0-9][0-9]*\)/ or "rid" = '"'"'\1'"'"'/g' -e 's/^ or/ AND /'`
+
+# echo "# $topic [$rids] -> $file"
+ cat <<__SHELL__ >> /dev/shm/curl
+curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"temperature_C\",\"humidity\" FROM \"rtl_433\" WHERE time > now() - $INTERVAL $rids" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/data.$file
+__SHELL__
+}
+
+influx_mqtt 'stat/boiler/DS18B20/temperature' 'DS18B20-t'
+influx_mqtt 'stat/boiler/DHT22/temperature' 'DHT22-t'
+influx_mqtt 'stat/boiler/DHT22/humidity' 'DHT22-h'
+
+influx_mqtt 'stat/boiler/d' 'boiler-d'
+
+influx_rtl 'vani-t-h' 108 40
+influx_rtl 'kutija-t-h' 55
+influx_rtl 'kupaona-t-h' 125 148
+influx_rtl 'kuhinja-t-h' 175 239
+influx_rtl 'soba-t-h' 125 184
+
+cat /dev/shm/curl | parallel
+
+
+GRAY=`echo $QUERY_STRING | grep -i gray | wc -l`
+
+tz_secs=`date +%:z | cut -d: -f1 | sed -e 's/^+//' -e 's/$/ * 3600/' | bc`
+
+cd /home/pi/vaillant-thermostat/
+gnuplot -e "gray=$GRAY ; lines=$LINES ; interval=\"$INTERVAL\" ; tz_secs=$tz_secs" temp3.gnuplot
+
+if [ "$GRAY" = 1 ] ; then
+ convert /dev/shm/temp3.png -gravity center -extent 600x800 -colorspace Gray /dev/shm/temp3-gray.png
+ GRAY="-gray"
+else
+ GRAY=""
+fi
+
+#set > /dev/shm/temp3.cgi.vars
+
+lines_checked=""
+test "$LINES" = 1 && lines_checked="checked"
+
+if echo $HTTP_USER_AGENT | grep Mozilla > /dev/null ; then
+ echo "Content-type: text/html\r\n\r\n"
+ cat << __HTML__
+<body>
+<form method="get" action="/temp3.sh" style="position: fixed; top: 0; left: 0">
+<input type=submit name="t" value="48h">
+<input type=submit name="t" value="24h">
+<input type=submit name="t" value="12h">
+<input type=submit name="t" value="6h">
+<input type=submit name="t" value="1h">
+<input type=checkbox name="lines" $lines_checked> <!-- $LINES -->
+</form>
+<img src="/temp3.png">
+</body>
+__HTML__
+ exit 0
+fi
+
+echo "Location: $REQUEST_SCHEME://$SERVER_NAME:$SERVER_PORT/temp3$GRAY.png"
+echo
+
+exit 0
+