Created
January 14, 2024 10:36
-
-
Save letsautomatenet/8e9f63a3ec33bf30b1e26618042200b4 to your computer and use it in GitHub Desktop.
ESPHome Advanced Guide - test-sensor-esp8266
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example from YouTube video: https://www.youtube.com/watch?v=XIY1xOzM3fs | |
# Push Button, Status LEDs, Analog Input (FSR Sensor), Air Quality Sensor, Distance Sensor | |
### START - Update this section with relevant details ### | |
substitutions: | |
device_name: "device-name-here" | |
friendly_name: Device Name Here | |
board_type: d1_mini | |
# ESPHome API used by Home Assistant, etc | |
# If you go to this page it generates one for you automatically! | |
# https://esphome.io/components/api.html#configuration-variables | |
api_key: "Generate a key and put it here" | |
ap_password: "randomsecurepassword" # Fallback WiFi Access Point password | |
ota_password: "differentrandomsecurepassword" # Password used to remotely flash firmware | |
### END ### | |
esphome: | |
name: ${device_name} | |
friendly_name: ${friendly_name} | |
esp8266: | |
board: ${board_type} | |
# Enable logging | |
logger: | |
# Enable Home Assistant API | |
api: | |
encryption: | |
key: ${api_key} | |
ota: | |
password: ${ota_password} | |
wifi: | |
ssid: !secret wifi_ssid | |
password: !secret wifi_password | |
# Enable fallback hotspot (captive portal) in case wifi connection fails | |
ap: | |
ssid: ${device_name} | |
password: ${ap_password} | |
captive_portal: | |
# Restart & Safe Mode Buttons | |
button: | |
- platform: restart | |
name: "Restart Device" | |
- platform: safe_mode | |
name: "Restart in Safe Mode" | |
# I2C Bus for air quality and distance sensors | |
i2c: | |
scl: D1 | |
sda: D2 | |
scan: true | |
id: bus_a | |
# LED Outputs | |
output: | |
- platform: gpio | |
id: green_led | |
pin: D5 | |
- platform: gpio | |
id: red_led | |
pin: D6 | |
- platform: gpio | |
id: blue_led | |
pin: D7 | |
# Light switches to control LEDs | |
light: | |
- platform: binary | |
name: "Green LED" | |
output: green_led | |
id: green_led_light | |
- platform: binary | |
name: "Red LED" | |
output: red_led | |
id: red_led_light | |
- platform: binary | |
name: "Blue LED" | |
output: blue_led | |
id: blue_led_light | |
# Button to control blue LED | |
binary_sensor: | |
- platform: gpio | |
pin: | |
number: RX | |
inverted: true | |
mode: | |
input: true | |
pullup: true | |
id: pushbutton | |
name: Doorbell | |
filters: | |
- delayed_off: 10ms | |
on_press: | |
then: | |
- output.turn_on: blue_led | |
on_release: | |
then: | |
- output.turn_off: blue_led | |
sensor: | |
# FSR Pressure Sensor | |
- platform: adc | |
pin: A0 | |
id: bedsensor1 | |
name: "Bed Sensor" | |
update_interval: 1s | |
internal: false # Set to true to not send to HA | |
# Turn different LEDs on dependent on pressure applied | |
on_value_range: | |
- below: 0.6 | |
then: | |
- light.turn_off: red_led_light | |
- light.turn_on: green_led_light | |
- below: 0.1 | |
then: | |
- light.turn_off: red_led_light | |
- light.turn_off: green_led_light | |
- light.turn_on: blue_led_light | |
- above: 0.1 | |
then: | |
- light.turn_off: blue_led_light | |
- above: 0.3 | |
then: | |
- light.turn_on: green_led_light | |
- above: 0.6 | |
then: | |
- light.turn_on: red_led_light | |
- light.turn_off: green_led_light | |
# Pressure Sensor. 5 second updates | |
- platform: template | |
name: "Bed Sensor 5s" | |
id: bedsensor2 | |
accuracy_decimals: 2 | |
update_interval: 5s | |
lambda: |- | |
return id(bedsensor1).state; | |
unit_of_measurement: "v" | |
# Air Quality Sensor. BME680 | |
- platform: bme680 | |
temperature: | |
name: "BME680 Temperature" | |
oversampling: 16x | |
pressure: | |
name: "BME680 Pressure" | |
humidity: | |
id: "humidity" | |
name: "BME680 Humidity" | |
gas_resistance: | |
id: "gas_resistance" | |
name: "BME680 Gas Resistance" | |
address: 0x77 | |
update_interval: 60s | |
- platform: template | |
name: "BME680 Indoor Air Quality" | |
id: iaq | |
icon: "mdi:gauge" | |
# caulculation: comp_gas = log(R_gas[ohm]) + 0.04 log(Ohm)/%rh * hum[%rh] | |
lambda: |- | |
return log(id(gas_resistance).state) + 0.04 * id(humidity).state; | |
# Distance Sensor | |
- platform: vl53l0x | |
name: "Lounge Door Presence Distance 1" | |
id: loungedoord1 | |
i2c_id: bus_a | |
address: 0x29 | |
# enable_pin: GPIO14 | |
timeout: 200us | |
update_interval: 500ms | |
unit_of_measurement: "m" | |
long_range: false | |
internal: false | |
# filters: | |
# - clamp: | |
# min_value: 10 | |
# max_value: 75 | |
# ignore_out_of_range: true | |
text_sensor: | |
# Simplified air quality reading | |
- platform: template | |
name: "BME680 IAQ Classification" | |
icon: "mdi:checkbox-marked-circle-outline" | |
lambda: |- | |
if (int(id(iaq).state) <= 50) { | |
return {"Excellent"}; | |
} | |
else if (int(id(iaq).state) <= 100) { | |
return {"Good"}; | |
} | |
else if (int(id(iaq).state) <= 150) { | |
return {"Lightly polluted"}; | |
} | |
else if (int(id(iaq).state) <= 200) { | |
return {"Moderately polluted"}; | |
} | |
else if (int(id(iaq).state) <= 250) { | |
return {"Heavily polluted"}; | |
} | |
else if (int(id(iaq).state) <= 350) { | |
return {"Severely polluted"}; | |
} | |
else if (int(id(iaq).state) <= 500) { | |
return {"Extremely polluted"}; | |
} | |
else { | |
return {"unknown"}; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment