Advertisement
Guest User

Untitled

a guest
Aug 25th, 2024
143
0
71 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 9.40 KB | None | 0 0
  1. # Presence Sensor DIY1
  2. substitutions:
  3.   name: presence-mbrtoilet
  4.   friendly_name: Presence MBR Toilet
  5.  
  6. esphome:
  7.   name: ${name}
  8.   friendly_name: ${friendly_name}
  9.   comment: DIY LD2410 Presence Sensor with ESPHome at MBR Toilet
  10.   on_boot:
  11.   - priority: 900.0
  12.     then:
  13.       - lambda: |-
  14.           id(cpu_speed) = ESP.getCpuFreqMHz();
  15.  
  16. esp32:
  17.   board: esp32dev
  18.   framework:
  19.     type: arduino
  20.  
  21. # Enable logging
  22. logger:
  23. # Enable Home Assistant API
  24. api:
  25.   encryption:
  26.     key: !secret psd1_encryption_key
  27.  
  28. ota:
  29.   - platform: esphome
  30.     password: !secret psd1_ota_pwd
  31.  
  32. #captive_portal:
  33.  
  34. wifi:
  35.   ssid: !secret wifi_ssid
  36.   password: !secret wifi_password
  37.   manual_ip:
  38.     static_ip: 192.168.2.25
  39.     gateway: 192.168.2.1
  40.     subnet: 255.255.255.0
  41.   #output_power: 20
  42.  
  43.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  44.   ap:
  45.     ssid: "${friendly_name} ESP"
  46.     password: !secret psd1_ap_pwd
  47.  
  48.   power_save_mode: none
  49.   #power_save_mode: light # none which does not work with bluetooth tracking
  50.  
  51.  #Open web port for browser access
  52. web_server:
  53.   port: 80
  54.  
  55. uart:
  56.   tx_pin: GPIO16
  57.   rx_pin: GPIO17
  58.   baud_rate: 256000
  59.   parity: NONE
  60.   stop_bits: 1
  61.  
  62. globals:
  63.   - id: cpu_speed
  64.     type: int
  65.     restore_value: no
  66.     initial_value: "0"
  67. ld2410:
  68.   id: ld2410_radar
  69.  
  70. #Configuration entities
  71. number:
  72.   - platform: ld2410
  73.     timeout:
  74.       name: Radar Timeout
  75.     max_move_distance_gate:
  76.       name: Radar Max Move Distance
  77.     max_still_distance_gate:
  78.       name: Radar Max Still Distance
  79.     g0:
  80.       move_threshold:
  81.         name: g0 move threshold
  82.       still_threshold:
  83.         name: g0 still threshold
  84.     g1:
  85.       move_threshold:
  86.         name: g1 move threshold
  87.       still_threshold:
  88.         name: g1 still threshold
  89.     g2:
  90.       move_threshold:
  91.         name: g2 move threshold
  92.       still_threshold:
  93.         name: g2 still threshold
  94.     g3:
  95.       move_threshold:
  96.         name: g3 move threshold
  97.       still_threshold:
  98.         name: g3 still threshold
  99.     g4:
  100.       move_threshold:
  101.         name: g4 move threshold
  102.       still_threshold:
  103.         name: g4 still threshold
  104.     g5:
  105.       move_threshold:
  106.         name: g5 move threshold
  107.       still_threshold:
  108.         name: g5 still threshold
  109.     g6:
  110.       move_threshold:
  111.         name: g6 move threshold
  112.       still_threshold:
  113.         name: g6 still threshold
  114.     g7:
  115.       move_threshold:
  116.         name: g7 move threshold
  117.       still_threshold:
  118.         name: g7 still threshold
  119.     g8:
  120.       move_threshold:
  121.         name: g8 move threshold
  122.       still_threshold:
  123.         name: g8 still threshold
  124.   # Setting ending of zone 1 occupancy
  125.   - platform: template
  126.     name: "Radar End Zone 1"
  127.     id: radar_z1_end
  128.     device_class: distance
  129.     min_value: 0
  130.     max_value: 600
  131.     step: 1
  132.     mode: box
  133.     update_interval: never
  134.     optimistic: true
  135.     restore_value: true
  136.     initial_value: 10
  137.     icon: "mdi:arrow-collapse-right"
  138.     entity_category: CONFIG
  139.  
  140.   # Setting ending of zone 2 occupancy
  141.   - platform: template
  142.     name: "Radar End Zone 2"
  143.     id: radar_z2_end
  144.     device_class: distance
  145.     min_value: 0
  146.     max_value: 600
  147.     step: 1
  148.     mode: box
  149.     update_interval: never
  150.     optimistic: true
  151.     restore_value: true
  152.     initial_value: 36
  153.     icon: "mdi:arrow-collapse-right"
  154.     entity_category: CONFIG
  155.  
  156.   # Setting ending of zone 3 occupancy
  157.   - platform: template
  158.     name: "Radar End Zone 3"
  159.     id: radar_z3_end
  160.     device_class: distance
  161.     min_value: 0
  162.     max_value: 600
  163.     step: 1
  164.     mode: box
  165.     update_interval: never
  166.     optimistic: true
  167.     restore_value: true
  168.     initial_value: 100
  169.     icon: "mdi:arrow-collapse-right"
  170.     entity_category: CONFIG
  171.  
  172. # START Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
  173. i2c:
  174.   sda: 21
  175.   scl: 22
  176.   scan: False
  177. # END Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
  178.  
  179. #Occupancy sensor
  180. binary_sensor:
  181.  # START Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
  182.   - platform: status
  183.     name: "${name} Lux Status"
  184.   # END Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
  185.   - platform: ld2410
  186.     has_target:
  187.       name: Radar Target
  188.       id: radar_has_target
  189.     has_moving_target:
  190.       name: Radar Moving Target
  191.     has_still_target:
  192.       name: Radar Still Target
  193.   ## Set Up Radar Zones Based On Distance
  194.   - platform: template
  195.     name: "Radar Zone 1 Occupancy"
  196.     device_class: occupancy
  197.     icon: mdi:motion-sensor
  198.     lambda: |-
  199.       if ((id(radar_has_target).state) && (id(radar_detection_distance).state < id(radar_z1_end).state)) {
  200.         return true;
  201.       } else {
  202.         return false;
  203.       }
  204.   - platform: template
  205.     name: "Radar Zone 2 Occupancy"
  206.     device_class: occupancy
  207.     icon: mdi:motion-sensor
  208.     lambda: |-
  209.       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))) {
  210.         return true;
  211.       } else {
  212.         return false;
  213.       }
  214.   - platform: template
  215.     name: "Radar Zone 3 Occupancy"
  216.     device_class: occupancy
  217.     icon: mdi:motion-sensor
  218.     lambda: |-
  219.       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))) {
  220.         return true;
  221.       } else {
  222.         return false;
  223.       }
  224.  
  225. #Exposes configuration and status sensors
  226. sensor:
  227.    #Device UPTIME
  228.   - platform: uptime
  229.     name: Uptime
  230.     id: sys_uptime
  231.     update_interval: 60s
  232.     #Device CPU Speed
  233.   - platform: template
  234.     name: "ESP Cpu Speed"
  235.     accuracy_decimals: 0
  236.     unit_of_measurement: Mhz
  237.     lambda: |-
  238.       return (id(cpu_speed));
  239.     entity_category: "diagnostic"
  240.     #Device Memory
  241.   - platform: template
  242.     id: esp_memory
  243.     icon: mdi:memory
  244.     name: ESP Free Memory
  245.     lambda: return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
  246.     unit_of_measurement: "kB"
  247.     state_class: measurement
  248.     entity_category: "diagnostic"
  249.     #Device Temperature
  250.   - platform: template
  251.     id: sys_esp_temperature
  252.     name: ESP Temperature
  253.     lambda: return temperatureRead();
  254.     unit_of_measurement: °C
  255.     device_class: TEMPERATURE
  256.     update_interval: 60s
  257.     #Device RSSI
  258.   - platform: wifi_signal
  259.     name: RSSI
  260.     id: wifi_signal_db
  261.     update_interval: 60s
  262.     entity_category: "diagnostic"
  263.   - platform: ld2410
  264.     moving_distance:
  265.       name: Radar Moving Distance
  266.       id: moving_distance
  267.     still_distance:
  268.       name: Radar Still Distance
  269.       id: still_distance
  270.     moving_energy:
  271.       name: Radar Move Energy
  272.     still_energy:
  273.       name: Radar Still Energy
  274.     detection_distance:
  275.       name: Radar Detection Distance
  276.       id: radar_detection_distance
  277.     g0:
  278.       move_energy:
  279.         name: g0 move energy
  280.       still_energy:
  281.         name: g0 still energy
  282.     g1:
  283.       move_energy:
  284.         name: g1 move energy
  285.       still_energy:
  286.         name: g1 still energy
  287.     g2:
  288.       move_energy:
  289.         name: g2 move energy
  290.       still_energy:
  291.         name: g2 still energy
  292.     g3:
  293.       move_energy:
  294.         name: g3 move energy
  295.       still_energy:
  296.         name: g3 still energy
  297.     g4:
  298.       move_energy:
  299.         name: g4 move energy
  300.       still_energy:
  301.         name: g4 still energy
  302.     g5:
  303.       move_energy:
  304.         name: g5 move energy
  305.       still_energy:
  306.         name: g5 still energy
  307.     g6:
  308.       move_energy:
  309.         name: g6 move energy
  310.       still_energy:
  311.         name: g6 still energy
  312.     g7:
  313.       move_energy:
  314.         name: g7 move energy
  315.       still_energy:
  316.         name: g7 still energy
  317.     g8:
  318.       move_energy:
  319.         name: g8 move energy
  320.       still_energy:
  321.         name: g8 still energy
  322.   # START Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
  323.   - platform: bh1750
  324.     name: "${name} Lux Level"
  325.     address: 0x23
  326.     update_interval: 60s
  327. #    update_interval: 1s
  328. #    filters:
  329. #      - sliding_window_moving_average:
  330. #          window_size: 10
  331. #          send_every: 10
  332. #          send_first_at: 1
  333. #      - or:
  334. #          - throttle: 60s
  335. #          - delta: 5
  336.   # END Lux https://community.home-assistant.io/t/outdoor-lux-sensor/421926
  337.  
  338. #Exposes control buttons
  339. button:
  340.   - platform: restart
  341.     icon: mdi:power-cycle
  342.     name: "ESP Reboot"
  343.  
  344.   - platform: factory_reset
  345.     disabled_by_default: True
  346.     name: "Factory Reset ESP"
  347.     id: factory_reset_all
  348.  
  349.   - platform: ld2410
  350.     factory_reset:
  351.       name: "Factory Reset Radar"
  352.     restart:
  353.       name: "Restart Radar"
  354.     query_params:
  355.       name: query params
  356.  
  357. #Exposes control switches
  358. switch:
  359.   - platform: ld2410
  360.     bluetooth:
  361.       name: "Radar Control Bluetooth"
  362.       id: radar_bluetooth
  363.     engineering_mode:
  364.       name: "Radar Engineering Mode"
  365. time:
  366.   - platform: sntp
  367.     id: time_sntp
  368.  
  369. #Radar firmware version
  370. text_sensor:
  371.  # Expose ESPHome version as sensor.
  372.   - platform: version
  373.     name: ESPHome Version
  374.   # Expose WiFi information as sensors.
  375.   - platform: wifi_info
  376.     ip_address:
  377.       name: IP
  378.     ssid:
  379.       name: SSID
  380.     bssid:
  381.       name: MAC
  382.   - platform: ld2410
  383.     version:
  384.       name: "Radar Firmware Version"
  385. #Set distance resolution - 0.75m or 0.2m
  386. select:
  387.   - platform: ld2410
  388.     distance_resolution:
  389.       name: "Radar Distance Resolution"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement