-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKendallScript
More file actions
127 lines (111 loc) · 2.85 KB
/
Copy pathKendallScript
File metadata and controls
127 lines (111 loc) · 2.85 KB
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
% Config params, overwrite any previous settings from the commandline
config ap_ssid MQTT_SERVICES
config ap_password stevieray01
config ssid GlenVista1CF0
config password stevieray01
config ntp_server 1.de.pool.ntp.org
config mqtt_host m14.cloudmqtt.com
config mqtt_port 19801
config mqtt_user htzkfqlx
config mqtt_password PLsADzYDYbdX
%config speed 160
% Now the initialization, this is done once after booting
on init
do
% Status of the relay
setvar $relay_status=0
setvar $run=0
gpio_out 12 $relay_status
gpio_out 13 not ($relay_status)
% Voltage topic
setvar $Voltage_topic="/system/voltage/VOLTS"
% Season topic
setvar $Season_topic="season/SET"
setvar $Season="Summer"
% Status topic
setvar $status_topic="WaterHeater/PWR"
publish local $status_topic $relay_status retained
% local subscriptions once in 'init'
subscribe local $Voltage_topic
subscribe local $Season_topic
settimer 1 500
settimer 2 1000
% Now the MQTT client init, this is done each time the client connects
on mqttconnect
do
% remote subscriptions for each connection in 'mqttconnect'
publish remote $status_topic $relay_status retained
% Now the events, checked whenever something happens
on topic local $Season_topic
do
if $Season = "Summer" then
setvar $Season = "Winter"
setvar $relay_status = 0
gpio_out 12 $relay_status
gpio_out 13 not ($relay_status)
else
setvar $Season = "Summer"
endif
publish local "stat/season" $Season
publish remote "stat/season" $Season
on topic remote $Season_topic
do
if $Season = "Summer" then
setvar $Season = "Winter"
setvar $relay_status = 0
gpio_out 12 $relay_status
gpio_out 13 not ($relay_status)
else
setvar $Season = "Summer"
endif
on topic local $Voltage_topic
do
setvar $Volts = $this_data
setvar $int = csvstr($this_data, 0, ".")
setvar $frac = csvstr($this_data, 1, ".") | "0"
setvar $fixed_point = $int | substr($frac, 0, 1)
if 534 > $fixed_point then
setvar $run = 0
endif
if $Season = "Winter" then
setvar $run=0
endif
if 510 > $fixed_point then
setvar $relay_status = 0
gpio_out 12 $relay_status
gpio_out 13 not ($relay_status)
endif
if $run > 4 then
setvar $relay_status = 1
gpio_out 12 $relay_status
gpio_out 13 not ($relay_status)
endif
% println "Minutes passed="|$run
% Checking timer
on timer 1
do
setvar $run = $run + 1
% println "Minutes passed="|$run
if $run > 180 then
setvar $run = 180
endif
settimer 1 60000
on timer 2
do
if $Season = "Winter" then
setvar $run=0
setvar $relay_status = 0
gpio_out 12 $relay_status
gpio_out 13 not ($relay_status)
endif
publish local "stat/season" $Season
publish remote "stat/season" $Season
if $relay_status = 0 then
publish local $status_topic "Off"
publish remote $status_topic "Off"
else
publish local $status_topic "On"
publish remote $status_topic "On"
endif
publish remote $Voltage_topic $Volts
settimer 2 5000