Battery level monitor

Hi everyone!

I’m new into the esphome/HA-thing, but I’m totally in it after a few days :smiley:

I want to build multiple sensors and automations for my home and want to doi on my own, without buying expensive plug&play stuff (ok some of these things are quite practical :D)

I managed to build an easy PIRmotion sensor using an esp8266 wemos D1 mini and managed to automate, that it turning a light and sends me a notification via WhatsApp and HA-App.
It was not difficult, because I used mostly things, I copies from the internet.
But now a want to power the sensor with a Lipo battery. I ordered a battery shield to recharge the battery, but I have no clue, how to monitor the remaining battery level from Home assistant.

This is my esphome code:

ˋesphome:
name: pir-sensor-1
friendly_name: PIR-Sensor-1

esp8266:
board: esp01_1m

Enable logging

logger:

Enable Home Assistant API

api:
encryption:
Key:“xxxxxxxxxxxxxx"

ota:
password: “xxxxxxxxxxxxxx”

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: “Pir-Sensor-1 Fallback Hotspot”
password: “xxxxxxxxxxxxxx”

captive_portal:

binary_sensor:

  • platform: gpio
    pin: 13
    name: “PIR Sensor”
    device_class: motionˋ

Is there a way, to include a sensor for the battery level or something?

Thanks for your answers
Bye Toni

Sorry for this crazy text format. I hope you can read it anyways

For batteries, I would certainly advise that you get a charger / system that can handle this for you, and talk to that. Batteries can be a bit finicky, and chargers are not something I would encourage DIY. Easy way to start a fire.

That being said, if you’re just trying to measure battery level, voltage is a fairly safe method, but be aware that adding anything to your battery can be a risk, and may drain it more than not having monitoring. The easy way is to measure voltage and compare against expected. A 2.4V battery may measure 2.46 at full, and 2.12 at empty, for example. Then you’d just have a linear regression from 100% at 2.46 and 0% at 2.12. Most typically, you’d set 0% to somewhere above the “limit” so as to protect your battery from discharging too much.

Hey. Thanks for the answer. What chargers do you recommend and how do I add the code for monitoring? There is no entity for the sensors battery or something listed in HA

That showcases a fairly easy walkthrough of how you could use a battery to power ESP Home devices. Seems reasonable, and you’d probably just swap out new batteries, and/or charge them separately. Keeps any battery charging separate.

Then for measuring voltage the ESP 8266 has an ADC Pin you can use:

Just need a voltage transducer or transformer to reduce the voltage range from 0-4.xV of the battery, to 0-1v. You could use a simple voltage divider circuit to divide by 5, and you’d be safe. Just depends on the accuracy of the ADC. I’m sure you can google an answer to how to measure higher voltages on this pin. You’ll want some diodes, capacitors, resistors, etc. Best to find an example from someone unless you have small circuit knowledge.

1 Like

Welcome @Toni4 . Please take a look at this forum rule for how to format your code properly.

Quite a few people who would otherwise offer support will skip over posts if they aren’t formatted so they are easy to read.

Cheers.

2 Likes

I’m using this blueprint:

Oh ya! I can tell when someone has the esphome itch… You’re hooked now. I know someone already mentioned it but, messing with Li ion especially is quite risky if you don’t understand how to charge and care for them properly. Many people have not taken the warning seriously or they didn’t bother learning first and they burnt their homes down. Dealing with batteries is 100% doable but you need to know what your dealing with.