Hardware:
- RadiationD-v1.1 (CAJOE)
- Gaiger tube J321 (kompatibilné s M4011)
- ESP8266 Wemos D1 mini Pro
- oled displej 128x32
- Batéria 3.7V 1500mAh
(Ďalšie súčiastky, nabijačka s boost modulom, odpory pre led, tranzistor a snimanie nabitia batérie, tranzistor 2N2222 na snimanie pripojenia nabijačky, led, kable, jumpere, dupont kable, skrutky)
Software:
Yaml kód:
Kód: Vybrat vše
substitutions:
friendly_name: ESP-Dozimeter
device_description: "Dozimeter Modul RadiationD-v1.1 (CAJOE) Tube J321, Create by TiiM 2022"
esphome:
name: esp-dozimeter
esp8266:
board: d1_mini_pro
# Enable logging
logger:
# Enable Home Assistant API
#api:
mqtt:
broker: '192.168.31.212'
username: !secret mqtt_username
password: !secret mqtt_password
discovery: true
# discovery_retain: false
birth_message:
will_message:
on_message:
- topic: esp-dozimeter/ota_mode
payload: 'ON'
then:
- deep_sleep.prevent: deep_sleep_1
deep_sleep:
id: deep_sleep_1
sleep_duration: 360s
run_duration: 120s
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
power_save_mode: HIGH
manual_ip:
# Set this to the IP of the ESP
static_ip: 192.168.31.89
# Set this to the IP address of the router. Often ends with .1
gateway: 192.168.31.1
# The subnet of the network. 255.255.255.0 works for most home networks.
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esphome-Web-B314B3"
password: "rFyPcvBKo1IV"
captive_portal:
i2c:
sda: D2
scl: D1
scan: true
status_led:
pin:
# Green LED
number: D6
sensor:
##WIFI
- platform: wifi_signal
name: "${friendly_name} Signal"
id: "signal"
update_interval: 30s
##BATTERY
- platform: adc
pin: A0
name: "${friendly_name} Battery"
accuracy_decimals: 2
update_interval: 60s
filters:
- multiply: 16.557
icon: mdi:battery
id: batlevel
#OLD STATUS POWER CHARGING
# on_value:
# then:
# - sensor.template.publish:
# id: latest_adc_sensor
# state: !lambda "return id(batlevel).state;"
# - script.execute: chargebattery
# - sensor.template.publish:
# id: adc_sensor
# state: !lambda "return id(batlevel).state;"
# internal: true
# - platform: template
# id: latest_adc_sensor
# name: "${friendly_name} Latest Battery"
# icon: "mdi:omega"
# unit_of_measurement: 'V'
# accuracy_decimals: 3
# filters:
# - median:
# window_size: 7
# send_every: 4
# send_first_at: 3
# internal: true
#
# - platform: template
# id: adc_sensor
# name: "${friendly_name} Battery"
# icon: "mdi:omega"
# unit_of_measurement: 'V'
# accuracy_decimals: 2
# filters:
# - median:
# window_size: 14
# send_every: 9
# send_first_at: 7
#GEIGER
- platform: pulse_counter
pin: D5
id: geigercounter
name: "${friendly_name} Radiation"
# update_interval: 1s
unit_of_measurement: 'µSv/h'
accuracy_decimals: 3
count_mode:
rising_edge: DISABLE
falling_edge: INCREMENT
icon: mdi:radioactive
filters:
# - multiply: 0.00812037037037 old
- multiply: 0.005966
# >0.81 >100cpm alert
# calculate tube m4011, mounted J321
# Gamma Sensitivity Ra226 (cps/mR/hr) 27 (SBM-20 = 29)
# Gamma Sensitivity Co60 (cps/mR/hr) 22
# (27+22)/2=24.5
# Multiply counts per second by 60 to get CPM: 24.5 x 60 = 1470 CPM
# absorption rate to be use is 8.77 which I understand is for air
# So finally the 1530 CPM is divided by the absorption rate of 8.77 to get ratio between CPM and uSv: 1470 / 8.77 = 167.617
# inverse 0.00596598639455782312925170068027
# https://sites.google.com/site/diygeigercounter/technical/gm-tubes-supported (method 2)
#POWER SENSOR
#Yellow led status
#Red led status battery not connected (broken)
binary_sensor:
- platform: gpio
pin:
number: D7
inverted: true
name: "${friendly_name} Charger"
device_class: power
id: chargerbattery
on_state:
then:
- light.toggle: oledlight
- if:
condition:
binary_sensor.is_on: chargerbattery
then:
- deep_sleep.prevent: deep_sleep_1
else:
- delay: 120sec
- deep_sleep.enter: deep_sleep_1
time:
- platform: sntp
id: esptime
timezone: "Europe/Bratislava"
light:
- platform: monochromatic
name: "${friendly_name} Brightness"
output: oled_bc
id: oledlight
output:
- platform: template
id: oled_bc
type: float
write_action:
then:
- lambda: id(oled).set_contrast(state);
min_power: 0.1
max_power: 1.0
script:
- id: oled_turn_on
mode: single
then:
#OLD STATUS POWER CHARGING
# - id: chargebattery
# mode: single
# then:
# Test battery charge
# - if:
# condition:
# for:
# time: 5sec
# condition:
# lambda: "return id(batlevel).state > id(latest_adc_sensor).state;"
# then:
# - text_sensor.template.publish:
# id: text_status
# state: "On"
#text_sensor:
##Battery Charge text
# - platform: template
# id: text_status
# name: "${friendly_name} Battery Charge"
# lambda: |-
# return {"Off"};
# icon: "mdi:water-circle"
display:
- platform: ssd1306_i2c
model: "SSD1306 128x32"
id: oled
reset_pin: D8
address: 0x3C
# invert: true
rotation: 180°
lambda: |-
int signal_wifi = int(id(signal).state);
float bat_level = (id(batlevel).state);
//GEIGER
if (id(geigercounter).has_state()) {
it.printf(0, 32, id(font2), TextAlign::BASELINE_LEFT, "%.3f", id(geigercounter).state);
}
it.print(56, 30, id(font3), TextAlign::BASELINE_LEFT, "µSv/h");
if (id(geigercounter).state >= 0.8) {
static int i = 0;
i++;
if ((i % 2) == 0)
it.printf(90, 30, id(font5), TextAlign::BASELINE_LEFT, "\U000F043C");
else
it.printf(90, 30, id(font5), TextAlign::BASELINE_LEFT, "\U000F11CF");
}
else {
it.printf(90, 30, id(font5), TextAlign::BASELINE_LEFT, "\U000F043C");
}
// signal
if (signal_wifi < 0 && signal_wifi >= -50) {
it.printf(62, 0, id(font4), TextAlign::TOP_CENTER, "\U000F08BE");
}
if (signal_wifi < -50 && signal_wifi >= -70) {
it.printf(62, 0, id(font4), TextAlign::TOP_CENTER, "\U000F08BD");
}
if (signal_wifi < -70 && signal_wifi >= -100) {
it.printf(62, 0, id(font4), TextAlign::TOP_CENTER, "\U000F08BC");
}
else {
it.printf(62, 0, id(font4), TextAlign::TOP_CENTER, "\U000F08BF");
}
// battery
if (bat_level >= 4.0) {
it.printf(73, -2, id(fontbattery), TextAlign::TOP_CENTER, "\U000F0079");
}
else if (bat_level < 4.0 && bat_level >= 3.8) {
it.printf(72, -1, id(fontbattery), TextAlign::TOP_CENTER, "\U000F0081");
}
else if (bat_level < 3.8 && bat_level >= 3.5) {
it.printf(72, -1, id(fontbattery), TextAlign::TOP_CENTER, "\U000F007F");
}
else if (bat_level < 3.5 && bat_level >= 3.3) {
it.printf(72, -1, id(fontbattery), TextAlign::TOP_CENTER, "\U000F007B");
}
else {
it.printf(72, -1, id(fontbattery), TextAlign::TOP_CENTER, "\U000F10CD");
}
// battery charge
if(id(chargerbattery).state) {
it.printf(82, -1, id(fontbattery), TextAlign::TOP_CENTER, "\U000F0241");
}
font:
- file: 'font_rg.ttf'
id: font1
size: 28
- file: 'font_rg.ttf'
id: font2
size: 38
- file: 'arial.ttf'
id: font3
size: 13
glyphs:
['&', '@', '!', ',', '.', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0',
'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z','å', 'ä', 'ö', '/','º','µ','³']
- file: 'materialdesignicons-webfont.ttf'
id: font4
size: 14
glyphs: [
"\U000F08BF", # no wifi
"\U000F08BC", # wifi low
"\U000F08BD", # mwifi middle
"\U000F08BE",# wifi high
]
- file: 'materialdesignicons-webfont.ttf'
id: fontbattery
size: 14
glyphs: [
"\U000F0079", # full
"\U000F0081", # 75
"\U000F007F", # 50
"\U000F007B", # 25
"\U000F10CD", # empty
"\U000F0241", # flash
"\U000F0904", # sleep
]
- file: 'materialdesignicons-webfont.ttf'
id: font5
size: 38
glyphs: [
"\U000F043C",# radioactive
"\U000F11CF",# alert
]
- Počitanie counterov
- Zobrazenie hodnoty radioaktivity uSv/h
(prepočet podľa typu trubice je napísaný v yaml kóde tak ako som postupoval ja a poďla Slvenského hydrometeorologického inštítútu https://www.shmu.sk/sk/?page=1&id=radio ... n_id=11813 pre Bratislavu mi dáva spárvne hodnoty, na obrázku nižšie vidíte až poslednú hodinu po zmene kódu a úpravy multiplieru začal dávať porovnateľné hodnoty. - 100% chod na batérií s deep sleep, napájanie plánujem z malého 5v solárneho panelu a poďla toho nastavím dĺžku uspania
- Detekcia pripojenia nabíjania
- Wifi a batéria stav na dipleji
- nad hodnotu 0,8uSv/h začne ikona radioaktivity blikať. (limitná hodnota pre bezpečnú radiaktivbitu vo vzduchu
Finálna verzia: Spodné jumpere ovládaju zapnutie a vipnutie napájanie a akustický signál