Rain drop detector

www
mamonick
Dárce - Donátor
Dárce - Donátor
Příspěvky: 187
Registrován: 20. září 2021, 13:47
Bydliště: Třebechovice p. O.
Dal poděkování: 23 poděkování
Dostal poděkování: 22 poděkování

Re: Rain drop detector

Příspěvek od mamonick »

Dobře Ty! ;)
Já bych určitě měl zájem o kód. Pokud se dívám správně, senzory stanice máš na třech deskách.
já teď stavím meteo - zatím mám teplotu, tlak, vlhkost, pm2,5 a pm10.
No a chci přidat
  • senzor deště
  • úhrn srážek
  • síla větru
  • směr větru
Takže to je to, co máš Ty ;)

Uživatelský avatar
tiimsvk
Dárce - Donátor
Dárce - Donátor
Příspěvky: 800
Registrován: 06. květen 2021, 07:03
Dal poděkování: 72 poděkování
Dostal poděkování: 65 poděkování

Re: Rain drop detector

Příspěvek od tiimsvk »

Kód pre esp_wheaterstation s deep sleep: (tu sa nachadzaju senzory aj pre rychlosť a smer vetra)

Kód: Vybrat vše

substitutions:
  friendly_name: ESP-WheaterStation
  device_name: esp32-wheaterstation
  status_led: GPIO26

esphome:
  name: esp32-wheaterstation
  platform: ESP32
  board: esp32dev

# Enable logging
logger:
#  level: WARN

# 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:
    topic: $device_name/status
    payload: online
  will_message:
    topic: $device_name/status1
    payload: offline
  on_message:
    - topic: esp32-wheaterstation/ota_mode
      payload: 'ON'
      then:
        - deep_sleep.prevent: deep_sleep1

ota:
  password: "a2d4a7b35e971cf5e681d99856c37536"

wifi:
#  power_save_mode: HIGH
  fast_connect: on
  ssid: "DreamLoveHome"
  password: "ZelenyDom2"
  manual_ip:
    # Set this to the IP of the ESP
    static_ip: 192.168.31.229
    # 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: "Esp32-Wheaterstation"
    password: "wheaterstation"

captive_portal:

#Status LED for connection
status_led:
  pin:
    # Blue LED
    number: ${status_led}

i2c:
    sda: 21
    scl: 22 #hnedy -> oranžovy
    scan: true
#    frequency: 100khz

sensor:
##CO2 sensor
#  - platform: adc
#    pin: GPIO33
#    name: "${friendly_name} - CO2"
#    accuracy_decimals: 2
#    update_interval: 60s
#    filters:
#      - multiply: 1150
#    unit_of_measurement: 'ppm'
##CO2 sensor V
#  - platform: adc
#    pin: GPIO33
#    name: "${friendly_name} - CO2 - V"
#    accuracy_decimals: 2
#    update_interval: 60s

## Wifi signal 
  - platform: wifi_signal
    name: "${friendly_name} Signal"
    update_interval: 240s
    filters:
      - multiply: 1.0

##Light sensor BH1750
  - platform: bh1750
    name: "${friendly_name} LUX"
    address: 0x23
#    measurement_duration: 128
    update_interval: 15s

##Temp sensor DHT22 - broken unplugged
#  - platform: dht
#    model: AM2302
#    pin: GPIO5
#    temperature:
#      id: dht22_temp
#      name: "${friendly_name} DHT22 Temperature"
#      internal: true
#    humidity:
#      name: "${friendly_name} Humidity"
#      id: dht22_humidity
#    update_interval: 10s

##DEW POINT
  - platform: template
    name: "${friendly_name} Dew Point"
    icon: "mdi:thermometer"
    filters:
      - filter_out: nan
    unit_of_measurement: "°C"
    lambda: |-
      return (id(bmp280_temp).state - (100 - id(aht20_humidity).state) / 5);  

##BMP 280 sensor Pressure
  - platform: bmp280
#    iir_filter: 16x
    temperature:
      id: bmp280_temp
      name: "${friendly_name} BMP280 Temperature"
      oversampling: 16x
#      internal: true
    pressure:
      name: "${friendly_name} Pressure"
      oversampling: 16x
    address: 0x77
    update_interval: 10s

  - platform: aht10
#    update_interval: 30s
    temperature:
      name: "${friendly_name} AHT Temperature"
      id: aht20_temp
      accuracy_decimals: 1
      filters:
        - offset: -1.5
    humidity:
      name: "${friendly_name} Humidity"
      id: aht20_humidity
      accuracy_decimals: 1
      filters:
#        - offset: 8.0

  - platform: template
    name: "${friendly_name} Temperature"
    icon: "mdi:thermometer"
    unit_of_measurement: "°C"
    lambda: |-
      return (
        id(bmp280_temp).state
        +
        id(aht20_temp).state
      ) / 2;
    update_interval: 15s

#  - platform: adc
#    pin: A0
#    name: "Water Pressure"
#    id: 'WaterPressure'
#    filters:
#    - offset: 0.5
#    - lambda: return x * 3.3 / 1024 #not sure if this should be the supply voltage of 5v or 3.3V
#    update_interval: 1s

##SOUND DETECT

##WIND SPEED
  - platform: pulse_counter
    pin: 
      number: GPIO27
      mode:
        input: true
        pullup: true
    unit_of_measurement: 'km/h'
    name: "${friendly_name} Wind Speed"
    icon: 'mdi:weather-windy'
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 13us
#    update_interval: 60s
    # rotations_per_sec = pulses / 2 / 60
    # circ_m = 0.09 * 2 * 3.14 = 0.5652
    # mps = 1.18 * circ_m * rotations_per_sec
    # mps = 1.18 * 0.5652 / 2 / 60 = 0,0055578
    filters:
#      - multiply: 0.0055578 =m/s
# km/h *3,6
      - multiply: 0.02000808
      #- sliding_window_moving_average:
      #    window_size: 2
      #    send_every: 1

##WIND DIRECTION
  - platform: adc
    id: source_sensor
    pin: GPIO39
#    name: ${friendly_name} ADC
    attenuation: 11db
    internal: true
    update_interval: 15s
    accuracy_decimals: 1
    filters:
      - multiply: 0.846153 # 3.9 -> 3.3V

  - platform: resistance
    sensor: source_sensor
    id: resistance_sensor_wind
    configuration: DOWNSTREAM
    resistor: 10kOhm
    internal: true
#    name: ${friendly_name} - Resistance Sensor
    reference_voltage: 3.9V
    accuracy_decimals: 1
    filters:
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 3
      #- heartbeat: 30s
    on_value:
#SEVER
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor_wind
              above: 4000
              below: 5500
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "SEVER"
            - sensor.template.publish:
                id: wind_heading
                state: 0.0
#SEVEROVÝCHOD
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor_wind
              above: 500
              below: 800
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "SEVEROVÝCHOD"
            - sensor.template.publish:
                id: wind_heading
                state: 45.0
#VÝCHOD
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor_wind
              above: 1400
              below: 2200
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "VÝCHOD"
            - sensor.template.publish:
                id: wind_heading
                state: 90.0
#JUHOVÝCHOD
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor_wind
              above: 2000
              below: 3000
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "JUHOVÝCHOD"
            - sensor.template.publish:
                id: wind_heading
                state: 135.0
#JUH
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor_wind
              above: 7500
              below: 10000
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "JUH"
            - sensor.template.publish:
                id: wind_heading
                state: 180.0
#JUHOZÁPAD
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor_wind
              above: 19500
              below: 21500
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "JUHOZÁPAD"
            - sensor.template.publish:
                id: wind_heading
                state: 225.0
#ZÁPAD
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor_wind
              above: 15000
              below: 17500
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "ZÁPAD"
            - sensor.template.publish:
                id: wind_heading
                state: 270
#SEVEROZÁPAD
      - if:
          condition:
            sensor.in_range:
              id: resistance_sensor_wind
              above: 11000
              below: 13000
          then:
            - text_sensor.template.publish:
                id: wind_dir_card
                state: "SEVEROZÁPAD"
            - sensor.template.publish:
                id: wind_heading
                state: 315.0

  - platform: template
    name: "${friendly_name} Wind Heading"
    id: wind_heading
    unit_of_measurement: "°"

##UV index
  - platform: adc
    id: adcuv
    pin: GPIO34
    attenuation: 11dB
    name: "UV Intensity"
    update_interval: 10s
    filters:
      # No value lower than 0
      - lambda: 'return max((float)0.99, x);'
      # No value greater than $max_resistance
      - lambda: 'return min((float)2.8, x);'
    unit_of_measurement: 'mW/cm^2'

  - platform: template
    name: "${friendly_name} UV Index"
    lambda: |-
       return ((id(adcuv).state - 1.0) * (15.0 - 0.0) / (2.8 - 1.0) + 0.0);
#      return ((id(adcuv).state - 0.99) * (15.0 - 0.0) / (2.8 - 0.99) + 0.0);
    update_interval: 20s
    unit_of_measurement: "UV"
    icon: 'mdi:sunglasses'
    filters:
      - calibrate_linear:
          # Map 0.0 (from sensor) to 0.0 (true value)
          - 0.2 -> 0.0
          - 0.49 -> 0.1
          - 1.4 -> 5.0
          - 3.5 -> 8.0
      - lambda: 'return max((float)0, x);'
      - filter_out: 0.0

text_sensor:
##WIND DIRECTION TEXT
  - platform: template
    name: "${friendly_name} Wind Direction"
    id: wind_dir_card

  - platform: template
    id: text_sound
    name: "${friendly_name} Sound Detect"
    lambda: !lambda |-
      if (id(sound_level).state) {
        return {"Silence"};
      } else {
        return {"Detected"};
      }
    update_interval: 60s

##LED BLUE
light:
  - platform: binary
    name: "${friendly_name} Led Shield"
    output: blue_led
#    effects:
#      - strobe:

output:
  - id: blue_led
    platform: gpio
    pin: GPIO26

switch:
##RESTART ESP
  - platform: restart
    name: "${friendly_name} Restart"

##SOUND DETECTED
binary_sensor:
  - platform: gpio
    id: sound_level
    pin: 33
    name: "Sound level"
    filters:
#      - invert:
      - delayed_on: 1s
      - delayed_off: 1s
    internal: true

##TIME
time:
  - platform: sntp
    timezone: "Europe/Bratislava"
##DEEP SLEEP
deep_sleep:
  id: deep_sleep1
  run_duration: 30sec
  sleep_duration: 1min
esp_airquality bez deep sleep senzory pre dážď, ktoré musia fungovať bez uspania

Kód: Vybrat vše

substitutions:
  device_name: ESP-AirQuality
  friendly_name: ESP-AirQuality
  device_description: "ESP-Airquality"
  hostname: 'esp-airquality'
  status_led: GPIO27

#Rain drop
  resistor_value: "9.9kOhm"
  
 # Value of the resistance at which a significant change is considered
 # to occur
  rain_detection_threshold: "4000"
 
 # If the resistance increases by this value, the sensor is considered
 # to be dry
  dry_detection_threshold: "4000"
 
 # When booting, if the resistance is lower this value, assume sensor is wet
  wet_resistance_when_booting: "30000"
 
 # +------------------------------+
 # | Delay between 2 rain measure |
 # +------------------------------+
 # In dry mode
  measure_interval_dry: "15000"
 
 # In wet mode
 # Must be large enough not to damage the tracks prematurely
 # but small enough to be reactive enough.
  measure_interval_wet: "30000"
 
 # Stabilization before reading the resistance
 # A too short delay will not allow to read the low resistances
  stabilization_delay: 4sec

esphome:
  name: $hostname
  platform: ESP32
  board: esp32dev
#Rain drop
  on_boot:
    then:
      - script.execute: test_resistance
      - script.execute: measure_loop
logger:

# Enable Home Assistant API
api:
  reboot_timeout: 0s
ota:

web_server:
  port: 80

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: True
  manual_ip:
    static_ip: 192.168.31.190
    gateway: 192.168.31.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Airquality Fallback Hotspot"
    password: "GzcBzxK8Tctq"

captive_portal:

#RainDrop
globals:
  - id: measure_delay
    type: int
    restore_value: yes
    initial_value: $measure_interval_dry

script:
  - id: switch_off_battery_charge
    mode: single
    then:
      - switch.turn_off: battery_charger
  - id: begin_measure
    mode: single
    then:
      - switch.turn_on: resistance_bias
      - delay: $stabilization_delay

  - id: end_measure
    mode: single
    then:
      - switch.turn_off: resistance_bias

  - id: test_resistance
    mode: single
    then:
      - script.execute: begin_measure
      - script.wait: begin_measure

      - if:
          condition:
            lambda: "return id(resistance_sensor).state < $wet_resistance_when_booting;"
          then:
            - script.execute: its_raining

      - script.execute: end_measure
      - script.wait: end_measure

  - id: save_current_resistance
    then:
      - sensor.template.publish:
          id: latest_resistance_sensor
          state: !lambda "return id(resistance_sensor).state;"
      - sensor.template.publish:
          id: latest_average_resistance_sensor
          state: !lambda "return id(average_resistance_sensor).state;"

  # Currently:
  # * Rain is detected with the most recent value compared to a threshold
  # * To detect when it dries, we use the average

  # To be tested:
  # The lowest resistance that corresponds to a complete saturation
  # of the sensor is permanently recorded: If this value is not reached
  # but the resistance does not decrease during a period of time,
  # we know that it is not raining anymore.

  - id: update_average_values
    mode: single
    then:
      # Set the average resistance
      - if:
          condition:
            lambda: "return (id(resistance_sensor).state >= 0 && id(resistance_sensor).state <= 50000);"
          then:
            - sensor.template.publish:
                id: average_resistance_sensor
                state: !lambda "return id(resistance_sensor).state;"

  - id: measure
    mode: single
    then:
      - script.execute: begin_measure
      - script.wait: begin_measure

      # Init latest resistance value if not a number
      - if:
          condition:
            lambda: "return isnan(id(latest_resistance_sensor).state);"
          then:
            - script.execute: save_current_resistance
            - script.wait: save_current_resistance
      - if:
          condition:
            lambda: "return isnan(id(latest_average_resistance_sensor).state);"
          then:
            - script.execute: save_current_resistance
            - script.wait: save_current_resistance

      - script.execute: update_average_values

      # Test for raining
      - if:
          condition:
            for:
              time: 30sec
              condition:
                lambda: "return id(resistance_sensor).state + $rain_detection_threshold < id(latest_resistance_sensor).state;"
          then:
            - script.execute: its_raining

      # Test for drying
      - if:
          condition:
            lambda: "return id(average_resistance_sensor).state - $dry_detection_threshold > id(latest_average_resistance_sensor).state;"
          then:
            - script.execute: its_drying

      # Test for dry
      # We assume sensor is dry when current resistance == max resistance
      - if:
          condition:
            lambda: "return id(resistance_sensor).state > 45000;"
          then:
            - script.execute: its_dry

      - script.execute: end_measure
      - script.wait: end_measure

  - id: measure_loop
    mode: single
    then:
      - while:
          condition:
            lambda: "return true;"
          then:
            - script.execute: measure
            - script.wait: measure
            - delay: !lambda "return id(measure_delay);"

  - id: its_raining
    mode: single

    then:
      - script.execute: save_current_resistance
      - script.wait: save_current_resistance
      - homeassistant.event:
          event: esphome.its_raining
      - text_sensor.template.publish:
          id: text_status
          state: "Raining"
      - globals.set:
          id: measure_delay
          value: $measure_interval_wet

  - id: its_drying
    mode: single
    then:
      - script.execute: save_current_resistance
      - script.wait: save_current_resistance
      - text_sensor.template.publish:
          id: text_status
          state: "Drying"
      - globals.set:
          id: measure_delay
          value: $measure_interval_wet

  - id: its_dry
    mode: single
    then:
      - script.execute: save_current_resistance
      - script.wait: save_current_resistance
      - text_sensor.template.publish:
          id: text_status
          state: "Dry"
      - globals.set:
          id: measure_delay
          value: $measure_interval_dry

uart:
  - id: uart2
    rx_pin: GPIO14
    baud_rate: 9600
  
  - id: uart1
    rx_pin: GPIO17
    tx_pin: GPIO13
    baud_rate: 9600
 

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true

#Status LED for connection
status_led:
  pin:
    # Red LED on Cam Spot
    number: ${status_led}
    inverted: true

#as3935_i2c:
#  irq_pin: GPIO16
#  indoor: False
#  spike_rejection: 5
#mqtt:
#  broker: 192.168.31.212
#  port: 1883
#  username: admin
#  password: admin
#  client_id: "${device_name}"
#  discovery: True
#  client_id: hassio-mqtt-client
#  discovery_retain: False
#  birth_message:
#  will_message:

text_sensor:
##RAIN DROPS
  - platform: template
    id: text_status
    name: "${friendly_name} Raining Sensor"
    lambda: |-
      return {"Dry"};
    icon: "mdi:water-circle"

#binary_sensor:
#  - platform: as3935
#    name: "Storm Alert"

sensor:
#  - platform: as3935
#    lightning_energy:
#      name: "Lightning Energy"
#    distance:
#      name: "Distance Storm"

##WIFI SIGNAL
  - platform: wifi_signal
    name: "${friendly_name} Signal"
    update_interval: 320s
    filters:
      - multiply: 1.0

##SMOKE DETECTOR
  - platform: adc
    name: "${friendly_name} Smoke Detector"
    pin: GPIO39
    update_interval: 60s                # You can change that
    filters:
      - multiply: 100
      - quantile:
          window_size: 7
          send_every: 4
          send_first_at: 3
          quantile: .5
    unit_of_measurement: "%"
    icon: "mdi:smoke"               # You can change that

##TEMP CHASE BATTERY
  - platform: adc
    id: ntc_adc_sensor
    pin: GPIO36
#    attenuation: 11db #(on esp32)
    update_interval: 5s
    internal: true

  - platform: resistance
    name: "${friendly_name} NTC Resistance"
    id: ntc_resistance_sensor
    sensor: ntc_adc_sensor
    configuration: DOWNSTREAM
    resistor: 10kOhm
    internal: true

  - platform: ntc
    name: "${friendly_name} Temperature Battery"
    sensor: ntc_resistance_sensor
    accuracy_decimals: 1
    calibration:
      - 1.580kOhm -> 58°C
      - 0.950kOhm -> 24°C
      - 0.012kOhm -> 1°C
#    filters:
#    - offset: -10

#RAIN DROPS
  - platform: adc
    id: source_sensor2
    pin: GPIO34
    name: ADC
    attenuation: 11db
    internal: true

    # It is important to have a low update interval so that
    # the measurement has time to be done correctly during
    # the activation of the voltage AND taking into account the median filter
    update_interval: 250ms

    filters:
#      - multiply: 0.846153 # 3.9 (11db attenuation full-scale voltage) -> 3.3V
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 3

  - platform: resistance
    sensor: source_sensor2
    id: real_resistance_sensor
    name: "${friendly_name} Resistance"
    configuration: DOWNSTREAM
    resistor: $resistor_value
    reference_voltage: 3.3V
    internal: true
    icon: "mdi:omega"
    filters:
      # No value lower than 0
      - lambda: 'return max((float)1000, x);'
      # No value greater than $max_resistance
      - lambda: 'return min((float)50000, x);'
    on_value:
      then:
        - if:
            condition:
              lambda: |-
                  return (
                      id(real_resistance_sensor).state > 1000
                      &&
                      // <= is important to force the resistance to the max
                      // in order to have a value to compare if the
                      // resistance drops
                      id(real_resistance_sensor).state <= 50000
                  );
            then:
              - sensor.template.publish:
                  id: resistance_sensor
                  state: !lambda "return id(real_resistance_sensor).state;"

  - platform: template
    id: latest_resistance_sensor
    name: "${friendly_name} latest resistance"
    icon: "mdi:omega"
    unit_of_measurement: 'Ω'
    internal: true

  - platform: template
    id: latest_average_resistance_sensor
    name: "${friendly_name} latest average resistance"
    icon: "mdi:omega"
    unit_of_measurement: 'Ω'
    internal: true

  - platform: template
    id: resistance_sensor
    name: "${friendly_name} RainDrop Resistance"
    icon: "mdi:omega"
    unit_of_measurement: 'Ω'

  - platform: template
    id: average_resistance_sensor
    name: "${friendly_name} average resistance"
    icon: "mdi:omega"
    unit_of_measurement: 'Ω'
    filters:
      - sliding_window_moving_average:
          window_size: 5
          send_every: 5
      #- heartbeat: 2min
    internal: true

##CCS811 CO2 SENSOR
#  - platform: ccs811
#    eco2:
#      name: "${friendly_name} eCO2"
#    tvoc:
#      name: "${friendly_name} TVOC"
#    address: 0x5A
#    update_interval: 120s
#    baseline: 0x06BD

  - platform: mhz19
    co2:
      name: "MH-Z19 CO2 Value"
    temperature:
      name: "MH-Z19 Temperature"
    update_interval: 10s
    automatic_baseline_calibration: false
    uart_id: uart1

##INA3221 DC current sensor
  - platform: ina3221
    address: 0x40
    channel_1:
      shunt_resistance: 0.1 ohm
      current:
        name: "${friendly_name} Current Solar"
        accuracy_decimals: 3
      power:
        name: "${friendly_name} Power Solar"
        accuracy_decimals: 3
        id: solar_power
      bus_voltage:
        name: "${friendly_name} Voltage Solar"
      shunt_voltage:
        name: "${friendly_name} - Shunt Voltage Solar"
        internal: true
    channel_2:
      shunt_resistance: 0.1 ohm
      current:
        name: "${friendly_name} Current Charger"
      power:
        name: "${friendly_name} Power Charger"
      bus_voltage:
        name: "${friendly_name} Voltage Charger"
      shunt_voltage:
        name: "${friendly_name} Shunt Voltage Charger"
        internal: true
    channel_3:
      shunt_resistance: 0.1 ohm
      current:
        name: "${friendly_name} Current Battery"
        accuracy_decimals: 3
      power:
        name: "${friendly_name} Power Battery"
        accuracy_decimals: 3
      bus_voltage:
        name: "${friendly_name} Voltage Battery"
        #low battery script
        on_value_range:
        - below: 3.0
          then:
            - switch.turn_on: battery_charger
        - above: 3.95
          then:
            - switch.turn_off: battery_charger
      shunt_voltage:
        name: "${friendly_name} Shunt Voltage Battery"
        internal: true

    update_interval: 10s
  - platform: total_daily_energy
    name: "${friendly_name} Solar Energy"
    power_id: solar_power

##SOLAR RADIATION
  - platform: template
    name: "${friendly_name} Solar Radiation"
    icon: "mdi:solar-power"
    unit_of_measurement: "(W/m2)/day"
    lambda: |-
      return (id(solar_power).state * (1 / (0.2 * 0.3)) * 24);  
#      watt*(1m2/(a*b))*24
      
#      1 kW/m2 × (24 h/day) = (24 kWh/m2)/day

##IKEA PM2.5 SENSOR
  - platform: pm1006
    pm_2_5:
      name: "${friendly_name} PM2.5"
      filters:
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 3
#    update_interval: 15s
    uart_id: uart2

##RAIN SENSOR TIIM
  - platform: pulse_counter
    pin:
      number: GPIO19
      mode: INPUT_PULLUP
    unit_of_measurement: 'mm/min'
    name: "${friendly_name} Rainfall"
    icon: 'mdi:weather-rainy'
    id: rain_gauge
#    internal: true
    count_mode:
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 13us
    update_interval: 60s
    filters:
      - multiply: 0.2794
    accuracy_decimals: 2

  - platform: total_daily_energy
    name: "${friendly_name} Rainfall Daily"
    power_id: rain_gauge
    unit_of_measurement: 'mm'
    icon: 'mdi:weather-rainy'
    # x60 To convert to aggregated rain amount
    filters:
      - multiply: 60
    accuracy_decimals: 2

switch:
##BATTERY CHARGER SWITCH
  - platform: gpio
    id: battery_charger
    restore_mode: ALWAYS_OFF
    pin:
      number: GPIO17
#      inverted: true
    name: "'${friendly_name} Battery Charger"
     
##LED CAM WHITE
  - platform: gpio
    pin: GPIO25
    name: "'${friendly_name} Led White"

##LED CAM RED
#  - platform: gpio
#    pin:
#      number: GPIO27
#      inverted: true
#    name: "'${friendly_name} Led Red"

##RAIN DROP
  - platform: gpio
    id: resistance_bias
    name: "${friendly_name} RainDrop Test"
    icon: "mdi:power"
    pin:
      number: GPIO05
      mode: OUTPUT

##WHEATERSTATION SWITCH
  - platform: gpio
    restore_mode: ALWAYS_ON
    pin:
      number: GPIO13
#      inverted: true
    name: "'${friendly_name} WheaterStation"

##RESTART ESP32s
  - platform: restart
    name: "'${friendly_name} AirQuality"

##TIME
# Enable time component to reset energy at midnight

time:
  - platform: homeassistant
    id: homeassistant_time
A bonus kamera:

Kód: Vybrat vše

substitutions:
  # Modify variables based on your settings
  friendly_name: ESP-AirQuality-Cam

esphome:
  name: esp-airquality-cam
  
esp32:
  board: esp32dev
#  framework:
#    type: arduino
#    version: 1.0.5

# 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:

ota:
  password: "1d268f331a8ae2acf01f28b93624d651"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: True
  manual_ip:
    static_ip: 192.168.31.162
    gateway: 192.168.31.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Cam3 Fallback Hotspot"
    password: "7iNJ5ImnusGd"

captive_portal:

# ESP32-CAM
#  resolution: VGA
#  jpeg_quality: 10
#  max_framerate: 10fps
#  idle_framerate: 0.1fps
#  vertical_flip: true
#  horizontal_mirror: true

esp32_camera:
  name: "${friendly_name} Camera"
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  resolution: 640x480

sensor:
# Wifi signal 
  - platform: wifi_signal
    name: "${friendly_name} Signal"
    update_interval: 120s
# Flashlight
output:
  - platform: gpio
    pin: GPIO4
    id: gpio_4
light:
  - platform: binary
    output: gpio_4
    name: "${friendly_name} Led"
    icon: "mdi:led-outline"

switch:
##RESTART ESP
  - platform: restart
    name: "${friendly_name} Restart"

  - platform: gpio
    restore_mode: ALWAYS_OFF
    pin: #GPIO12
      number: GPIO13
#      inverted: true

#      mode:
#        input: true
#        pulldown: true

    name: "${friendly_name} IR Light"
    icon: "mdi:spotlight-beam"
Samozrejme stále ju vylepšujem a po včerajších úravach odtial vypadli switche na nabijanie a manualny reštart ale ešte to nemam v kode opravené.
Ak budeš mať nejaké vylepšenia sem s nimi, ale asi do nového vlakna by som dal :)

mamonick
Dárce - Donátor
Dárce - Donátor
Příspěvky: 187
Registrován: 20. září 2021, 13:47
Bydliště: Třebechovice p. O.
Dal poděkování: 23 poděkování
Dostal poděkování: 22 poděkování

Re: Rain drop detector

Příspěvek od mamonick »

Super! Díky moc. O víkendu na ty yamly kouknu podrobněji.

mamonick
Dárce - Donátor
Dárce - Donátor
Příspěvky: 187
Registrován: 20. září 2021, 13:47
Bydliště: Třebechovice p. O.
Dal poděkování: 23 poděkování
Dostal poděkování: 22 poděkování

Re: Rain drop detector

Příspěvek od mamonick »

tiimsvk píše: 27. červenec 2022, 11:32 ...
Inak termal shield mam vyrobený zo zavitových tyči a podnosov pod kvetináče :D. Nemám zatial k dispozící 3D tlačiareň možno na vianoce :)
...
Tak já budu mít zítra vše vytištěno, tak jestli chceš, dám to tisknout znovu. Ty jsi poskytl kód (a doufám, že ještě i další rady v budoucnu), já Ti za to nabízím ten shield s držákem na raindrop.
A na zásilkovně se pak nějak domluvíme ;)

Uživatelský avatar
tiimsvk
Dárce - Donátor
Dárce - Donátor
Příspěvky: 800
Registrován: 06. květen 2021, 07:03
Dal poděkování: 72 poděkování
Dostal poděkování: 65 poděkování

Re: Rain drop detector

Příspěvek od tiimsvk »

Ahoj jasne mam zaujem daj mi potom vedet v sukromnej sprave a sa dohodneme :)

mamonick
Dárce - Donátor
Dárce - Donátor
Příspěvky: 187
Registrován: 20. září 2021, 13:47
Bydliště: Třebechovice p. O.
Dal poděkování: 23 poděkování
Dostal poděkování: 22 poděkování

Re: Rain drop detector

Příspěvek od mamonick »

tiimsvk píše: 14. srpen 2022, 11:05 Ahoj jasne mam zaujem daj mi potom vedet v sukromnej sprave a sa dohodneme :)
Poslal jsem Ti zprávu... už se to tiskne ;)

Odpovědět

Zpět na „ESPHome“