From 8851f8da5e511a9af088ee1c5c311ca09b9f1d84 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 6 Jun 2024 11:08:40 +1200 Subject: [PATCH] various esphome yaml tidyups --- esphome/esp-attobat.yaml | 8 - esphome/esp-leafbat2.yaml | 88 +++-- esphome/esp-occupancyoffice.yaml | 74 ++-- esphome/esp-occupancystair.yaml | 72 ++-- esphome/esp-weatherstation.yaml | 638 +++++++++++++++++-------------- 5 files changed, 493 insertions(+), 387 deletions(-) diff --git a/esphome/esp-attobat.yaml b/esphome/esp-attobat.yaml index 0ae03b6..48f2353 100644 --- a/esphome/esp-attobat.yaml +++ b/esphome/esp-attobat.yaml @@ -120,14 +120,6 @@ mqtt: # payload: offline # A way to prevent deep sleep using MQTT command on_message: - - topic: viewroad-commands/attobat/deepsleepoff - payload: 'ON' - then: - - deep_sleep.prevent: deep_sleep_1 - - topic: viewroad-commands/attobat/deepsleepon - payload: 'ON' - then: - - deep_sleep.enter: deep_sleep_1 - topic: viewroad-commands/attobat/deepsleep payload: 'OFF' then: diff --git a/esphome/esp-leafbat2.yaml b/esphome/esp-leafbat2.yaml index 74e7f86..58d35ab 100644 --- a/esphome/esp-leafbat2.yaml +++ b/esphome/esp-leafbat2.yaml @@ -1,16 +1,60 @@ ############################################# -# Common -############################################# +############################################# +# Nissan Leaf 12V Battery Monitor +# Monitoring the status of a vehicle 12V battery with +# an esp8266 (D1 Mini). It will obviously only +# transmit when the vehicle is within wifi range. +# Voltage is measured with a resistor voltage divider +# into the analogue GPIO on the esp8266. +# https://zorruno.com/2022/vehicle-12v-battery-monitoring/ +############################################## +# zorruno 2022-09-31 V1 Untested +# zorruno 2024-06-02 V2 YAML Tidyups +############################################# +############################################# + +############################################# +# Variable Substitutions +# Give this a useful name & description here +# and change values accordingly +############################################# substitutions: - devicename: esp-leafbat2 - nice_devicename: "Leaf Battery Monitor 2" + devicename: "esp-leafbat2" + friendly_name: "Nissan Leaf 12V Battery Monitor" + description_comment: "Nissan Leaf 12V Battery Monitor (when home)" + + #if NOT using a secrets file, just replace these with the passwords etc in speech marks + api_key: !secret esp-leafbat_api_key #unfortunately you can't use substitutions in secrets names + ota_pass: !secret esp-leafbat_ota_pass #unfortunately you can't use substitutions in secrets names + #update_time: 30s #update time for for temp sensors etc + + wifi_ssid: !secret wifi_ssid + wifi_pass: !secret wifi_password + #Add these if we are giving it a static ip, or remove them in the Wifi section + static_ip_address: !secret esp-leafbat_static_ip + static_ip_gateway: !secret esp-leafbat_gateway + static_ip_subnet: !secret esp-leafbat_subnet + + mqtt_server: !secret mqtt_server + mqtt_username: !secret mqtt_username + mqtt_password: !secret mqtt_password + mqtt_topic: "esphome/esp-leafbat2" #main topic for the mqtt server, call it what you like + + web_server_username: !secret web_server_username + web_server_password: !secret web_server_password + + fallback_ap_ssid: "Esp-Leafbat2 Fallback Hotspot" + fallback_ap_password: !secret fallback_ap_password + + ############################################# # ESPHome ############################################# esphome: - name: $devicename + name: ${devicename} + comment: ${description_comment} #appears on the esphome page in HA ######################################## # Specific board for ESPHome device @@ -28,7 +72,7 @@ logger: ######################################## api: encryption: - key: !secret esp-leafbat2_api_key + key: ${api_key} ######################################## # Enable Over the Air Update Capability @@ -36,24 +80,24 @@ api: ######################################## ota: safe_mode: true - password: !secret esp-leafbat2_ota_pass + password: ${ota_pass} ######################################## # Use Wifi # (credentials are in secrets file) ######################################## wifi: - ssid: !secret wifi_ssid - password: !secret wifi_password + ssid: ${wifi_ssid} + password: ${wifi_password} # Details for fallback hotspot (captive portal) in case wifi connection fails ap: - ssid: "Esp-Leafbat2 Fallback Hotspot" - password: !secret fallback_ap_password + ssid: ${fallback_ap_ssid} + password: ${fallback_ap_password} # Static IP (for lower power/quicker on time) manual_ip: - static_ip: !secret esp-leafbat2_static_ip - gateway: !secret esp-leafbat2_gateway - subnet: !secret esp-leafbat2_subnet + static_ip: ${static_ip_address} + gateway: ${static_ip_gateway} + subnet: ${static_ip_subnet} ############################################# # Fallback captive portal @@ -66,17 +110,17 @@ captive_portal: web_server: port: 80 auth: - username: !secret web_server_username - password: !secret web_server_password + username: ${web_server_username} + password: ${web_server_password} ######################################## # MQTT Monitoring ######################################## mqtt: - broker: !secret mqtt_server - topic_prefix: esphome/esp-leafbat2 - username: !secret mqtt_username - password: !secret mqtt_password + broker: ${mqtt_server} + topic_prefix: ${mqtt_topic} + username: ${mqtt_username} + password: ${mqtt_password} # # Availability Topic #birth_message: @@ -87,11 +131,11 @@ mqtt: # payload: offline # A way to prevent deep sleep using MQTT command on_message: - - topic: viewroad-commands/leafbat2/deepsleepoff + - topic: viewroad-commands/leafbat2/deepsleep payload: 'ON' then: - deep_sleep.prevent: deep_sleep_1 - - topic: viewroad-commands/leafbat2/deepsleepon + - topic: viewroad-commands/leafbat2/deepsleep payload: 'ON' then: - deep_sleep.enter: deep_sleep_1 diff --git a/esphome/esp-occupancyoffice.yaml b/esphome/esp-occupancyoffice.yaml index a33a9ee..ee1c84e 100644 --- a/esphome/esp-occupancyoffice.yaml +++ b/esphome/esp-occupancyoffice.yaml @@ -2,6 +2,8 @@ ############################################# ############################################# # HiLink LD1125H mmWave sensor, with BME280 Temp/Hum/Pres Sensor on an ESP32 +# https://zorruno.com/2024/mmwave-occupancy-with-esp32-ld1125h/ +# # https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/tree/main # https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/blob/main/LD1125H/ESP32-LD1125H-Complete.yaml # @@ -16,16 +18,35 @@ ############################################# ############################################# -# Variable Substitutions +# VARIABLE SUBSTITUTIONS +# Give the device a useful name & description here +# and change values accordingly. ############################################# substitutions: devicename: "esp-occupancyoffice" friendly_name: "Office State" description_comment: "D1 Mini ESP32 with LD1125H mmWave and environment sensors for downstairs office" - api_key: !secret esp-occupancyoffice_api_key #unfortunately you can't use substitutions in secrets names - ota_pass: !secret esp-occupancyoffice_ota_pass #unfortunately you can't use substitutions in secrets names + + #if NOT using a secrets file, just replace these with the passwords etc (in quotes) + api_key: !secret esp-occupancyoffice_api_key #unfortunately you can't use substitutions inside secrets names + ota_pass: !secret esp-occupancyoffice_ota_pass #unfortunately you can't use substitutions inside secrets names + wifi_ssid: !secret wifi_ssid + wifi_password: !secret wifi_password + fallback_ap_password: !secret fallback_ap_password + #Add these if we are giving it a static ip, or remove them in the Wifi section + #static_ip_address: !secret esp-occupancyoffice_static_ip + #static_ip_gateway: !secret esp-occupancyoffice_gateway + #static_ip_subnet: !secret esp-occupancyoffice_subnet + + mqtt_server: !secret mqtt_server + mqtt_username: !secret mqtt_username + mqtt_password: !secret mqtt_password mqtt_topic: "esphome" #main topic for the mqtt server, call it what you like - update_time: 30s #update time for for temp sensors etc + + #web_server_username: !secret web_server_username + #web_server_password: !secret web_server_password + + update_time: 30s #update time for for general temp sensors etc ############################################# # ESPHome @@ -67,7 +88,7 @@ esp32: board: esp32dev framework: #type: arduino - type: esp-idf #Suggested Use ESP-IDF Framework, or Plug Out the UART Cable Might Cause ESP32 Hang. + type: esp-idf #Suggest using the ESP-IDF Framework. Changing from arduino to esp-idf needs a cabled download to change partitions version: recommended #recommended, latest or dev ############################################# @@ -83,12 +104,13 @@ i2c: ############################################# # ESPHome external or custom components to use # https://esphome.io/components/external_components.html +# https://github.com/ssieb/esphome_components/tree/master/components/serial ############################################# external_components: - source: type: git url: https://github.com/ssieb/custom_components #Thanks for @ssieb components. - components: [ serial ] #text_sensor that reads lines for a uart. Also, a sensor that reads single values from the uart. + components: [ serial ] #text_sensor that reads lines for a uart. Also, a sensor that reads single binary values from the uart. ############################################# # ESPHome Logging Enable @@ -121,16 +143,16 @@ ota: # https://esphome.io/components/wifi.html ############################################# wifi: - ssid: !secret wifi_ssid - password: !secret wifi_password + ssid: ${wifi_ssid} + password: ${wifi_password} #power_save_mode: LIGHT #https://esphome.io/components/wifi.html#wifi-power-save-mode #manual_ip: #optional static IP address - #static_ip: 192.168.x.x - #gateway: 192.168.X.x - #subnet: 255.255.255.0 + #static_ip: ${static_ip_address} + #gateway: ${static_ip_gateway} + #subnet: ${static_ip_subnet} ap: #Details for fallback hotspot (captive portal) in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode - ssid: $devicename fallback AP - password: !secret fallback_ap_password + ssid: ${devicename} fallback AP + password: ${fallback_ap_password} ap_timeout: 5min #default is 1min ############################################# @@ -140,8 +162,9 @@ wifi: ############################################# #web_server: # port: 80 -# username: !secret web_server_username #probably a good idea to secure it -# password: !secret web_server_password +# auth: +# username: ${web_server_username} #probably a good idea to secure it +# password: ${web_server_password} ############################################# # MQTT Monitoring @@ -149,10 +172,10 @@ wifi: # MUST also have api enabled if you enable MQTT ############################################# mqtt: - broker: !secret mqtt_server + broker: ${mqtt_server} topic_prefix: ${mqtt_topic}/${devicename} - username: !secret mqtt_username - password: !secret mqtt_password + username: ${mqtt_username} + password: ${mqtt_password} ############################################# # Bluetooth @@ -172,25 +195,16 @@ mqtt: ############################################# # UART Serial # hardware on EPS32, but software, and can be glitchy on ESP8266 -# https://esphome.io/components/uart.html?highlight=uart +# https://esphome.io/components/uart.html ############################################# uart: id: LD1125H_UART_BUS rx_pin: GPIO16 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang tx_pin: GPIO17 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang -# rx_pin: GPIO1 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang -# tx_pin: GPIO0 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang baud_rate: 115200 data_bits: 8 stop_bits: 1 parity: NONE -# debug: -# direction: BOTH -# dummy_receiver: false -# after: -# delimiter: "\n" -# sequence: -# - lambda: UARTDebug::log_string(direction, bytes); ############################################# # Global Variables for use in automations etc @@ -370,8 +384,8 @@ sensor: - heartbeat: 0.2s ############################################# -# Text Sensors (custom component) -# refer https://github.com/ssieb/esphome_components/tree/master/components/serial +# Text Sensors +# refer https://esphome.io/components/text_sensor/index.html ############################################# text_sensor: - platform: serial diff --git a/esphome/esp-occupancystair.yaml b/esphome/esp-occupancystair.yaml index 1b99b04..4ee793b 100644 --- a/esphome/esp-occupancystair.yaml +++ b/esphome/esp-occupancystair.yaml @@ -1,17 +1,20 @@ ############################################# ############################################# -# HiLink LD2410 mmWave sensor, with BME280 Temp/Hum/Pres Sensor on an ESP32 +# HiLink LD2410 mmWave sensor, with BME280 Temp/Hum/Pres Sensor and PIR on an ESP32 # https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/tree/main # https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/blob/main/LD1125H/ESP32-LD1125H-Complete.yaml # # https://esphome.io/components/sensor/ld2410.html # https://www.simplysmart.house/blog/presence-detection-ld2410-home-assistant # +# The B and c versions of this device can use Bluetooth, but we are not using it here. ############################################# ############################################# ############################################# -# Variable Substitutions +# VARIABLE SUBSTITUTIONS +# Give the device a useful name & description here +# and change values accordingly. ############################################# substitutions: devicename: "esp-occupancystair" @@ -19,8 +22,23 @@ substitutions: description_comment: "D1 Mini ESP32 with LD2410 mmWave for internal stairwell and environment sensors for under house" api_key: !secret esp-occupancystair_api_key #unfortunately you can't use substitutions in secrets names ota_pass: !secret esp-occupancystair_ota_pass #unfortunately you can't use substitutions in secrets names + wifi_ssid: !secret wifi_ssid + wifi_password: !secret wifi_password + fallback_ap_password: !secret fallback_ap_password + #Add these if we are giving it a static ip, or remove them in the Wifi section + #static_ip_address: !secret esp-occupancystair_static_ip + #static_ip_gateway: !secret esp-occupancystair_gateway + #static_ip_subnet: !secret esp-occupancystair_subnet + + mqtt_server: !secret mqtt_server + mqtt_username: !secret mqtt_username + mqtt_password: !secret mqtt_password mqtt_topic: "esphome" #main topic for the mqtt server, call it what you like - update_time: 30s #update time for for temp sensors etc + + #web_server_username: !secret web_server_username + #web_server_password: !secret web_server_password + + update_time: 30s #update time for for general temp sensors etc ############################################# # ESPHome @@ -33,7 +51,6 @@ esphome: #priority: -200 #then: - ############################################# # ESP Platform and Framework # https://esphome.io/components/esp32.html @@ -52,7 +69,7 @@ esp32: i2c: sda: GPIO19 scl: GPIO21 - scan: True + scan: True frequency: 100kHz #10, 50, 100, 200, 800 are possible settings, 100kHz was reliable for me ############################################# @@ -86,16 +103,16 @@ ota: # https://esphome.io/components/wifi.html ############################################# wifi: - ssid: !secret wifi_ssid - password: !secret wifi_password + ssid: ${wifi_ssid} + password: ${wifi_password} #power_save_mode: LIGHT #https://esphome.io/components/wifi.html#wifi-power-save-mode #manual_ip: #optional static IP address - #static_ip: 192.168.x.x - #gateway: 192.168.X.x - #subnet: 255.255.255.0 + #static_ip: ${static_ip_address} + #gateway: ${static_ip_gateway} + #subnet: ${static_ip_subnet} ap: #Details for fallback hotspot (captive portal) in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode - ssid: $devicename fallback AP - password: !secret fallback_ap_password + ssid: ${devicename} fallback AP + password: ${fallback_ap_password} ap_timeout: 5min #default is 1min ############################################# @@ -105,8 +122,9 @@ wifi: ############################################# web_server: port: 80 -# username: !secret web_server_username #probably a good idea to secure it -# password: !secret web_server_password +# auth: +# username: ${web_server_username} #probably a good idea to secure it +# password: ${web_server_password} ############################################# # MQTT Monitoring @@ -114,10 +132,10 @@ web_server: # MUST also have api enabled if you enable MQTT ############################################# mqtt: - broker: !secret mqtt_server + broker: ${mqtt_server} topic_prefix: ${mqtt_topic}/${devicename} - username: !secret mqtt_username - password: !secret mqtt_password + username: ${mqtt_username} + password: ${mqtt_password} ############################################# # Bluetooth @@ -142,19 +160,10 @@ uart: id: ld2410_uart rx_pin: GPIO16 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang tx_pin: GPIO17 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang -# rx_pin: GPIO1 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang -# tx_pin: GPIO0 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang baud_rate: 256000 # default for LD2410 is 25600, 8, 0, NONE data_bits: 8 stop_bits: 1 parity: NONE -# debug: -# direction: BOTH -# dummy_receiver: false -# after: -# delimiter: "\n" -# sequence: -# - lambda: UARTDebug::log_string(direction, bytes); ############################################# # General esp status LED @@ -166,7 +175,6 @@ status_led: ignore_strapping_warning: True #https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins inverted: false - ############################################# # LD2410 Sensors # https://esphome.io/components/sensor/ld2410.html @@ -366,12 +374,13 @@ sensor: name: g8 still energy # The ld2410 switch allows you to control your LD2410 Sensor. +#Bluetooth switch is only useful of you have a B or C model switch: - platform: ld2410 engineering_mode: name: ${friendly_name} LD2140 Engineering Mode - bluetooth: - name: ${friendly_name} LD2140 Control Bluetooth + #bluetooth: + #name: ${friendly_name} LD2140 Control Bluetooth #The ld2410 binary sensors to get presence notification binary_sensor: @@ -407,11 +416,12 @@ button: name: Query Parameters #The ld2410 text sensor allows you to get information about your LD2410 Sensor. +#Bluetooth sensor is only useful of you have a B or C model text_sensor: - platform: ld2410 version: name: ${friendly_name} LD2140 Firmware Version - mac_address: - name: ${friendly_name} LD2140 BT MAC Address + #mac_address: + #name: ${friendly_name} LD2140 BT MAC Address diff --git a/esphome/esp-weatherstation.yaml b/esphome/esp-weatherstation.yaml index 1c4ab77..6d98739 100644 --- a/esphome/esp-weatherstation.yaml +++ b/esphome/esp-weatherstation.yaml @@ -7,6 +7,7 @@ # zorruno 2024-05-24 V1.1 Tested ok and added some V calibration for mine # zorruno 2024-05-25 V2 A bunch more sensors added (wind direction not yet sorted) # zorruno 2024-05-25 V3 Shuffled some sensors, rain count added +# zorruno 2024-06-03 V4 tweaks to battery and wind ############################################# ############################################# @@ -24,39 +25,42 @@ # bmp280: Temp/pressure on the board (0x76 i2c) # pulse_meter: Wind Speed (GPIO14) # pulse_meter: Rainfall (GPIO12) - +# # text_sensor: Beaufort Wind Scale Labelling # text_sensor: Temp (av) Average of all temps # +# Battery Calcs: +# template: Last 30mins battery MAX +# template: battery now - max (discharge/charge) +# template binary: discharging, charging, stable +# # TO TEST (HAVE SENSOR or doesn't need one) # tsl2561: Ambient Light sensor (0x39 i2c) # ads1115 A1_GND: UV Index # ads1115 A0_GND: Wind Direction # -# Battery Calcs: -# template: Last 20mins battery MAX -# template: battery now - max (discharge/charge) -# template binary: discharging, charging, stable -# # ORDERED BUT DON'T HAVE YET # ltr390: Ambient Light and UV sensor (0x53 i2c) # pmsx003: PM Particulate Filter (UART) # AS3935: lightning sensor (i2c, but needs design) +# ds1307: RTC (i2c) # -# NOT USED (code commented) +# NOT USED (but code commented) # bme280_i2c: Temp/humid/press (not used) # # POSSIBLY ADD # Analogue for Solar V? # ground movement/earthquake? # water sensor (rain now) +# soil temp +# soil moisture # ############################################# ############################################# # WEMOS D1 Mini GPIO, and Weather station Use ############################################# -# PIN HEADERS ON Weatherstation board: +# PIN HEADERS on Weatherstation board: # D1, GPIO5 Used as SCL (I2C) # D2, GPIO4 Used as SDA (I2C) # D3, GPIO0 connected to FLASH button, boot fails if pulled LOW @@ -66,7 +70,7 @@ # D7, GPIO13 Used for DHT # D8, GPIO15 (Boot fails if pulled HIGH) # -# NO HEADERS ON Weatherstation board: +# NO HEADERS on Weatherstation board: # D0, GPIO16, (used to wake up from deep sleep) # RX, GPIO3 (HIGH at boot) # TX, GPIO1 (HIGH at boot, boot fails if pulled LOW) @@ -140,7 +144,7 @@ esp8266: i2c: sda: GPIO4 scl: GPIO5 - scan: True + scan: True #scan the bus on startup. Useful if looking for the address of something #frequency: 100kHz #10, 50, 100, 200, 800 are possible settings, 100kHz was reliable for me for ESP32, default is 50kHz ############################################# @@ -148,7 +152,7 @@ i2c: # https://esphome.io/components/logger.html ############################################# logger: - level: DEBUG #INFO Level suggested, or DEBUG for testing + level: INFO #INFO Level suggested, or DEBUG for testing #baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #esp8266_store_log_strings_in_flash: false #tx_buffer_size: 64 @@ -195,8 +199,8 @@ wifi: # and not compile, or it will crash occasionally) # https://esphome.io/components/web_server.html ############################################# -web_server: - port: 80 +#web_server: +# port: 80 # version: 1 #V1 occasionally works better, V2 The nicer page # username: !secret web_server_username #probably a good idea to secure it # password: !secret web_server_password @@ -267,14 +271,35 @@ text_sensor: id: wind_dir update_interval: never +############################################# ############################################# # General Sensors # https://esphome.io/components/sensor/index.html ############################################# +############################################# sensor: ################################ - # BMP280 temp/pressure + # UPTIME + # Device uptime info + # https://esphome.io/components/sensor/uptime.html + ################################ + - platform: uptime + name: ${friendly_name} Uptime + + ################################ + # WIFI SIGNAL + # Quality of Wifi in dBm + # https://esphome.io/components/sensor/wifi_signal.html + ################################ + - platform: wifi_signal + name: ${friendly_name} WiFi Signal + update_interval: ${update_time} + #retain: true #retain useful if sleeping + + ################################ + # BMP280 TEMPERATURE AND PRESSURE + # The BMP does not have humidity, use the BME for that # https://esphome.io/components/sensor/bmp280.html ################################ - platform: bmp280 @@ -292,37 +317,9 @@ sensor: unit_of_measurement: "hPa" oversampling: 16X #retain: true #MQTT retain useful if sleeping - ################################ - # BME280 temp/humidity/pressure (Note, BME and BMP Are different...) - # https://esphome.io/cookbook/bme280_environment.html - ################################ - #- platform: bme280_i2c - # address: 0x76 - # update_interval: ${update_time} - # temperature: - # name: ${friendly_name} BME280 Temp - # accuracy_decimals: 1 - # oversampling: 2x - # unit_of_measurement: "°C" - # #retain: true #MQTT retain useful if sleeping - # pressure: - # name: ${friendly_name} BME280 Pressure - # oversampling: 2x - # unit_of_measurement: "hPa" - # #retain: true #MQTT retain useful if sleeping - # humidity: - # name: ${friendly_name} BME280 Humidity - # accuracy_decimals: 1 - # oversampling: 2x - # unit_of_measurement: "%" - # #retain: true #MQTT retain useful if sleeping - - - - ################################ - # DHT temp/humidity + # DHT TEMPERATURE, PRESSURE & HUMIDITY # https://esphome.io/components/sensor/dht.html # These DHTs are not very accurate... ################################ @@ -337,63 +334,24 @@ sensor: name: ${friendly_name} DHT22 Humidity unit_of_measurement: "%" #retain: true #retain useful if sleeping - + ################################ - # TSL2561 ambient light sensor - # https://esphome.io/components/sensor/tsl2561.html + # TEMP SENSORS AVERAGE + # Averaging for the various temp sensors on board ################################ - #- platform: tsl2561 - # name: ${friendly_name} Ambient Light - # address: 0x39 - # update_interval: 60s - - ################################ - # LTR390 Ambient Light and UV Sensor - # https://esphome.io/components/sensor/ltr390.html - ################################ - #- platform: ltr390 - # address: 0x35 - # uv_index: - # name: ${friendly_name} 390 UV Index - # uv: - # name: ${friendly_name} 390 UV Sensor Counts - # light: - # name: ${friendly_name} 390 Light - # ambient_light: - # name: ${friendly_name} 390 UV Sensor Counts - # update_interval: 60s - - ################################ - # PMSX003 Particulate sensor - # NEEDS UART SET FIRST - # https://esphome.io/components/sensor/pmsx003.html - ################################ - #- platform: pmsx003 - # type: PMSX003 - # pm_1_0: - # name: ${friendly_name} Particulate Matter <1.0µm - # pm_2_5: - # name: ${friendly_name} <2.5µm - # pm_10_0: - # name: ${friendly_name} <10.0µm Concentration - - ################################ - # Device uptime info - # https://esphome.io/components/sensor/uptime.html - ################################ - - platform: uptime - name: ${friendly_name} Uptime - -################################ -# Quality of Wifi in dBm -# https://esphome.io/components/sensor/wifi_signal.html -################################ - - platform: wifi_signal - name: ${friendly_name} WiFi Signal - update_interval: ${update_time} - #retain: true #retain useful if sleeping + - platform: template + name: ${friendly_name} Temp (av) + icon: "mdi:thermometer" + unit_of_measurement: "°C" + lambda: |- + return ( + id(bmp280_temp).state + + + id(dht_temp).state + ) / 2; ################################ + # BATTERY VOLTAGE # Analog sensor for voltage reading # (A0 on esp8266) # https://esphome.io/components/sensor/adc.html @@ -404,10 +362,15 @@ sensor: pin: A0 unit_of_measurement: "V" accuracy_decimals: 6 - update_interval: 10s + update_interval: 30s #retain: true #retain useful if sleeping filters: + - heartbeat: 30s - multiply: 5.223 # tested with multimeter + - sliding_window_moving_average: + window_size: 2 #2x 30s = 60s average period + send_every: 1 + send_first_at: 1 - calibrate_linear: - 3.321 -> 3.125 - 3.89 -> 3.90 @@ -427,7 +390,7 @@ sensor: return id(battery_voltage).state; //grabs values from the battery_voltage filters: - sliding_window_moving_average: - window_size: 40 #40x 30s = 20 min average period + window_size: 60 #40x 30s = 20 min average period send_every: 1 send_first_at: 1 @@ -440,12 +403,13 @@ sensor: id: battery_voltage_recentmax unit_of_measurement: "V" accuracy_decimals: 6 - update_interval: 30s #updates every 30s + update_interval: 30s #updates every 10s lambda: > return id(battery_voltage).state; //grabs values from the battery_voltage filters: + - heartbeat: 30s - max: - window_size: 40 #40x 30s = 20 min average period + window_size: 60 #60x 30s = 30 min max value send_every: 1 send_first_at: 1 @@ -458,7 +422,6 @@ sensor: lambda: > return {id(battery_voltage_recentmax).state - id(battery_voltage).state}; //recent av voltage - now - - platform: duty_time id: battery_discharge_time name: ${friendly_name} Time battery is discharging @@ -472,21 +435,179 @@ sensor: lambda: > return { id(battery_voltage).state <= id(battery_voltage_recentav).state }; - -############################################# -# WIND SENSOR -# looks like this one -# https://www.sparkfun.com/datasheets/Sensors/Weather/Weather%20Sensor%20Assembly..pdf -############################################# - -############################################# -# USEFUL LINKS -# Wind Sensing -# https://community.home-assistant.io/t/measuring-wind-speed/395693/20 -# https://community.home-assistant.io/t/measuring-wind-speed/395693/21 -############################################# + ################################ + # RAIN SENSOR + # Pulse Meter for measuring rainfall + # https://esphome.io/components/sensor/pulse_meter.html + ################################ + # CALIBRATION HINTS + # https://forum.mysensors.org/topic/9594/misol-rain-gauge-tipping-bucket-rain-amount/2 + ################################ + - platform: pulse_meter + id: rainfall_meter + pin: + number: GPIO12 #D6 on D1 Mini + mode: + input: true + pullup: true + internal_filter_mode: EDGE + internal_filter: 10ms + name: ${friendly_name} Rainfall + #icon: mdi: + unit_of_measurement: "mm" + accuracy_decimals: 1 + timeout: 5s + filters: + - heartbeat: 2s + #- timeout: + # timeout: "5s" #after 5 seconds, if no pulses received.... + # value: 0 #make the value = 0 + - multiply: 0.2794 #mm of rain from tip bucket, 0.28 mm per pulse, or 3.57 pulse per mm (NEEDS CALIBRATION) + - sliding_window_moving_average: # Moving average to prevent too many data points + window_size: 4 + send_every: 1 + #- clamp: + # min_value: 0 + # max_value: 250 #if anything over that, we have debounce issues or are going to die + # ignore_out_of_range: true ################################ + # Pulse Meter for measuring wind speed + # Analog sensor for voltage reading + # https://esphome.io/components/sensor/pulse_meter.html + # + # This Anenometer https://www.sparkfun.com/datasheets/Sensors/Weather/Weather%20Sensor%20Assembly..pdf + # The cup-type anemometer measures wind speed by closing a contact + # as a magnet moves past a reed switch. A wind speed of 1.492mph (2.4km/h) (0.667m/s) + # causes the switch to close once per second. The reed switch closes twice per revolution. + # 1rps = 60rpm = 2.4kmh + # 1pulse/min = 2.4kmh/60 = 0.04kmh + # Pulse meter component measures the time between rising edges on a pin, + # for each pulse it outputs the frequency in pulses/min. + ################################ + # USEFUL LINKS + # https://community.home-assistant.io/t/measuring-wind-speed/395693/20 + # https://community.home-assistant.io/t/measuring-wind-speed/395693/21 + ############################################# + - platform: pulse_meter # https://community.home-assistant.io/t/measuring-wind-speed/395693 + id: wind_meter + pin: + number: GPIO14 #D5 on D1 Mini + mode: + input: true + pullup: true + #internal: true # If true, don't send to HA/MQTT etc + internal_filter_mode: EDGE + internal_filter: 10ms + name: ${friendly_name} Wind speed + icon: "mdi:weather-windy" + unit_of_measurement: "km/h" + accuracy_decimals: 1 + timeout: 5s + filters: + - heartbeat: 2s + #- timeout: + # timeout: "5s" #after 5 seconds, if no pulses received.... + # value: 0 #make the value = 0 + - multiply: 0.04 #kmh + - sliding_window_moving_average: # Moving average to prevent too many data points + window_size: 4 + send_every: 1 + - clamp: + min_value: 0 + max_value: 250 #if anything over that, we have debounce issues or are going to die + ignore_out_of_range: true + + # - platform: pulse_counter + # # https://community.home-assistant.io/t/measuring-wind-speed/395693 + # id: wind_pulses + # pin: + # number: GPIO14 #D5 on D1 Mini + # mode: + # input: true + # pullup: true + + ################################ + # WIND 10 MINUTE MAX + # Template for wind gust measurements + # To measure GUST properly, the World Meteorological Organization + # recommends gust measurement should be wind speed averages over + # 3 second periods and report the maximum of these averages + # within a sliding window of the last 10 minutes. + # This needs a wind speed history buffer of 200 samples + # (200 x 3 second average = 10 minutes) + ################################ + # Useful links + # https://community.home-assistant.io/t/adding-an-old-marine-anemometer-to-ha/337842 + ################################ + - platform: template + name: ${friendly_name} Windspeed Gust (Max last 10m) + unit_of_measurement: "km/h" + update_interval: 3s #updates every 2s + lambda: > + return id(wind_meter).state; //grabs values from the wind_sensor + filters: + - filter_out: nan #in case there is no value + - max: + window_size: 200 #10 Min window as 3s update x 200 = 10min + send_every: 1 #updates on the 1st 2s check + send_first_at: 1 #on restart, send after first 10s + + ################################ + # BEAUFORT SCALE + # Template for Beaufort for measuring wind speed + # The output updates the Text Sensor ID wind_scale + # https://windy.app/blog/wind-speed-beaufort-scale.html + ################################ + - platform: template + #name: ${friendly_name} Windspeed Scale + internal: true # no need to show this externally as it is just for calculating Beaufort + #icon: "mdi:weather-windy" + id: wind_meter_scale + lambda: return id(wind_meter).state; + #unit_of_measurement: "m/s" + update_interval: 5s + filters: + - throttle_average: 5s + - multiply: 0.278 #to get m/s from km/h + on_value: + lambda: |- + if (id(wind_meter_scale).state < 0.1) { + id(wind_scale).publish_state("Calm"); + } else if (id(wind_meter_scale).state > 0 && id(wind_meter_scale).state < 2) { + id(wind_scale).publish_state("Light Air"); + } else if (id(wind_meter_scale).state >= 2 && id(wind_meter_scale).state < 3) { + id(wind_scale).publish_state("Light Breeze"); + } else if (id(wind_meter_scale).state >= 3 && id(wind_meter_scale).state < 5) { + id(wind_scale).publish_state("Gentle Breeze"); + } else if (id(wind_meter_scale).state >= 5 && id(wind_meter_scale).state < 8) { + id(wind_scale).publish_state("Moderate Breeze"); + } else if (id(wind_meter_scale).state >= 8 && id(wind_meter_scale).state < 11) { + id(wind_scale).publish_state("Fresh Breeze"); + } else if (id(wind_meter_scale).state >= 11 && id(wind_meter_scale).state < 14) { + id(wind_scale).publish_state("Strong Breeze"); + } else if (id(wind_meter_scale).state >= 14 && id(wind_meter_scale).state < 17) { + id(wind_scale).publish_state("Near Gale"); + } else if (id(wind_meter_scale).state >= 17 && id(wind_meter_scale).state < 21) { + id(wind_scale).publish_state("Gale"); + } else if (id(wind_meter_scale).state >= 21 && id(wind_meter_scale).state < 24) { + id(wind_scale).publish_state("Severe Gale"); + } else if (id(wind_meter_scale).state >= 24 && id(wind_meter_scale).state < 28) { + id(wind_scale).publish_state("Storm"); + } else if (id(wind_meter_scale).state >= 28 && id(wind_meter_scale).state < 33) { + id(wind_scale).publish_state("Violent Storm"); + } else if (id(wind_meter_scale).state >= 33) { + id(wind_scale).publish_state("Hurricane Force"); + } else { + id(wind_scale).publish_state(""); + } + + ############################################# + # WIND DIRECTION SENSOR + # looks like this one + # https://www.sparkfun.com/datasheets/Sensors/Weather/Weather%20Sensor%20Assembly..pdf + # uses black and green cables for R value + ############################################# # Wind Direction, Analogue on ADS115 # Analog sensor for voltage reading # https://esphome.io/components/sensor/ads1115.html @@ -497,12 +618,21 @@ sensor: # values giving the output voltage value for each azimuth. # We could also report a compass direction. ################################ + # Useful Links + # https://community.home-assistant.io/t/davis-wind-direction-equipment-and-esp-home/508764 + ################################ - platform: ads1115 multiplexer: 'A0_GND' - gain: 6.144 + gain: 4.096 name: ${friendly_name} Wind Direction id: wind_direction - update_interval: 5s + update_interval: 2s + # measured V Max: 3.31 Min: 0.585 + #- calibrate_linear + # Map 0.0 (from sensor) to 0.0 (true value) + # - 0.585 -> 0 + # - 3.31 -> 100 + # filters: # lambda: |- # if( (x * (360.0/5.0)) >= 10.0 && (x * (360.0/5.0)) <= 70.0 ) { return x = 45 }; @@ -554,82 +684,6 @@ sensor: -# - platform: pulse_meter -# pin: - # number: GPIO13 #This is Pin D7 on the D1 Mini ESP8266 - # mode: -# input: true -# pullup: true -# name: ${friendly_name} Wind speed -# id: wind_meter -# unit_of_measurement: m/s -# accuracy_decimals: 1 -# timeout: 5s -# internal_filter_mode: EDGE -# internal_filter: 10ms - - # A wind speed of 2.4km/h (1.492mph) causes the switch to close once per second. - # that is 0.667m/s. - # Switch closes twice per revolution - - # rotations_per_sec = pulses / 2 / 60 - # circ_m = 0.09 * 2 * 3.14 = 0.5652 - # mps = 1.18 * circ_m * rotations_per_sec - # mps = 1.18 * (0.5652 / 2 / 60) = 0.0055578 -# -# filters: -# # - multiply: 0.0055578 #use for m/s -# # - multiply: 2.237 #m/s to mph -# # - multiply: 0.0124327986 #m/s * mph conversion -# # - multiply: ? #m/s to kph -# - multiply: 0.0055578 -# - sliding_window_moving_average: # Helps prevent too many datapoints -# window_size: 10 -# send_every: 10 - - ################################ - # Pulse Meter for measuring wind speed - # Analog sensor for voltage reading - # https://esphome.io/components/sensor/pulse_meter.html - # - # This Anenometer https://www.sparkfun.com/datasheets/Sensors/Weather/Weather%20Sensor%20Assembly..pdf - # - # The cup-type anemometer measures wind speed by closing a contact - # as a magnet moves past a reed switch. A wind speed of 1.492mph (2.4km/h) (0.667m/s) - # causes the switch to close once per second. The reed switch closes twice per revolution. - # 1rps = 60rpm = 2.4kmh - # 1pulse/min = 2.4kmh/60 = 0.04kmh - # Pulse meter component measures the time between rising edges on a pin, - # for each pulse it outputs the frequency in pulses/min. - ################################ - - platform: pulse_meter # https://community.home-assistant.io/t/measuring-wind-speed/395693 - id: wind_meter - pin: - number: GPIO14 #D5 on D1 Mini - mode: - input: true - pullup: true - #internal: true # If true, don't send to HA/MQTT etc - internal_filter_mode: EDGE - internal_filter: 10ms - name: ${friendly_name} Wind speed - icon: "mdi:weather-windy" - unit_of_measurement: "km/h" - accuracy_decimals: 1 - timeout: 5s - filters: - - heartbeat: 2s - #- timeout: - # timeout: "5s" #after 5 seconds, if no pulses received.... - # value: 0 #make the value = 0 - - multiply: 0.04 #kmh - - sliding_window_moving_average: # Moving average to prevent too many data points - window_size: 4 - send_every: 1 - - clamp: - min_value: 0 - max_value: 250 #if anything over that, we have debounce issues or are going to die - ignore_out_of_range: true # on_value: # lambda: |- @@ -665,18 +719,7 @@ sensor: # - throttle: 30s - - platform: template - name: ${friendly_name} Windspeed Gust (Max last 10m) - unit_of_measurement: "km/h" - update_interval: 2s #updates every 2s - lambda: > - return id(wind_meter).state; //grabs values from the wind_sensor - filters: - - filter_out: nan #in case there is no value - - max: - window_size: 300 #10 Min window as 2s update x 300 = 10min - send_every: 1 #updates on the 1st 2s check - send_first_at: 1 #on restart, send after first 10s + # https://www.reddit.com/r/Esphome/comments/kndues/take_max_value_over_time/ @@ -791,66 +834,40 @@ sensor: # id: id_wind_speed_avg_10min +# - platform: pulse_meter +# pin: + # number: GPIO13 #This is Pin D7 on the D1 Mini ESP8266 + # mode: +# input: true +# pullup: true +# name: ${friendly_name} Wind speed +# id: wind_meter +# unit_of_measurement: m/s +# accuracy_decimals: 1 +# timeout: 5s +# internal_filter_mode: EDGE +# internal_filter: 10ms + + # A wind speed of 2.4km/h (1.492mph) causes the switch to close once per second. + # that is 0.667m/s. + # Switch closes twice per revolution + + # rotations_per_sec = pulses / 2 / 60 + # circ_m = 0.09 * 2 * 3.14 = 0.5652 + # mps = 1.18 * circ_m * rotations_per_sec + # mps = 1.18 * (0.5652 / 2 / 60) = 0.0055578 +# +# filters: +# # - multiply: 0.0055578 #use for m/s +# # - multiply: 2.237 #m/s to mph +# # - multiply: 0.0124327986 #m/s * mph conversion +# # - multiply: ? #m/s to kph +# - multiply: 0.0055578 +# - sliding_window_moving_average: # Helps prevent too many datapoints +# window_size: 10 +# send_every: 10 - ################################ - # Averaging for the various temp sensors on board - ################################ - - platform: template - name: ${friendly_name} Temp (av) - icon: "mdi:thermometer" - unit_of_measurement: "°C" - lambda: |- - return ( - id(bmp280_temp).state - + - id(dht_temp).state - ) / 2; - ################################ - # Template for Beaufort for measuring wind speed - # https://windy.app/blog/wind-speed-beaufort-scale.html - ################################ - - platform: template - name: ${friendly_name} Windspeed Scale - icon: "mdi:weather-windy" - id: wind_meter_scale - lambda: return id(wind_meter).state; - unit_of_measurement: "m/s" - update_interval: 5s - filters: - - throttle_average: 5s - - multiply: 0.278 #to get m/s from km/h - on_value: - lambda: |- - if (id(wind_meter_scale).state < 0.1) { - id(wind_scale).publish_state("Calm"); - } else if (id(wind_meter_scale).state > 0 && id(wind_meter_scale).state < 2) { - id(wind_scale).publish_state("Light Air"); - } else if (id(wind_meter_scale).state >= 2 && id(wind_meter_scale).state < 3) { - id(wind_scale).publish_state("Light Breeze"); - } else if (id(wind_meter_scale).state >= 3 && id(wind_meter_scale).state < 5) { - id(wind_scale).publish_state("Gentle Breeze"); - } else if (id(wind_meter_scale).state >= 5 && id(wind_meter_scale).state < 8) { - id(wind_scale).publish_state("Moderate Breeze"); - } else if (id(wind_meter_scale).state >= 8 && id(wind_meter_scale).state < 11) { - id(wind_scale).publish_state("Fresh Breeze"); - } else if (id(wind_meter_scale).state >= 11 && id(wind_meter_scale).state < 14) { - id(wind_scale).publish_state("Strong Breeze"); - } else if (id(wind_meter_scale).state >= 14 && id(wind_meter_scale).state < 17) { - id(wind_scale).publish_state("Near Gale"); - } else if (id(wind_meter_scale).state >= 17 && id(wind_meter_scale).state < 21) { - id(wind_scale).publish_state("Gale"); - } else if (id(wind_meter_scale).state >= 21 && id(wind_meter_scale).state < 24) { - id(wind_scale).publish_state("Severe Gale"); - } else if (id(wind_meter_scale).state >= 24 && id(wind_meter_scale).state < 28) { - id(wind_scale).publish_state("Storm"); - } else if (id(wind_meter_scale).state >= 28 && id(wind_meter_scale).state < 33) { - id(wind_scale).publish_state("Violent Storm"); - } else if (id(wind_meter_scale).state >= 33) { - id(wind_scale).publish_state("Hurricane Force"); - } else { - id(wind_scale).publish_state(""); - } #switch: # - platform: template @@ -918,39 +935,68 @@ sensor: # restore_value: no # initial_value: '0.0' - ################################ - # Pulse Meter for measuring rainfall - # https://esphome.io/components/sensor/pulse_meter.html - # + ################################ - # CALIBRATION HINTS - # https://forum.mysensors.org/topic/9594/misol-rain-gauge-tipping-bucket-rain-amount/2 + # BME280 temp/humidity/pressure (Note, BME and BMP Are different...) + # https://esphome.io/cookbook/bme280_environment.html ################################ - - platform: pulse_meter - id: rainfall_meter - pin: - number: GPIO12 #D6 on D1 Mini - mode: - input: true - pullup: true - #internal: true # If true, don't send to HA/MQTT etc - internal_filter_mode: EDGE - internal_filter: 10ms - name: ${friendly_name} Rainfall - #icon: mdi: - unit_of_measurement: "mm" - accuracy_decimals: 1 - timeout: 5s - filters: - - heartbeat: 2s - #- timeout: - # timeout: "5s" #after 5 seconds, if no pulses received.... - # value: 0 #make the value = 0 - - multiply: 0.2794 #mm of rain from tip bucket, 0.28 mm per pulse, or 3.57 pulse per mm (NEEDS CALIBRATION) - - sliding_window_moving_average: # Moving average to prevent too many data points - window_size: 4 - send_every: 1 - #- clamp: - # min_value: 0 - # max_value: 250 #if anything over that, we have debounce issues or are going to die - # ignore_out_of_range: true \ No newline at end of file + #- platform: bme280_i2c + # address: 0x76 + # update_interval: ${update_time} + # temperature: + # name: ${friendly_name} BME280 Temp + # accuracy_decimals: 1 + # oversampling: 2x + # unit_of_measurement: "°C" + # #retain: true #MQTT retain useful if sleeping + # pressure: + # name: ${friendly_name} BME280 Pressure + # oversampling: 2x + # unit_of_measurement: "hPa" + # #retain: true #MQTT retain useful if sleeping + # humidity: + # name: ${friendly_name} BME280 Humidity + # accuracy_decimals: 1 + # oversampling: 2x + # unit_of_measurement: "%" + # #retain: true #MQTT retain useful if sleeping + + + ################################ + # TSL2561 ambient light sensor + # https://esphome.io/components/sensor/tsl2561.html + ################################ + #- platform: tsl2561 + # name: ${friendly_name} Ambient Light + # address: 0x39 + # update_interval: 60s + + ################################ + # LTR390 Ambient Light and UV Sensor + # https://esphome.io/components/sensor/ltr390.html + ################################ + #- platform: ltr390 + # address: 0x35 + # uv_index: + # name: ${friendly_name} 390 UV Index + # uv: + # name: ${friendly_name} 390 UV Sensor Counts + # light: + # name: ${friendly_name} 390 Light + # ambient_light: + # name: ${friendly_name} 390 UV Sensor Counts + # update_interval: 60s + + ################################ + # PMSX003 Particulate sensor + # NEEDS UART SET FIRST + # https://esphome.io/components/sensor/pmsx003.html + ################################ + #- platform: pmsx003 + # type: PMSX003 + # pm_1_0: + # name: ${friendly_name} Particulate Matter <1.0µm + # pm_2_5: + # name: ${friendly_name} <2.5µm + # pm_10_0: + # name: ${friendly_name} <10.0µm Concentration \ No newline at end of file