Add trial HLK sensors

This commit is contained in:
Joshua Boniface 2023-12-05 16:00:44 -05:00
parent 2803e5b554
commit 3b06e61f5d
2 changed files with 873 additions and 0 deletions

View File

@ -0,0 +1,393 @@
---
###############################################################################
# SuperSensor v1.0 ESPHome configuration
###############################################################################
#
# Copyright (C) 2023 Joshua M. Boniface <joshua@boniface.me>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
###############################################################################
substitutions:
# How long a PIR activation should be held for
pir_holdtime: "15s"
esphome:
name: supersensor
name_add_mac_suffix: true
friendly_name: "Supersensor"
project:
name: joshuaboniface.supersensor
version: "0.1"
includes:
- veml7700.h
libraries:
- "Wire"
- "Adafruit Unified Sensor"
- "SPI"
- "Adafruit BusIO"
- "Adafruit VEML7700 Library"
on_boot:
- priority: 600
then:
- light.turn_on:
id: output_led
effect: flash
red: 1
green: 1
blue: 1
dashboard_import:
package_import_url: github://joshuaboniface/supersensor/supersensor.yaml
import_full_config: false
esp32:
board: esp32dev
# framework:
# type: esp-idf
# sdkconfig_options:
# CONFIG_ESP32_DEFAULT_CPU_FREQ_240: "y"
# CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ: "240"
# CONFIG_ESP32_DATA_CACHE_64KB: "y"
# CONFIG_ESP32_DATA_CACHE_LINE_64B: "y"
# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ: "240"
# CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
# CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
script:
- id: pir_handler
then:
- lambda: |-
id(pir_motion).publish_state(true);
- while:
condition:
binary_sensor.is_on: pir_gpio
then:
- delay: ${pir_holdtime}
- lambda: |-
id(pir_motion).publish_state(false);
# Enable logging only via web
logger:
level: DEBUG
baud_rate: 0
api:
encryption:
key: !secret api_encryption_key
on_client_disconnected:
- light.turn_on:
id: output_led
effect: flash
red: 1
green: 1
blue: 1
- switch.turn_off: use_wake_word
on_client_connected:
- switch.turn_on: use_wake_word
- delay: 2s
- switch.turn_off: use_wake_word
- delay: 2s
- switch.turn_on: use_wake_word
- delay: 2s
- light.turn_off:
id: output_led
ota:
password: !secret ota_password
safe_mode: false
web_server:
port: 80
auth:
username: !secret web_auth_username
password: !secret web_auth_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: !secret wifi_domain
power_save_mode: LIGHT
reboot_timeout: 5min
uart:
id: LD1115H_UART_BUS
rx_pin: GPIO3
tx_pin: GPIO1
baud_rate: 115200
setup_priority: 200
i2c:
sda: GPIO21
scl: GPIO22
scan: true
i2s_audio:
i2s_lrclk_pin: GPIO25
i2s_bclk_pin: GPIO26
microphone:
- platform: i2s_audio
id: mic
adc_type: external
i2s_din_pin: GPIO27
pdm: false
voice_assistant:
microphone: mic
use_wake_word: false
noise_suppression_level: 2
auto_gain: 31dBFS
volume_multiplier: 4.0
id: assist
on_error:
- light.turn_off:
id: output_led
transition_length: 1s
- logger.log: "Voice Assistant encountered an error; restarting it"
- switch.turn_off: use_wake_word
- delay: 1s
- switch.turn_on: use_wake_word
on_wake_word_detected:
- light.turn_off:
id: output_led
- light.turn_on:
id: output_led
red: 0
green: 0
blue: 1
on_listening:
- light.turn_on:
id: output_led
red: 0
green: 0
blue: 1
on_stt_end:
- light.turn_off:
id: output_led
transition_length: 1s
on_tts_start:
- light.turn_off:
id: output_led
transition_length: 1s
- if:
condition:
lambda: return x != "Sorry, I couldn't understand that";
then:
- logger.log: "Command successful!"
- light.turn_on:
id: output_led
effect: hold
red: 0
green: 1
blue: 0
else:
- logger.log: "Command failed!"
- light.turn_on:
id: output_led
effect: hold
red: 1
green: 0
blue: 0
light:
- platform: rgb
id: output_led
red: rgb_r
green: rgb_g
blue: rgb_b
default_transition_length: 0.15s
flash_transition_length: 0.15s
effects:
- strobe:
name: flash
colors:
- state: true
duration: 0.5s
- state: false
duration: 0.5s
- automation:
name: hold
sequence:
- delay: 5s
- light.turn_off:
id: output_led
transition_length: 1s
output:
- platform: ledc
id: rgb_r
pin: GPIO14
- platform: ledc
id: rgb_g
pin: GPIO12
- platform: ledc
id: rgb_b
pin: GPIO13
button:
- platform: restart
name: "ESP32 Restart"
icon: mdi:power-cycle
entity_category: "diagnostic"
switch:
- platform: template
name: "Enable Wake Word"
icon: mdi:account-voice
id: use_wake_word
optimistic: true
restore_mode: ALWAYS_OFF
entity_category: config
on_turn_on:
- lambda: id(assist).set_use_wake_word(true);
- if:
condition:
not:
- voice_assistant.is_running
then:
- voice_assistant.start_continuous
on_turn_off:
- voice_assistant.stop
- lambda: id(assist).set_use_wake_word(false);
binary_sensor:
- platform: gpio
name: "PIR GPIO"
id: pir_gpio
pin: GPIO33
internal: false
device_class: motion
on_press:
- script.stop: pir_handler
- script.execute: pir_handler
- platform: template
name: "PIR Motion"
id: pir_motion
device_class: motion
- platform: gpio
name: "LD1115H Presence"
id: ld11115h_gpio
pin: GPIO23
internal: false
device_class: motion
sensor:
# - platform: bme280
# temperature:
# name: "BME280 Temperature"
# pressure:
# name: "BME280 Pressure"
# humidity:
# name: "BME280 Humidity"
# update_interval: 15s
# address: 0x76
- platform: bmp280
temperature:
name: "BMP280 Temperature"
pressure:
name: "BMP280 Pressure"
update_interval: 5s
address: 0x76
- platform: custom
lambda: |-
auto veml7700 = new VEML7700CustomSensor();
App.register_component(veml7700);
return {veml7700->lux_sensor};
sensors:
- name: "VEML7700 Illumination"
unit_of_measurement: Lux
accuracy_decimals: 0
- platform: uptime
name: "ESP32 Uptime"
icon: mdi:clock-alert
update_interval: 5s
entity_category: "diagnostic"
- platform: wifi_signal
name: "ESP32 WiFi RSSI"
icon: mdi:wifi-strength-2
update_interval: 5s
entity_category: "diagnostic"
- platform: internal_temperature
name: "ESP32 Temperature"
icon: mdi:thermometer
unit_of_measurement: °C
device_class: TEMPERATURE
update_interval: 5s
entity_category: "diagnostic"
- platform: template
name: "ESP32 CPU Frequency"
icon: mdi:cpu-32-bit
accuracy_decimals: 1
unit_of_measurement: MHz
update_interval: 5s
lambda: |-
return ets_get_cpu_frequency();
entity_category: "diagnostic"
- platform: template
name: "ESP32 Free Memory"
icon: mdi:memory
unit_of_measurement: 'kB'
state_class: measurement
update_interval: 5s
lambda: |-
return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
entity_category: "diagnostic"
number:
- platform: template
name: LD1115H TH1 #TH1 is Movement/Motion Sensitivity
id: LD1115H_TH1
icon: "mdi:cogs"
optimistic: true
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "120" #Default TH1 Setting
min_value: 20
max_value: 1200
step: 10
set_action:
then:
- uart.write:
id: LD1115H_UART_BUS
data: !lambda |-
std::string th1st = "th1=" + str_sprintf("%.0f",x) +" \n";
return std::vector<uint8_t>(th1st.begin(), th1st.end());
- platform: template
name: LD1115H TH2 #TH2 is Occupancy/Presence Sensitivity
id: LD1115H_TH2
icon: "mdi:cogs"
optimistic: true
restore_value: true #If you don't want to store the setting at ESP, set it to false.
initial_value: "250" #Default TH2 Setting
min_value: 50
max_value: 2500
step: 10
set_action:
then:
- uart.write:
id: LD1115H_UART_BUS
data: !lambda |-
std::string th2st = "th2=" + str_sprintf("%.0f",x) +" \n";
return std::vector<uint8_t>(th2st.begin(), th2st.end());

View File

@ -0,0 +1,480 @@
---
###############################################################################
# SuperSensor v1.0 ESPHome configuration
###############################################################################
#
# Copyright (C) 2023 Joshua M. Boniface <joshua@boniface.me>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
###############################################################################
substitutions:
# How long a PIR activation should be held for
pir_holdtime: "15s"
esphome:
name: supersensor
name_add_mac_suffix: true
friendly_name: "Supersensor"
project:
name: joshuaboniface.supersensor
version: "0.1"
# includes:
# - veml7700.h
# libraries:
# - "Wire"
# - "Adafruit Unified Sensor"
# - "SPI"
# - "Adafruit BusIO"
# - "Adafruit VEML7700 Library"
on_boot:
- priority: 600
then:
- light.turn_on:
id: output_led
effect: flash
red: 1
green: 1
blue: 1
dashboard_import:
package_import_url: github://joshuaboniface/supersensor/supersensor.yaml
import_full_config: false
esp32:
board: esp32dev
# framework:
# type: esp-idf
# sdkconfig_options:
# CONFIG_ESP32_DEFAULT_CPU_FREQ_240: "y"
# CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ: "240"
# CONFIG_ESP32_DATA_CACHE_64KB: "y"
# CONFIG_ESP32_DATA_CACHE_LINE_64B: "y"
# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
# CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ: "240"
# CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
# CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"
script:
- id: pir_handler
then:
- lambda: |-
id(pir_motion).publish_state(true);
- while:
condition:
binary_sensor.is_on: pir_gpio
then:
- delay: ${pir_holdtime}
- lambda: |-
id(pir_motion).publish_state(false);
# Enable logging only via web
logger:
level: DEBUG
baud_rate: 115200
api:
encryption:
key: !secret api_encryption_key
on_client_disconnected:
- light.turn_on:
id: output_led
effect: flash
red: 1
green: 1
blue: 1
- switch.turn_off: use_wake_word
on_client_connected:
- switch.turn_on: use_wake_word
- delay: 2s
- switch.turn_off: use_wake_word
- delay: 2s
- switch.turn_on: use_wake_word
- delay: 2s
- light.turn_off:
id: output_led
ota:
password: !secret ota_password
safe_mode: false
web_server:
port: 80
auth:
username: !secret web_auth_username
password: !secret web_auth_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: !secret wifi_domain
power_save_mode: LIGHT
reboot_timeout: 5min
uart:
id: ld2410_uart
rx_pin: GPIO18
tx_pin: GPIO19
baud_rate: 256000
data_bits: 8
stop_bits: 1
parity: NONE
i2c:
sda: GPIO16
scl: GPIO17
scan: true
i2s_audio:
i2s_lrclk_pin: GPIO27
i2s_bclk_pin: GPIO26
microphone:
- platform: i2s_audio
id: mic
adc_type: external
i2s_din_pin: GPIO14
pdm: false
voice_assistant:
microphone: mic
use_wake_word: false
noise_suppression_level: 2
auto_gain: 31dBFS
volume_multiplier: 4.0
id: assist
on_error:
- light.turn_off:
id: output_led
transition_length: 1s
- logger.log: "Voice Assistant encountered an error; restarting it"
- switch.turn_off: use_wake_word
- delay: 1s
- switch.turn_on: use_wake_word
on_wake_word_detected:
- light.turn_off:
id: output_led
- light.turn_on:
id: output_led
red: 0
green: 0
blue: 1
on_listening:
- light.turn_on:
id: output_led
red: 0
green: 0
blue: 1
on_stt_end:
- light.turn_off:
id: output_led
transition_length: 1s
on_tts_start:
- light.turn_off:
id: output_led
transition_length: 1s
- if:
condition:
lambda: return x != "Sorry, I couldn't understand that";
then:
- logger.log: "Command successful!"
- light.turn_on:
id: output_led
effect: hold
red: 0
green: 1
blue: 0
else:
- logger.log: "Command failed!"
- light.turn_on:
id: output_led
effect: hold
red: 1
green: 0
blue: 0
light:
- platform: rgb
id: output_led
red: rgb_r
green: rgb_g
blue: rgb_b
default_transition_length: 0.15s
flash_transition_length: 0.15s
effects:
- strobe:
name: flash
colors:
- state: true
duration: 0.5s
- state: false
duration: 0.5s
- automation:
name: hold
sequence:
- delay: 5s
- light.turn_off:
id: output_led
transition_length: 1s
output:
- platform: ledc
id: rgb_r
pin: GPIO32
- platform: ledc
id: rgb_g
pin: GPIO33
- platform: ledc
id: rgb_b
pin: GPIO25
ld2410:
id: ld2410_radar
uart_id: ld2410_uart
# max_move_distance : 6m
# max_still_distance: 0.75m
# g0_move_threshold: 10
# g0_still_threshold: 20
# g1_move_threshold: 10
# g1_still_threshold: 20
# g2_move_threshold: 20
# g2_still_threshold: 21
# g3_move_threshold: 30
# g3_still_threshold: 31
# g4_move_threshold: 40
# g4_still_threshold: 41
# g5_move_threshold: 50
# g5_still_threshold: 51
# g6_move_threshold: 60
# g6_still_threshold: 61
# g7_move_threshold: 70
# g7_still_threshold: 71
# g8_move_threshold: 80
# g8_still_threshold: 81
binary_sensor:
- platform: gpio
name: "PIR GPIO"
id: pir_gpio
pin: GPIO13
internal: false
device_class: motion
on_press:
- script.stop: pir_handler
- script.execute: pir_handler
- platform: template
name: "PIR Motion"
id: pir_motion
device_class: motion
- platform: ld2410
ld2410_id: ld2410_radar
has_target:
name: "LD2410C Presence"
has_moving_target:
name: "LD2410C Moving Target"
has_still_target:
name: "LD2410C Still Target"
sensor:
# - platform: bme280
# temperature:
# name: "BME280 Temperature"
# pressure:
# name: "BME280 Pressure"
# humidity:
# name: "BME280 Humidity"
# update_interval: 15s
# address: 0x76
- platform: bmp280
temperature:
name: "BMP280 Temperature"
pressure:
name: "BMP280 Pressure"
update_interval: 5s
address: 0x76
# - platform: custom
# lambda: |-
# auto veml7700 = new VEML7700CustomSensor();
# App.register_component(veml7700);
# return {veml7700->lux_sensor};
# sensors:
# - name: "VEML7700 Illumination"
# unit_of_measurement: Lux
# accuracy_decimals: 0
- platform: ld2410
ld2410_id: ld2410_radar
moving_distance:
name: "LD2410C Moving Distance"
id: moving_distance
still_distance:
name: "LD2410C Still Distance"
id: still_distance
moving_energy:
name: "LD2410C Move Energy"
still_energy:
name: "LD2410C Still Energy"
detection_distance:
name: "LD2410C Presence Distance"
- platform: uptime
name: "ESP32 Uptime"
icon: mdi:clock-alert
update_interval: 5s
entity_category: diagnostic
- platform: wifi_signal
name: "ESP32 WiFi RSSI"
icon: mdi:wifi-strength-2
update_interval: 5s
entity_category: diagnostic
- platform: internal_temperature
name: "ESP32 Temperature"
icon: mdi:thermometer
unit_of_measurement: °C
device_class: TEMPERATURE
update_interval: 5s
entity_category: diagnostic
- platform: template
name: "ESP32 CPU Frequency"
icon: mdi:cpu-32-bit
accuracy_decimals: 1
unit_of_measurement: MHz
update_interval: 5s
lambda: |-
return ets_get_cpu_frequency();
entity_category: diagnostic
- platform: template
name: "ESP32 Free Memory"
icon: mdi:memory
unit_of_measurement: 'kB'
state_class: measurement
update_interval: 5s
lambda: |-
return heap_caps_get_free_size(MALLOC_CAP_INTERNAL) / 1024;
entity_category: diagnostic
text_sensor:
- platform: ld2410
version:
name: "LD2410C Firmware Version"
mac_address:
name: "LD2410C MAC Address"
button:
- platform: ld2410
restart:
name: "LD2410C Restart"
factory_reset:
name: "LD2410C Factory Reset"
- platform: restart
name: "ESP32 Restart"
icon: mdi:power-cycle
entity_category: diagnostic
switch:
- platform: template
name: "Enable Wake Word"
icon: mdi:account-voice
id: use_wake_word
optimistic: true
restore_mode: ALWAYS_OFF
entity_category: config
on_turn_on:
- lambda: id(assist).set_use_wake_word(true);
- if:
condition:
not:
- voice_assistant.is_running
then:
- voice_assistant.start_continuous
on_turn_off:
- voice_assistant.stop
- lambda: id(assist).set_use_wake_word(false);
- platform: ld2410
engineering_mode:
name: "LD2410C Engineering Mode"
bluetooth:
name: "LD2410C Bluetooth"
number:
- platform: ld2410
timeout:
name: "LD2410C Timeout"
light_threshold:
name: "LD2410C Light Threshold"
max_move_distance_gate:
name: "LD2410C Max Move Distance Gate"
max_still_distance_gate:
name: "LD2410C Max Still Distance Gate"
g0:
move_threshold:
name: "LD2410C Gate0 Move Threshold"
still_threshold:
name: "LD2410C Gate0 Still Threshold"
g1:
move_threshold:
name: "LD2410C Gate1 Move Threshold"
still_threshold:
name: "LD2410C Gate1 Still Threshold"
g2:
move_threshold:
name: "LD2410C Gate2 Move Threshold"
still_threshold:
name: "LD2410C Gate2 Still Threshold"
g3:
move_threshold:
name: "LD2410C Gate3 Move Threshold"
still_threshold:
name: "LD2410C Gate3 Still Threshold"
g4:
move_threshold:
name: "LD2410C Gate4 Move Threshold"
still_threshold:
name: "LD2410C Gate4 Still Threshold"
g5:
move_threshold:
name: "LD2410C Gate5 Move Threshold"
still_threshold:
name: "LD2410C Gate5 Still Threshold"
g6:
move_threshold:
name: "LD2410C Gate6 Move Threshold"
still_threshold:
name: "LD2410C Gate6 Still Threshold"
g7:
move_threshold:
name: "LD2410C Gate7 Move Threshold"
still_threshold:
name: "LD2410C Gate7 Still Threshold"
g8:
move_threshold:
name: "LD2410C Gate8 Move Threshold"
still_threshold:
name: "LD2410C Gate8 Still Threshold"
select:
- platform: ld2410
distance_resolution:
name: "LD2410C Distance Resolution"