#!/bin/sh LOCK=/var/lock/LCK..ttyATH0.stm32 M=10.32.139.1 WATERS=0 MAX=65 OUTSIDE="$(mosquitto_sub -t tele/weather/tempc -h ${M} -W 1 -C 1 | sed -e 's/\..*$//g') " logger -t thermostat " outside is $OUTSIDE" # conventions # POWER is power to valve coil # OPEN is valve state # DELTA is temp difference # var1 is low set point # var2 is high set point # var3 is manual override # towel radiators FUZZY=0 for i in laundry_radiator bathroom_radiator; do O="$(mosquitto_sub -t stat/$i/OPEN -h ${M} -W 1 -C 1)" P="$(mosquitto_sub -t stat/$i/POWER -h ${M} -W 1 -C 1)" if [ "$P" == "OFF" -a "$O" == "1" ]; then FUZZY=1 O=0 fi if [ "$P" == "ON" -a "$O" == "0" ]; then FUZZY=1 fi W=0 if [ "$O" == "1" ]; then W=$MAX fi WATERS="$WATERS $W" logger -t thermostat " $i O=$O W=$W" done #... others where we care about the delta for i in kstudy_radiator bedroom_radiator spare_bedroom_radiator dd_radiator1 dd_radiator2 dd_radiator3 hall_radiator kitchen_radiator music_room_radiator 2fl_stair_radiator 2fl_main_radiator; do O="$(mosquitto_sub -t stat/$i/OPEN -h ${M} -W 1 -C 1)" P="$(mosquitto_sub -t stat/$i/POWER -h ${M} -W 1 -C 1)" if [ "$P" == "OFF" -a "$O" == "1" ]; then FUZZY=1 O=0 fi if [ "$P" == "ON" -a "$O" == "0" ]; then FUZZY=1 fi T="$(mosquitto_sub -t stat/$i/TEMPERATURE -h ${M} -W 1 -C 1 | sed -e 's/\..*$//g') " D="$(expr $T - $OUTSIDE)" W=0 if [ "$O" == "1" ]; then W="$( expr \( \( \( $D * 2 \) / 3 \) + 55 \) )" #W="$( expr $D \* 5 + 45 )" fi logger -t thermostat " $i O=$O D=$D W=$W" WATERS="$WATERS $W" done R=0 for w in ${WATERS}; do if [ $w -gt $R ]; then R=$w fi done if [ $R -gt $MAX ]; then R=$MAX fi if [ "$FUZZY" -eq 1 ]; then logger -t thermostat "Fuzzy=1, stopping pump" R=0 fi if [ ! -f "${LOCK}" ]; then logger -t thermostat "Requesting water temp of $R" printf "\nCH=%d\n" $R > /dev/ttyATH0 else logger -t thermostat "Interface is locked, so cant request water temp of $R" fi