forked from iotdevicesdev/ggreg20-v3-tasmota-esp32-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ggreg20_v3_driver_v2.be
116 lines (102 loc) · 3.8 KB
/
ggreg20_v3_driver_v2.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#-
-----------------------------------------------------
| GGreg20_V3 Geiger Counter driver written in Berry |
| coded by aldweb (November 20th, 2023) |
-----------------------------------------------------
aldweb upgrade #4
- change: calibration factor upgraded to 0.00812
aldweb upgrade #3
- change: memory and code optimized
- new: 5 minutes CPM precision set to 1 digit after the decimal point
- cosmetic change: from "uSv" to "µSv"
aldweb upgrade #2
- new: full rewrite of the driver, to clean and beautify code
- new: include CPM 5 minutes average
aldweb upgrade #1
- fix: if the native temperature sensor of the ESP32 is not shown (SetOption146 0), then the driver would fail to run, this is corrected
- fix: as explained by distrubi (https://github.com/iotdevicesdev/ggreg20-v3-tasmota-esp32-driver/pull/1), "the calculated dose was waaaay too low", his fix - which also softcodes the conversion factor - was integrated
- new: since CPM count is reset every 60 seconds, added a time counter, which is basically to just display the value stored in the ctr variable
-#
tasmota.cmd('counter1 0')
#- Tubes can vary (+-20%) so recommendation is to use a conversion factor between 0.0054 and 0.0092
and to calibrate the calculations with a trusted (certified) device
if calibration not easily available, 0.0057 or 0.0065 are common values found on the www
there is also an explanation by the manufacturer of GGreg20_V3 Geiger Counter itself, suggesting to opt in for a value of 0.00812 (https://iot-devices.com.ua/en/technical-note-how-to-calculate-the-conversion-factor-for-geiger-tube-sbm20/)
-#
var GGpowerfactor = 0.00812
var GGtimer = 0
var GGcounter = 0
var GGcpt = 0
var GGpower = 0
var GGdose = 0
var GGcpm1 = 0
var GGcpm5 = 0
var GGpwr1 = 0
var GGpwr5 = 0
var GG5ptr = 1
GGcpm5data = {}
class GGREG20_V3 : Driver
# print(tasmota.read_sensors())
#- read and calculate accordingly -#
def read_power()
import string
var i = number(string.find(tasmota.read_sensors(), "C1")+4)
var counterstr = ''
var cpm5sum = 0
while tasmota.read_sensors()[i] != "}"
counterstr = counterstr + tasmota.read_sensors()[i]
i = i + 1
end
var counter = number(counterstr)
if GGtimer >= 60
GGcpm5data[GG5ptr] = GGcpt
GGcpm1 = GGcpt
GGpwr1 = GGpower
var j = 1
while j <= size(GGcpm5data)
cpm5sum = cpm5sum + GGcpm5data[j]
j = j + 1
end
GGcpm5 = 1.0 * cpm5sum / size(GGcpm5data)
GGpwr5 = GGcpm5 * GGpowerfactor
if GG5ptr <= 4
GG5ptr = GG5ptr + 1
else
GG5ptr = 1
end
GGdose = GGdose + (GGpower / 60)
GGcounter = counter
GGtimer = 0
end
GGcpt = counter - GGcounter
GGpower = GGcpt * GGpowerfactor
end
#- trigger a read every second -#
def every_second()
self.read_power()
GGtimer = GGtimer + 1
end
#- display sensor value in the web UI -#
def web_sensor()
import string
var msg = string.format(
"{s}GGreg20_V3 timer{m}%i seconds{e}"
"{s}GGreg20_V3 cpt{m}%i CpT{e}"
"{s}GGreg20_V3 powert{m}%1.3f µSv/h{e}"
"{s}GGreg20_V3 cpm1m{m}%i CpM{e}"
"{s}GGreg20_V3 power1m{m}%1.3f µSv/h{e}"
"{s}GGreg20_V3 cpm5m{m}%1.1f CpM{e}"
"{s}GGreg20_V3 power5m{m}%1.3f µSv/h{e}"
"{s}GGreg20_V3 dose{m}%1.4f µSv{e}",
GGtimer, GGcpt, GGpower, GGcpm1, GGpwr1, GGcpm5, GGpwr5, GGdose)
tasmota.web_send_decimal(msg)
end
#- add sensor value to teleperiod -#
def json_append()
import string
var msg = string.format(",\"GGreg20_V3\":{\"sec\":%i,\"cpt\":%i,\"powert\":%1.3f,\"cpm1m\":%i,\"power1m\":%1.3f,\"cpm5m\":%1.1f,\"power5m\":%1.3f,\"dose\":%1.4f}", GGtimer, GGcpt, GGpower, GGcpm1, GGpwr1, GGcpm5, GGpwr5, GGdose)
tasmota.response_append(msg)
end
end
GGREG20_V3 = GGREG20_V3()
tasmota.add_driver(GGREG20_V3)