Skip to content

Commit

Permalink
Reusable ESPHomeLabs
Browse files Browse the repository at this point in the history
  • Loading branch information
stefancrain committed Jul 22, 2022
0 parents commit 3ef4903
Show file tree
Hide file tree
Showing 29 changed files with 470 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/secrets.yaml

# Folder view configuration files
.DS_Store
Desktop.ini
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Stefan's ESPHomeLab

Currently a WIP, Reuseable config across my ESPHome devices

## Deploying

```shell
cd [projectdir]
esphome --substitution release_id "$(md5sum main.yaml | awk '{print $1}' | cut -b-8 )" run main.yaml --device /dev/xxxx
```
3 changes: 3 additions & 0 deletions common/binary_sensor/as3935.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- platform: as3935
name: "${node_name} Storm Alert"
3 changes: 3 additions & 0 deletions common/binary_sensor/connectivity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- platform: status
name: "${node_name} Connectivity"
3 changes: 3 additions & 0 deletions common/binary_sensor/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Trick to include secrets in imports
<<: !include ../../secrets.yaml
31 changes: 31 additions & 0 deletions common/device_base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
esphome:
name: ${node_name}
name_add_mac_suffix: true
project:
name: "stefancrain.${node_name}"
version: ${release_id}
board: ${board}
platform: ${platform}

# Enable logging
logger:
level: ${log_level}
logs:
switch: INFO
light: WARN

ota:
password: !secret ota_password

api:
password: !secret api_password

light:
- platform: status_led
name: "${node_name} Status LED"
pin: "${pin_led_status}"
restore_mode: ALWAYS_OFF

web_server:
port: 80
13 changes: 13 additions & 0 deletions common/network.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
wifi:
power_save_mode: none
output_power: 17.5db
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${node_name} Fallback Hotspot"
password: !secret fallback_hotspot_password

captive_portal:
40 changes: 40 additions & 0 deletions common/script/aqi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
- id: aqi
mode: restart
then:
# Bad if at least one of the sensor values is bad
- if:
condition:
or:
- sensor.in_range:
id: pm2_5_avg_24h
above: 25
- sensor.in_range:
id: pm10_avg_24h
above: 50
then:
- text_sensor.template.publish:
id: aqi
state: Bad
# else:
# # Acceptable if at least one of the sensor values is acceptable
# - if:
# condition:
# or:
# - sensor.in_range:
# id: pm2_5_avg_24h
# above: 12
# - sensor.in_range:
# id: pm10_avg_24h
# above: 25
# then:
# - text_sensor.template.publish:
# id: aqi
# state: Acceptable
# else:
# # Otherwise good (all of the sensor values are good)
# - text_sensor.template.publish:
# id: aqi
# state: Good



3 changes: 3 additions & 0 deletions common/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Trick to include secrets in imports
<<: !include ../secrets.yaml
30 changes: 30 additions & 0 deletions common/sensor/PMS5003.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- platform: pmsx003
type: PMSX003

pm_1_0:
name: "${node_name} Particulate Matter <1.0µm Concentration"
id: pm1
icon: mdi:chemical-weapon
filters:
- sliding_window_moving_average:
window_size: 30
send_every: 30

pm_2_5:
name: "${node_name} Particulate Matter <2.5µm Concentration"
id: pm2_5
icon: mdi:chemical-weapon
filters:
- sliding_window_moving_average:
window_size: 30
send_every: 30

pm_10_0:
name: "${node_name} Particulate Matter <10.0µm Concentration"
id: pm10
icon: mdi:chemical-weapon
filters:
- sliding_window_moving_average:
window_size: 30
send_every: 30
93 changes: 93 additions & 0 deletions common/sensor/aqi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---

# https://aqs.epa.gov/aqsweb/documents/codetables/aqi_breakpoints.html
- platform: template
name: "${node_name} US Air Quality Index"
id: us_aqi
value_template: >
{% set vv = states('sensor.pm2_5_avg_24h')|float %}
{% if vv > 0 and vv <= 12 %}
GOOD
{% elif vv > 12 and vv <= 35.5 %}
MODERATE
{% elif vv > 35.5 and vv <= 55.5 %}
UNHEALTHY FOR SENSITIVE
{% elif vv > 55.5 and vv <= 150.5 %}
UNHEALTHY
{% elif vv > 150.5 and vv <= 250.5 %}
VERY UNHEALTHY
{% elif vv > 250.5 %}
HAZARDOUS
{% else %}
UNKNOWN
{% endif %}
- platform: template
name: "${node_name} China Air Quality Index"
id: china_aqi
value_template: >
{% set vv = states('sensor.pm2_5_avg_24h')|float %}
{% if vv > 0 and vv <= 35 %}
GOOD
{% elif vv > 35 and vv <= 75 %}
MODERATE
{% elif vv > 75 and vv <= 115 %}
UNHEALTHY FOR SENSITIVE
{% elif vv > 115 and vv <= 150 %}
UNHEALTHY
{% elif vv > 150 and vv <= 250 %}
VERY UNHEALTHY
{% elif vv > 250 %}
HAZARDOUS
{% else %}
UNKNOWN
{% endif %}
# # The WHO guidelines work with 24-hour averages of the PM2.5 and PM10 sensors
- platform: template
name: "${node_name} Particulate Matter <1µm 24h average"
id: pm1_avg_24h
icon: mdi:chemical-weapon
unit_of_measurement: µg/m³
lambda: |-
return id(pm1).state;
update_interval: 60s
filters:
- sliding_window_moving_average:
window_size: 1440 # = 24 hours x 60 minutes
send_every: 1
on_value:
then:
- script.execute: aqi

# - platform: template
# name: "${node_name} Particulate Matter <2.5µm 24h average"
# id: pm2_5_avg_24h
# icon: mdi:chemical-weapon
# unit_of_measurement: µg/m³
# lambda: |-
# return id(pm2_5).state;
# update_interval: 60s
# filters:
# - sliding_window_moving_average:
# window_size: 1440 # = 24 hours x 60 minutes
# send_every: 1
# on_value:
# then:
# - script.execute: update_aqi

# - platform: template
# name: "${node_name} Particulate Matter <10.0µm 24h average"
# id: pm10_avg_24h
# icon: mdi:chemical-weapon
# unit_of_measurement: µg/m³
# lambda: |-
# return id(pm10).state;
# update_interval: 60s
# filters:
# - sliding_window_moving_average:
# window_size: 1440 # = 24 hours x 60 minutes
# send_every: 1
# on_value:
# then:
# - script.execute: update_aqi
6 changes: 6 additions & 0 deletions common/sensor/as3935.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- platform: as3935
lightning_energy:
name: "${node_name} Lightning Energy"
distance:
name: "${node_name} Distance Storm"
31 changes: 31 additions & 0 deletions common/sensor/bme680.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- platform: bme680_bsec
# Temperature in °C
temperature:
name: "${node_name} BME680 Temperature"
sample_rate: lp
# Pressure in hPa
pressure:
name: "${node_name} BME680 Pressure"
sample_rate: lp
# Relative humidity %
humidity:
name: "${node_name} BME680 Humidity"
sample_rate: lp
# Gas resistance in Ω
gas_resistance:
name: "${node_name} BME680 Gas Resistance"
# Indoor air quality value
iaq:
name: "${node_name} BME680 IAQ"
# IAQ accuracy as a numeric value of 0, 1, 2, 3
iaq_accuracy:
name: "${node_name} BME680 Numeric IAQ Accuracy"

# CO2 equivalent estimate in ppm
co2_equivalent:
name: "${node_name} BME680 CO2 Equivalent"
# Volatile organic compounds equivalent estimate in ppm
breath_voc_equivalent:
name: "${node_name} BME680 Breath VOC Equivalent"

3 changes: 3 additions & 0 deletions common/sensor/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Trick to include secrets in imports
<<: !include ../../secrets.yaml
23 changes: 23 additions & 0 deletions common/sensor/uptime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- platform: uptime
name: "${node_name} Uptime"
id: uptime_sensor
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
5 changes: 5 additions & 0 deletions common/sensor/wifi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# WiFi Signal sensor.
- platform: wifi_signal
name: "${node_name} WiFi Signal"
update_interval: 60s
4 changes: 4 additions & 0 deletions common/text_sensor/bme680.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- platform: bme680_bsec
iaq_accuracy:
name: "${node_name} BME680 IAQ Accuracy"
3 changes: 3 additions & 0 deletions common/text_sensor/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Trick to include secrets in imports
<<: !include ../../secrets.yaml
6 changes: 6 additions & 0 deletions common/text_sensor/uptime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# Make uptime Human Readable
- platform: template
name: "${node_name} Uptime Human Readable"
id: uptime_human
icon: mdi:clock-start
10 changes: 10 additions & 0 deletions common/text_sensor/wifi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- platform: wifi_info
ip_address:
name: "${node_name} Wifi Device IP Address"
mac_address:
name: "${node_name} Wifi Device Mac Address"
ssid:
name: "${node_name} Wifi Network name - SSID"
bssid:
name: "${node_name} Wifi Router - BSSID"
3 changes: 3 additions & 0 deletions common/time/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
# Trick to include secrets in imports
<<: !include ../../secrets.yaml
7 changes: 7 additions & 0 deletions common/time/sync-homeassistant.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# https://esphome.io/components/time.html#home-assistant-time-source
- platform: homeassistant
id: homeassistant_time
on_time_sync:
then:
- logger.log: "Synchronized system clock from Home Assistant"
7 changes: 7 additions & 0 deletions common/time/sync-sntp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# https://esphome.io/components/time.html#sntp-time-source
- platform: sntp
timezone: !secret timezone
on_time_sync:
then:
- logger.log: "Synchronized system clock from SNTP"
10 changes: 10 additions & 0 deletions font/google-roboto-mono.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- file: "gfonts://Roboto+Mono"
id: roboto_mono_regular_20
size: 20
- file: "gfonts://Roboto+Mono"
id: roboto_mono_regular_16
size: 16
- file: "gfonts://Roboto+Mono"
id: roboto_mono_regular_12
size: 12
10 changes: 10 additions & 0 deletions font/google-roboto.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- file: "gfonts://Roboto"
id: roboto_regular_20
size: 20
- file: "gfonts://Roboto"
id: roboto_regular_16
size: 16
- file: "gfonts://Roboto"
id: roboto_regular_12
size: 12
Loading

0 comments on commit 3ef4903

Please sign in to comment.