Skip to content

Commit a86f92b

Browse files
Merge pull request #6 from astraliens/main
feat: Increase update frequency for sensors
2 parents 74e0486 + 7b5df4a commit a86f92b

File tree

1 file changed

+64
-18
lines changed

1 file changed

+64
-18
lines changed

esp32-ggreg20-v3.yaml

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,51 +28,97 @@ wifi:
2828

2929
captive_portal:
3030

31+
globals:
32+
- id: pulse_history
33+
type: int[60]
34+
restore_value: no
35+
initial_value: "{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}"
36+
37+
- id: pulse_index
38+
type: int
39+
restore_value: no
40+
initial_value: "0"
41+
42+
- id: pulse_sum
43+
type: int
44+
restore_value: no
45+
initial_value: "0"
46+
3147
# Here we calc and include to the firmware a power and dose values of ionizing radiation as sensor outputs
3248
sensor:
3349
- platform: pulse_counter
50+
id: geiger_cps
51+
internal: true
3452
pin:
3553
number: 23
3654
inverted: True
37-
mode:
38-
input: True
55+
mode:
56+
input: True
3957
# No pullup or pulldown on ESP32 side because of internal pullup set in hardware at GGreg20_V3 pulse output side
4058
pullup: False
4159
pulldown: False
42-
unit_of_measurement: 'CPM'
43-
name: 'Ionizing Radiation Power CPM'
44-
count_mode:
60+
unit_of_measurement: 'CPS'
61+
name: 'Ionizing Radiation Power CPS'
62+
count_mode:
4563
rising_edge: DISABLE
4664
falling_edge: INCREMENT # GGreg20_V3 uses Active-Low logic
47-
# See ESPHome pulse_counter's internal filter in software mode issue here:
65+
# See ESPHome pulse_counter's internal filter in software mode issue here:
4866
# https://github.com/iotdevicesdev/GGreg20_V3-ESP32-HomeAssistant-ESPHome/issues/5
4967
# Issue walkaround is to disable these two lines:
5068
# use_pcnt: False ### disabled on 30/12/2024
5169
# internal_filter: 190us # for SBM20 tube, for J305 tube use 180us ### disabled on 30/12/2024
52-
update_interval: 60s
5370
accuracy_decimals: 0
54-
id: my_cpm_meter
55-
71+
update_interval: 1s
72+
filters:
73+
delta: 1
74+
on_raw_value:
75+
then:
76+
- lambda: |-
77+
x=round(x/60); // esphome calculating based on pulses per minute. round required to avoid problem when esphome calc value less than 60 pulses per minute (for example 59.7)
78+
id(pulse_sum) -= id(pulse_history)[id(pulse_index)]; // remove old value from overall sum
79+
id(pulse_history)[id(pulse_index)] = x; // 'x' is the raw pulse count
80+
id(pulse_sum) += x; // add new value to overall sum
81+
82+
id(pulse_index)++; // change array index where next value will be stores
83+
if (id(pulse_index) >= 60) id(pulse_index) = 0; // Reset at 60
84+
on_value:
85+
then:
86+
component.update: geiger_cpm
87+
88+
- platform: template
89+
id: geiger_cpm
90+
unit_of_measurement: 'CPM'
91+
name: 'Ionizing Radiation Power CPM'
92+
accuracy_decimals: 0
93+
update_interval: 1s
94+
state_class: measurement
95+
lambda: return id(pulse_sum);
96+
filters:
97+
delta: 1
98+
5699
- platform: copy
57-
source_id: my_cpm_meter
58-
unit_of_measurement: 'uSv/Hour'
100+
source_id: geiger_cpm
101+
id: ionizing_radiaton_power
102+
unit_of_measurement: 'µSv/h'
59103
name: 'Ionizing Radiation Power'
104+
state_class: measurement
105+
icon: mdi:radioactive
60106
accuracy_decimals: 3
61-
id: my_dose_meter
62107
filters:
63-
- sliding_window_moving_average: # 5-minutes moving average (MA5) here
64-
window_size: 5
65-
send_every: 1
66-
- multiply: 0.0057 # or 0.00332 for J305 by IoT-devices tube conversion factor of pulses into uSv/Hour
108+
- skip_initial: 15
109+
- sliding_window_moving_average: # 15 measurements moving average (MA5) here
110+
window_size: 15
111+
send_every: 1
112+
- multiply: 0.0057 # 0.0057 original value or 0.00332 for J305 by IoT-devices tube conversion factor of pulses into uSv/Hour
67113

68114
- platform: integration
69115
name: "Total Ionizing Radiation Dose"
70116
unit_of_measurement: "uSv"
71-
sensor: my_dose_meter # link entity id to the pulse_counter values above
117+
sensor: ionizing_radiaton_power # link entity id to the pulse_counter values above
72118
icon: "mdi:radioactive"
73119
accuracy_decimals: 5
74120
time_unit: min # integrate values every next minute
75121
filters:
76-
# obtained dose. Converting from uSv/hour into uSv/minute: [uSv/h / 60] OR [uSv/h * 0.0166666667].
122+
# obtained dose. Converting from uSv/hour into uSv/minute: [uSv/h / 60] OR [uSv/h * 0.0166666667].
77123
# if my_dose_meter in CPM, then [0.0057 / 60 minutes] = 0.000095; so CPM * 0.000095 = dose every next minute, uSv.
78124
- multiply: 0.0166666667

0 commit comments

Comments
 (0)