-
Notifications
You must be signed in to change notification settings - Fork 1
/
ggreg20_v3_drv.be
95 lines (84 loc) · 2.91 KB
/
ggreg20_v3_drv.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
84
85
86
87
88
89
90
91
92
93
94
95
#-
- Example of GGreg20_V3 driver written in Berry
- Copyright IoT-devices, LLC - Kyiv - Ukraine - 2022
- License https://github.com/iotdevicesdev/ggreg20-v3-tasmota-esp32-driver/blob/main/LICENSE
- Note. You may additionaly use tasmota.cmd('counter1 0') to reset counter1
-#
tasmota.cmd('counter1 0')
import string
var factor_power = 0.0054 # Tubes can vary (+ -20%), so we recommend using a conversion factor of 0.0054 to 0.0092 and calibrating the calculations with a trusted (certified) device.
var ctr = 0
var cur_ctr = 0
var cpm = 0
var ma5_pointer = 1
var ma5_val = 0
var dose = 0
ma5 = {}
var pwr_minute = 0
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;
pwr_minute = cpm * factor_power
dose = dose + (pwr_minute / 60)
ctr = 0
end
cur_ctr = number(ctr_val)
cpm = cur_ctr - self.st_ctr_val
self.num_ctr_val = cpm * factor_power
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 seconds{m}%i / 60 sec{e}"..
"{s}GGreg20_V3 cpm{m}%i CPM{e}"..
"{s}GGreg20_V3 power{m}%1.3f uSv/h{e}"..
"{s}GGreg20_V3 power last minute{m}%1.3f uSv/h{e}"..
"{s}GGreg20_V3 dose{m}%1.4f uSv{e}"..
"{s}GGreg20_V3 ma5{m}%1.3f uSv/h{e}",
ctr, cpm, self.num_ctr_val, pwr_minute, dose, 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,\"dose\":%1.4f,\"power ma5\":%1.3f, \"power 1m\":%1.3f}", cpm, power, dose, ma5_val, pwr_minute)
tasmota.response_append(msg)
end
end
GGREG20_V3 = GGREG20_V3()
tasmota.add_driver(GGREG20_V3)