Files
zorruno-homeassistant/esphome/esp-leafbat2.yaml
2024-06-06 11:08:40 +12:00

177 lines
5.3 KiB
YAML

#############################################
#############################################
# 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"
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}
comment: ${description_comment} #appears on the esphome page in HA
########################################
# Specific board for ESPHome device
########################################
esp8266:
board: d1_mini
#############################################
# ESPHome Logging Enable
#############################################
logger:
########################################
# Enable the Home Assistant API
########################################
api:
encryption:
key: ${api_key}
########################################
# Enable Over the Air Update Capability
# Safe mode will detect boot loops
########################################
ota:
safe_mode: true
password: ${ota_pass}
########################################
# Use Wifi
# (credentials are in secrets file)
########################################
wifi:
ssid: ${wifi_ssid}
password: ${wifi_password}
# Details for fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ${fallback_ap_ssid}
password: ${fallback_ap_password}
# Static IP (for lower power/quicker on time)
manual_ip:
static_ip: ${static_ip_address}
gateway: ${static_ip_gateway}
subnet: ${static_ip_subnet}
#############################################
# Fallback captive portal
#############################################
captive_portal:
########################################
# Web Portal for display and monitoring
########################################
web_server:
port: 80
auth:
username: ${web_server_username}
password: ${web_server_password}
########################################
# MQTT Monitoring
########################################
mqtt:
broker: ${mqtt_server}
topic_prefix: ${mqtt_topic}
username: ${mqtt_username}
password: ${mqtt_password}
#
# Availability Topic
#birth_message:
# topic: esphome/esp-leafbat2/availability
# payload: online
#will_message:
# topic: esphome/esp-leafbat2/availability
# payload: offline
# A way to prevent deep sleep using MQTT command
on_message:
- topic: viewroad-commands/leafbat2/deepsleep
payload: 'ON'
then:
- deep_sleep.prevent: deep_sleep_1
- topic: viewroad-commands/leafbat2/deepsleep
payload: 'ON'
then:
- deep_sleep.enter: deep_sleep_1
########################################
# Deep Sleep
########################################
deep_sleep:
run_duration: 20s
sleep_duration: 10min
id: deep_sleep_1
#############################################
#############################################
# MAIN SENSORS
#############################################
#############################################
sensor:
# Quality of Wifi in dBm
- platform: wifi_signal
name: "WiFi Signal"
update_interval: 10s
retain: true
# Analog sensor for voltage reading (A0)
- platform: adc
pin: A0
name: "Battery Voltage"
update_interval: 10s
retain: true
filters:
- multiply: 18.52 # trial and error calc/measure
- calibrate_linear:
- 5.99 -> 6.0
- 11.98 -> 11.99
- 16.98 -> 16.98
#name: "Battery Voltage"
# Optional variables:
#retain: true