summaryrefslogtreecommitdiffstats
path: root/boiler-monster/mr3020/usr/bin/thermostat
blob: 612c89921bd4b853c09287e7f94e3a3b4ace4bd0 (plain)
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
#!/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 boxroom_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