Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Presence Sensor DIY1
- substitutions:
- name: presence-mbrtoilet
- friendly_name: Presence MBR Toilet
- esphome:
- name: ${name}
- friendly_name: ${friendly_name}
- comment: DIY LD2410 Presence Sensor with ESPHome at MBR Toilet
- on_boot:
- - priority: 900.0
- then:
- - lambda: |-
- id(cpu_speed) = ESP.getCpuFreqMHz();
- esp32:
- board: esp32dev
- framework:
- type: arduino
- # Enable logging
- logger:
- # Enable Home Assistant API
- api:
- encryption:
- key: !secret psd1_encryption_key
- ota:
- - platform: esphome
- password: !secret psd1_ota_pwd
- #captive_portal:
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- manual_ip:
- static_ip: 192.168.2.25
- gateway: 192.168.2.1
- subnet: 255.255.255.0
- #output_power: 20
- # Enable fallback hotspot (captive portal) in case wifi connection fails
- ap:
- ssid: "${friendly_name} ESP"
- password: !secret psd1_ap_pwd
- power_save_mode: none
- #power_save_mode: light # none which does not work with bluetooth tracking
- #Open web port for browser access
- web_server:
- port: 80
- uart:
- tx_pin: GPIO16
- rx_pin: GPIO17
- baud_rate: 256000
- parity: NONE
- stop_bits: 1
- globals:
- - id: cpu_speed
- type: int
- restore_value: no
- initial_value: "0"
- ld2410:
- id: ld2410_radar
- #Configuration entities
- number:
- - platform: ld2410
- timeout:
- name: Radar Timeout
- max_move_distance_gate:
- name: Radar Max Move Distance
- max_still_distance_gate:
- name: Radar Max Still Distance
- g0:
- move_threshold:
- name: g0 move threshold
- still_threshold:
- name: g0 still threshold
- g1:
- move_threshold:
- name: g1 move threshold
- still_threshold:
- name: g1 still threshold
- g2:
- move_threshold:
- name: g2 move threshold
- still_threshold:
- name: g2 still threshold
- g3:
- move_threshold:
- name: g3 move threshold
- still_threshold:
- name: g3 still threshold
- g4:
- move_threshold:
- name: g4 move threshold
- still_threshold:
- name: g4 still threshold
- g5:
- move_threshold:
- name: g5 move threshold
- still_threshold:
- name: g5 still threshold
- g6:
- move_threshold:
- name: g6 move threshold
- still_threshold:
- name: g6 still threshold
- g7:
- move_threshold:
- name: g7 move threshold
- still_threshold:
- name: g7 still threshold
- g8:
- move_threshold:
- name: g8 move threshold
- still_threshold:
- name: g8 still threshold
- # Setting ending of zone 1 occupancy
- - platform: template
- name: "Radar End Zone 1"
- id: radar_z1_end
- device_class: distance
- min_value: 0
- max_value: 600
- step: 1
- mode: box
- update_interval: never
- optimistic: true
- restore_value: true
- initial_value: 10
- icon: "mdi:arrow-collapse-right"
- entity_category: CONFIG
- # Setting ending of zone 2 occupancy
- - platform: template
- name: "Radar End Zone 2"
- id: radar_z2_end
- device_class: distance
- min_value: 0
- max_value: 600
- step: 1
- mode: box
- update_interval: never
- optimistic: true
- restore_value: true
- initial_value: 36
- icon: "mdi:arrow-collapse-right"
- entity_category: CONFIG
- # Setting ending of zone 3 occupancy
- - platform: template
- name: "Radar End Zone 3"
- id: radar_z3_end
- device_class: distance
- min_value: 0
- max_value: 600
- step: 1
- mode: box
- update_interval: never
- optimistic: true
- restore_value: true
- initial_value: 100
- icon: "mdi:arrow-collapse-right"
- entity_category: CONFIG
- # START Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
- i2c:
- sda: 21
- scl: 22
- scan: False
- # END Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
- #Occupancy sensor
- binary_sensor:
- # START Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
- - platform: status
- name: "${name} Lux Status"
- # END Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
- - platform: ld2410
- has_target:
- name: Radar Target
- id: radar_has_target
- has_moving_target:
- name: Radar Moving Target
- has_still_target:
- name: Radar Still Target
- ## Set Up Radar Zones Based On Distance
- - platform: template
- name: "Radar Zone 1 Occupancy"
- device_class: occupancy
- icon: mdi:motion-sensor
- lambda: |-
- if ((id(radar_has_target).state) && (id(radar_detection_distance).state < id(radar_z1_end).state)) {
- return true;
- } else {
- return false;
- }
- - platform: template
- name: "Radar Zone 2 Occupancy"
- device_class: occupancy
- icon: mdi:motion-sensor
- lambda: |-
- if ((id(radar_has_target).state) && ((id(radar_z1_end).state < id(radar_detection_distance).state) && (id(radar_detection_distance).state < id(radar_z2_end).state))) {
- return true;
- } else {
- return false;
- }
- - platform: template
- name: "Radar Zone 3 Occupancy"
- device_class: occupancy
- icon: mdi:motion-sensor
- lambda: |-
- if ((id(radar_has_target).state) && ((id(radar_z2_end).state < id(radar_detection_distance).state) && (id(radar_detection_distance).state < id(radar_z3_end).state))) {
- return true;
- } else {
- return false;
- }
- #Exposes configuration and status sensors
- sensor:
- #Device UPTIME
- - platform: uptime
- name: Uptime
- id: sys_uptime
- update_interval: 60s
- #Device CPU Speed
- - platform: template
- name: "ESP Cpu Speed"
- accuracy_decimals: 0
- unit_of_measurement: Mhz
- lambda: |-
- return (id(cpu_speed));
- entity_category: "diagnostic"
- #Device Memory
- - platform: template
- id: esp_memory
- icon: mdi:memory
- name: ESP Free Memory
- lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
- unit_of_measurement: "kB"
- state_class: measurement
- entity_category: "diagnostic"
- #Device Temperature
- - platform: template
- id: sys_esp_temperature
- name: ESP Temperature
- lambda: return temperatureRead();
- unit_of_measurement: °C
- device_class: TEMPERATURE
- update_interval: 60s
- #Device RSSI
- - platform: wifi_signal
- name: RSSI
- id: wifi_signal_db
- update_interval: 60s
- entity_category: "diagnostic"
- - platform: ld2410
- moving_distance:
- name: Radar Moving Distance
- id: moving_distance
- still_distance:
- name: Radar Still Distance
- id: still_distance
- moving_energy:
- name: Radar Move Energy
- still_energy:
- name: Radar Still Energy
- detection_distance:
- name: Radar Detection Distance
- id: radar_detection_distance
- g0:
- move_energy:
- name: g0 move energy
- still_energy:
- name: g0 still energy
- g1:
- move_energy:
- name: g1 move energy
- still_energy:
- name: g1 still energy
- g2:
- move_energy:
- name: g2 move energy
- still_energy:
- name: g2 still energy
- g3:
- move_energy:
- name: g3 move energy
- still_energy:
- name: g3 still energy
- g4:
- move_energy:
- name: g4 move energy
- still_energy:
- name: g4 still energy
- g5:
- move_energy:
- name: g5 move energy
- still_energy:
- name: g5 still energy
- g6:
- move_energy:
- name: g6 move energy
- still_energy:
- name: g6 still energy
- g7:
- move_energy:
- name: g7 move energy
- still_energy:
- name: g7 still energy
- g8:
- move_energy:
- name: g8 move energy
- still_energy:
- name: g8 still energy
- # START Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
- - platform: bh1750
- name: "${name} Lux Level"
- address: 0x23
- update_interval: 60s
- # update_interval: 1s
- # filters:
- # - sliding_window_moving_average:
- # window_size: 10
- # send_every: 10
- # send_first_at: 1
- # - or:
- # - throttle: 60s
- # - delta: 5
- # END Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
- #Exposes control buttons
- button:
- - platform: restart
- icon: mdi:power-cycle
- name: "ESP Reboot"
- - platform: factory_reset
- disabled_by_default: True
- name: "Factory Reset ESP"
- id: factory_reset_all
- - platform: ld2410
- factory_reset:
- name: "Factory Reset Radar"
- restart:
- name: "Restart Radar"
- query_params:
- name: query params
- #Exposes control switches
- switch:
- - platform: ld2410
- bluetooth:
- name: "Radar Control Bluetooth"
- id: radar_bluetooth
- engineering_mode:
- name: "Radar Engineering Mode"
- time:
- - platform: sntp
- id: time_sntp
- #Radar firmware version
- text_sensor:
- # Expose ESPHome version as sensor.
- - platform: version
- name: ESPHome Version
- # Expose WiFi information as sensors.
- - platform: wifi_info
- ip_address:
- name: IP
- ssid:
- name: SSID
- bssid:
- name: MAC
- - platform: ld2410
- version:
- name: "Radar Firmware Version"
- #Set distance resolution - 0.75m or 0.2m
- select:
- - platform: ld2410
- distance_resolution:
- name: "Radar Distance Resolution"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement