Monitor your car battery in Home Assistant

I have just tried to add the extra line and it wont allow me to upload, is it my syntax that is not correct?
image

I am sorry, deep_sleep does not have that parameter. I got confused. You don’t need that. Thanks

1 Like

because when the engine is running the alternator engages and supplies electricity to the electrical system. When the car is off, then any active device pulls power from whatever charge is stored in the battery.

Thank you once again I now have all 3 cars with devices on. I have added an automation to notify via the app and Alexa when the voltage drops below 12 Volts.
Is there any way to display the voltages in a gauge ? So the last reading can be seen all the time, Rather than having to click on the Devices voltage field in a glance card. Using the gauge card returns “Entity is non-numeric: sensor.voltage_2”
Thanks

I think that you are trying to read the sensor from the node on EspHome. In this case, since you are using deep sleep, you need to read the mqtt sensor on HA.

- platform: mqtt
    name: Battery Voltage
    state_topic: "battery_voltage/sensor/voltage/state"
    unit_of_measurement: 'V'
    device_class: voltage
    qos: 2
    payload_available: "online"
    payload_not_available: "offline"
2 Likes

thanks for being so helpful, yes I have been getting the senor data from Esp Home.
I have added the text to my config.yaml and get this error
bad indentation of a mapping entry at line 152, column 9:
name: Battery Voltage
^
This is one of my favorite integrations and with the situation with the cars not being driven alot at the moment a very practical one.
I would love to have the gauges working for display on my wall mounted tablet.
Thanks once again If you are able to help.

1 Like

Philip,

You just need to check the indentation of the first line (platform). Make sure it’s correct in reference with the lines above it.

  - platform: mqtt

1 Like

:grinning: :grinning: :grinning: :grinning: :grinning:
Thank you so much for you help. It was a combination of the indentation and the fact I also had a sensor field higher up for the badnest, i placed the code under that and it was fine, I am still learning this yaml coding and with the help of people like yourself I am getting to understand it little by little. I presume, I just change the line to state_topic: “what i called the other sensors/sensor/voltage/state”

all sorted now Thank You once again

2 Likes

Great! I am glad I could help. We all are learning and it’s great to have a community to share our experiences/knowledge with other.

3 Likes

Thanks for this! Just waiting for my power shields and then I’ll build them!
Anyone tried adding a ds18b20 temp sensor to it? Just for the fun of it to get the interior car temp during winter to see if the heater is working :smiley:

1 Like

I had thought about that myself, but decided not to as I mounted all my units at within the engine bay to get a direct reading from the battery. My alarm keyfob also shows the internal temperature anyway, so I know its nice and warm/cold before getting in after a remote start.

Awsome, my old cars isn’t that fancy :joy:

I think I have some with 1.5m cables around here somewhere, will add one just for the fun of it. Should be fine to push through some grommet between the engine bay and the car. Will report back when it’s done!

Thanks for your code and advice.
Am I right that this is so the wemos d1 can wake up from deep sleep? (indeed mine with your ESPHome code goes to deep sleep but does not wake up)
Am I also right that it’s no longer possible to program the wemos d1 after that connection, at least not via USB?
Just want to double check before I solder the pins

Yes, that is so that the D1 Mini can wake up from deep sleep. I have two devices that use deep sleep and they have been working without any problem for at least 5 months. The D1 mini should wake up.

In order to upload any code OTA, you can stop deep sleep on the D1 Mini. See the deep_sleep.prevent and deep_sleep.enter below under the MQTT section.

esphome:
  name: ${devicename}
  platform: ESP8266
  board: d1_mini
deep_sleep:
  run_duration: 60s
  sleep_duration: 60min
  id: battery_deep_sleep

mqtt:
  broker: 192.168.XXXXXX
  username: !secret mqtt_username
  password: !secret mqtt_password
  
  birth_message:
    topic: battery_voltage/topic
    payload: online
  will_message:
    topic: battery_voltage/topic
    payload: offline
  
  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


I have an input boolean in HA. When I turn it off, it executes an automation and script to send an mqtt message to turn off deep sleep on my devices. The next time the D1 mini wakes up or if I reset it manually, it will not go to deep sleep.

deepsleepbutton

These are the automations:

##############################################################
# DEEP SLEEP FOR ESPHOME DEVICES
##############################################################
- id: TurnOffDeepSleepForOTA
  alias: Turn Off Deep Sleep For OTA
  trigger:
    platform: state
    entity_id: input_boolean.deep_sleep
    to: 'off'
  action:
    - service: script.turn_on
      entity_id: script.stop_deep_sleep_on_esphome_devices

##############################################################
- id: TurnOnDeepSleepForOTA
  alias: Turn On Deep Sleep For OTA
  trigger:
    platform: state
    entity_id: input_boolean.deep_sleep
    to: 'on'
  action:
    - service: script.turn_on
      entity_id: script.resume_deep_sleep_on_esphomedevices

These are the scripts:

####################################################################    
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

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

Of course, you could have them combined instead of separated in automations/scripts.

I would not solder anything until you have tested that everything is working.

I hope this helps.

3 Likes

Thanks a lot for the explanation and all details

1 Like

Will d1 mini run if i use one 1.5M ohm resistor instead of 1.44M ohm resistor one 1M ohm+220k ohm is it not 1,22MOhm?

The D1 mini has a built in 220k , so in total you’ll get 1M + 220k + 220k = 1.44M
I can’t see why it would not work, the idea of the 1.44 was that it would handle up to 16V input without burning the A0.

Thx did order som resistors whit 1m ohm and 220k ohm did not have so hi resitors home. Have 3 sensors 2 in cars and one in the caravan and it works perfect

Does anyone with better knowledge than me , know why after changing from my isp wifi and changing to unifi equipment (yet another rabbit hole) the D1s dont always connect to report the voltage. They worked 98% of the time before. I have created a 2.4 access point just from my Home automation, and used a new SSID, and re-flashed the D1s with the new details. When they do connect they have very good signal strength. One of my cars has not reported back now in 2 days? I am thinking it must be down to the unifi setup, but I have no issues with anything else (The D1s have static ip in the programming).