Files
zorruno-homeassistant/esphome/esp-attobat.yaml
2025-05-18 16:35:38 +12:00

217 lines
7.3 KiB
YAML

#############################################
#############################################
# BYD ATTO3 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/
##############################################
#############################################
#############################################
# Variable Substitutions
#############################################
substitutions:
devicename: "esp-attobat"
friendly_name: "Atto3 12V Battery Monitor"
description_comment: "Atto3 12V Battery Monitor (when home)"
api_key: !secret esp-attobat_api_key #unfortunately you can't use substitutions in secrets names
ota_pass: !secret esp-attobat_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
#A static IP will speed things up slightly in that it doesn't have to negotiate DHCP
static_ip_address: !secret esp-attobat_static_ip
static_ip_gateway: !secret esp-attobat_gateway
static_ip_subnet: !secret esp-attobat_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
mqtt_commandstopic: "viewroad-commands" #main topic for commands (ie sleep), call it what you like
#web_server_username: !secret web_server_username
#web_server_password: !secret web_server_password
update_time: 10s #update time for for general temp sensors etc
#############################################
# ESPHome
# https://esphome.io/components/esphome.html
#############################################
esphome:
name: ${devicename}
friendly_name: ${friendly_name}
comment: ${description_comment} #appears on the esphome page in HA
min_version: 2024.6.0
#############################################
# ESP Platform and Framework
# https://esphome.io/components/esp8266.html
# https://esphome.io/components/esp32.html
#############################################
esp8266:
board: d1_mini
framework:
version: latest #recommended, latest or dev
#############################################
# ESPHome Logging Enable
# https://esphome.io/components/logger.html
#############################################
logger:
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
#############################################
# Enable the Home Assistant API
# https://esphome.io/components/api.html
#############################################
api:
encryption:
key: ${api_key}
#############################################
# Enable Over the Air Update Capability
# https://esphome.io/components/ota.html?highlight=ota
#############################################
ota:
- platform: esphome
password: ${ota_pass}
#############################################
# Safe Mode
# Safe mode will detect boot loops
# https://esphome.io/components/safe_mode
#############################################
safe_mode:
#############################################
# Wifi Settings
# https://esphome.io/components/wifi.html
#
# Power Save mode (can reduce wifi reliability)
# NONE (least power saving, Default for ESP8266)
# LIGHT (Default for ESP32)
# HIGH (most power saving)
#############################################
wifi:
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: ${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: ${fallback_ap_password}
ap_timeout: 30min #Time until it brings up fallback AP. default is 1min
#############################################
# Web Portal for display and monitoring
#############################################
web_server:
port: 80
#version: 2
#include_internal: true
#ota: false
#auth:
#username: ${web_server_username}
#password: ${web_server_password}
#############################################
# MQTT Monitoring
# https://esphome.io/components/mqtt.html?highlight=mqtt
# MUST also have api enabled if you enable MQTT
#############################################
mqtt:
broker: ${mqtt_server}
topic_prefix: ${mqtt_topic}/${devicename}
username: ${mqtt_username}
password: ${mqtt_password}
discovery: False # enable entity discovery (true is default, we don't want two HA Instances)
# Availability Topic
birth_message:
topic: ${mqtt_topic}/${devicename}/availability
payload: online
will_message:
topic: ${mqtt_topic}/${devicename}/availability
payload: offline
# A way to prevent deep sleep using MQTT command
on_message:
- topic: ${mqtt_commandstopic}/${devicename}/deepsleep
payload: "OFF"
then:
- deep_sleep.prevent: deep_sleep_1
- topic: ${mqtt_commandstopic}/${devicename}/deepsleep
payload: "ON"
then:
- deep_sleep.enter: deep_sleep_1
# on_message:
# - topic: ${mqtt_commandstopic}/${devicename}/deepsleepon
# payload: 'ON'
# then:
# - deep_sleep.prevent: deep_sleep_1
# - topic: ${mqtt_commandstopic}/${devicename}/deepsleepoff
# payload: 'OFF'
# then:
# - deep_sleep.enter: deep_sleep_1
########################################
# Deep Sleep
# https://esphome.io/components/deep_sleep.html
########################################
deep_sleep:
run_duration: 20s
sleep_duration: 5min
id: deep_sleep_1
#############################################
#############################################
# MAIN SENSORS
#############################################
#############################################
sensor:
#Quality of Wifi in dBm
- platform: wifi_signal
name: "WiFi Signal"
update_interval: ${update_time}
retain: true #Retain this as you'll have no value between sleeps otherwise
#Analog sensor for voltage reading (A0)
- platform: uptime
name: "Uptime"
update_interval: ${update_time}
retain: true #Retain this as you'll have no value between sleeps otherwise
- platform: adc
pin: A0
name: "Battery Voltage"
update_interval: ${update_time}
retain: true #Retain this as you'll have no value between sleeps otherwise
filters:
- multiply: 3.3 #D1 mini V divider, 3.3V -> 1V on esp8266
- calibrate_linear: #Read values with voltmeter and bench supply
- 3.11 -> 14.00
- 3.00 -> 13.50
- 2.89 -> 13.00
- 2.77 -> 12.50
- 2.67 -> 12.00
- 2.55 -> 11.50
- 2.45 -> 11.00
- 2.34 -> 10.50
- 2.22 -> 10.00
- 2.11 -> 09.50
- 2.00 -> 09.00