-
Notifications
You must be signed in to change notification settings - Fork 1
/
autoexec.be
83 lines (74 loc) · 2.23 KB
/
autoexec.be
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
#-
- Example of GGreg20_V3 driver written in Berry
- Copyright IoT-devices, LLC - Kyiv - Ukraine - 2022
- Note. You may additionaly use tasmota.cmd('counter1 0') to reset counter1
-#
import string
var ctr = 0
var cur_ctr = 0
var cpm = 0
var ma5_pointer = 1
var ma5_val = 0
ma5 = {}
class GGREG20_V3 : Driver
var st, fn
var num_ctr_val
var ctr_val
var st_ctr_val
var ctr
# print(tasmota.read_sensors())
def read_power()
import string
var st = number(string.find(tasmota.read_sensors(), "C1")+4)
var fn = number(string.find(tasmota.read_sensors(), "ESP32")-4)
var i = st
var ctr_val = ''
var ma5_sum = 0
while i <= fn do ctr_val = ctr_val + tasmota.read_sensors()[i]; i = i + 1 end end
if ctr == 0
self.st_ctr_val = number(ctr_val);
cur_ctr = self.st_ctr_val;
ctr = ctr + 1
end
if ctr == 60
self.st_ctr_val = number(ctr_val);
cur_ctr = self.st_ctr_val;
ma5[ma5_pointer] = self.num_ctr_val
var j = 1
while j <= size(ma5) do ma5_sum = ma5_sum + ma5[j]; j = j + 1 end end
ma5_val = ma5_sum / size(ma5)
if ma5_pointer <= 4
ma5_pointer = ma5_pointer + 1 else ma5_pointer = 1
end;
ctr = 0
end
cur_ctr = number(ctr_val)
cpm = cur_ctr - self.st_ctr_val
self.num_ctr_val = cpm * 0.0054
return self.num_ctr_val; self.st_ctr_val
end
#- trigger a read every second -#
def every_second()
self.read_power()
ctr = ctr + 1
end
#- display sensor value in the web UI -#
def web_sensor()
import string
var msg = string.format(
"{s}GGreg20_V3 cpm{m}%i CPM{e}"..
"{s}GGreg20_V3 power{m}%1.3f uSv/h{e}"..
"{s}GGreg20_V3 ma5{m}%1.3f uSv/h{e}",
cpm, self.num_ctr_val, ma5_val)
tasmota.web_send_decimal(msg)
end
#- add sensor value to teleperiod -#
def json_append()
import string
var power = self.num_ctr_val
var msg = string.format(",\"GGreg20_V3\":{\"cpm\":%i,\"power\":%1.3f,\"power ma5\":%1.3f}", cpm, power, ma5_val)
tasmota.response_append(msg)
end
end
GGREG20_V3 = GGREG20_V3()
tasmota.add_driver(GGREG20_V3)