Monitor your car battery in Home Assistant

Has anyone done this using Esphome instead of Tasmota? If so, would you please post and share your yaml code?

Sorry for the dumb question but what will happen if you don’t use the resistors and I connect directly the 12V to the AO pin of the D1 mini?

Thanks!

Hi, if you connect the battery directly without increasing the voltge divider resistor, you will feed 4V into the ESP8266 which is rated for Max 1V and destroy it.

You might want to watch this ESP8266 intro video to get more context - specifically jump to 1:42 where it shows the voltage divider part. https://youtu.be/dGrJi-ebZgI

As for ESPHome, I don’t have experience in that domain and I rather leave it to someone who does - so I can’t really answer that.

Hope that helped.

1 Like

Looks like you can accomplish this using the DEEP SLEEP feature. “Further Reading

I’m going to test it and and see how it works.

Although unconfirmed, based on some other threads, Deep Sleep is not recomended with Esphome, as it causes some errors in HA.

Actually, I implemented this using Esphome and deep sleep and everything works well.

Cool, do you mined sharing your config?

Sure!

Make sure that you have GPIO16 (pin D0 on the D1 mini board) connected to ground RST.

substitutions:
  devicename: battery_voltage
  devicename_friendly: Car Battery
  ip_address: 192.168.2.219


esphome:
  name: ${devicename}
  platform: ESP8266
  board: d1_mini
  
<<:  !include common/wifi_setup.yaml

<<:  !include common/logger.yaml

<<:  !include common/ota.yaml

deep_sleep:
  run_duration: 20s
  sleep_duration: 60min
  id: battery_deep_sleep

mqtt:
  broker: 192.168.2.XXX
  username: !secret mqtt_username
  password: !secret mqtt_password
  
  on_message:
    - topic: deep_sleep/ota_mode
      payload: 'ON'
      then:
        - deep_sleep.prevent: battery_deep_sleep
  
    
    - topic: deep_sleep/ota_mode
      payload: 'OFF'
      then:
        - deep_sleep.enter: battery_deep_sleep



binary_sensor:

  - !include common/binary_sensor_network_status.yaml
  

sensor:

  - platform: adc
    pin: A0
    name: "Voltage"
    update_interval: 10s
    filters:
      - multiply: 14.5583
    
    
  - !include common/wifi_signal.yaml
  
  - !include common/uptime.yaml
  
switch:

  - !include common/device_restart_switch.yaml
  

text_sensor:



  - !include common/mac_address_info.yaml

  - !include common/version.yaml
  
  - !include common/wifi_info.yaml

These scripts are in HA to stop/resume deep sleep if needed for an OTA update.

####################################################################    
stop_deep_sleep_on_esphome_devices:
  alias: Stop Deep Sleep
  sequence:
  - service: mqtt.publish
    data:
      topic: deep_sleep/ota_mode
      payload: 'ON'
      qos: 2
      retain: true
  - service: notify.mobile_app_my_iphone
    data:
      title: Deep Sleep
      message: Deep sleep turned off for OTA updates
      
####################################################################
resume_deep_sleep_on_esphomedevices:
  alias: Resume Deep Sleep
  sequence:
  - service: mqtt.publish
    data:
      topic: deep_sleep/ota_mode
      payload: 'OFF'
      qos: 2
      retain: true
  - service: notify.mobile_app_my_iphone
    data:
      title: Deep Sleep
      message: Deep sleep turned on

####################################################################

2 Likes

Thanks, did you try with the API and not MQTT?

I don’t remember where is the documentation, but I am 99.99% sure that you cannot use the API with deep sleep.

@laca75tn That’s what I meant by my previous statement.

Fake news

You should use MQTT not API for deep sleep.

Can you elaborate on this a little, why not for API?

I would have to find the thread(s) that explain it. It is probably the same one that gave you the impression that deep sleep is not recommended.

To GROUND or RST?

You are correct. D0 must be connected to RST. I fixed my post. Thanks!

1 Like

Hello I am trying to get this up and running via esp home but when uploading your config yaml I get an error
Error reading file /config/esphome/common/binary_sensor_network_status.yaml: [Errno 2] No such file or directory: ‘/config/esphome/common/binary_sensor_network_status.yaml’

this text is in red in your post so I think it needs to be changed for my setup but I am at a loss as what too? If you could expand a little please?

Can i use this to moniter my 12v 165ah solar battery
Tell me.

Those are pointers to included files. You can replace those with the ‘regular’ code you would have in an esphome node for wifi,log, ota etc
I can post the code in the more traditional way on Monday. Thanks

1 Like

Yes you can, just make sure that you have the correct resistors for the battery Amperage, otherwise you will burn your microprocessor.

1 Like

That would be great , thank you

Try this. This is the version without the included files.

substitutions:
  devicename: battery_voltage
  devicename_friendly: Car Battery
  ip_address: 192.168.1.219


esphome:
  name: ${devicename}
  platform: ESP8266
  board: d1_mini
  
wifi:
  networks:
    ssid: "HomeAssistant"
    password: "MyPassword"
    priority: 1
    
  #use_address: ${devicename}.local

  power_save_mode: none  

  reboot_timeout: 15min

  manual_ip:
    
    static_ip: ${ip_address}
    subnet: 255.255.255.0
    gateway: 192.168.1.1
    dns1: 192.168.1.1

  ap:
    ssid: "${devicename} Hotspot"
    password: "AnotherPassword"

  fast_connect: true     


captive_portal:    

logger:
  baud_rate: 0
  level: VERBOSE

ota:

deep_sleep:
  run_duration: 20s
  sleep_duration: 60min
  id: battery_deep_sleep

mqtt:
  broker: 192.168.1.XXX
  username: !secret mqtt_username
  password: !secret mqtt_password
  
  on_message:
    - topic: deep_sleep/ota_mode
      payload: 'ON'
      then:
        - deep_sleep.prevent: battery_deep_sleep
  
    
    - topic: deep_sleep/ota_mode
      payload: 'OFF'
      then:
        - deep_sleep.enter: battery_deep_sleep



binary_sensor:

  - platform: status
    name: ${devicename} network status
    id: ${devicename}_network_status
  

sensor:

  - platform: adc
    pin: A0
    name: "Voltage"
    update_interval: 10s
    filters:
      - multiply: 14.5583
    
    
  - platform: wifi_signal
    name: ${devicename} WiFi Signal
    update_interval: 60s
  
  - platform: uptime
    name: ${devicename} Uptime
    unit_of_measurement: h
    filters:
      - lambda: return int((x + 1800.0) / 3600.0);
  
switch:

  - platform: restart
    name: ${devicename} Restart
    id: restart_${devicename} 
  

text_sensor:

  - platform: version
    name: ${devicename} ESPHome version

  - platform: wifi_info
    ip_address:
      name: ${devicename} IP Address
    ssid:
      name: ${devicename} Connected SSID 
    bssid:
      name: ${devicename} BSSID

2 Likes