############################################# ############################################# # 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 mqtt_topic: "esphome" #main topic for the mqtt server, call it what you like update_time: 30s #update time for for temp sensors etc #Add these if we are giving it a static ip, or remove them in the Wifi section static_ip_address: !secret esp-attobat_static_ip static_ip_gateway: !secret esp-attobat_gateway static_ip_subnet: !secret esp-attobat_subnet ############################################# # ESPHome ############################################# esphome: name: $devicename comment: ${description_comment} #appears on the esphome page in HA ############################################# # 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: safe_mode: true #Safe mode will detect boot loops password: ${ota_pass} ############################################# # Wifi Settings # https://esphome.io/components/wifi.html ############################################# wifi: ssid: !secret wifi_ssid password: !secret wifi_password #power_save_mode: LIGHT #https://esphome.io/components/wifi.html#wifi-power-save-mode # Static IP (for lower power/quicker on time) manual_ip: 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 ap_timeout: 5min #default is 1min captive_portal: # Fallback captive portal https://esphome.io/components/captive_portal.html ############################################# # Web Portal for display and monitoring ############################################# web_server: port: 80 version: 2 include_internal: true ota: false auth: username: !secret web_server_username password: !secret web_server_password ############################################# # MQTT Monitoring # https://esphome.io/components/mqtt.html?highlight=mqtt # MUST also have api enabled if you enable MQTT ############################################# mqtt: broker: !secret mqtt_server topic_prefix: ${mqtt_topic}/${devicename} #username: !secret mqtt_username #password: !secret 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/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 ######################################## # 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: 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: - 0.41 -> 6.00 - 0.48 -> 7.00 - 0.54 -> 8.00 - 0.61 -> 9.00 - 0.68 -> 10.00 - 0.75 -> 11.00 - 0.81 -> 12.00 - 0.88 -> 13.00 - 0.94 -> 13.99 - 0.99 -> 14.70