Hi everyone,
I’m not super familiar with ESPHome, this is actually my first time using it.
I am building a touch sensor wifi button that is battery operated. It features a USB Type C charging module and a lithium 3.7v battery.
The Wemos D1 Mini does nothing but send a mqtt message when it wakes up through the touch button and an phototransistor by grounding the RST pin. Thanks to one user’s help on the board, I managed to achieve this by programming the Wemos D1 Mini.
I would like the Wemos D1 Mini also to send a mqtt message with the battery percentage (ideally, but also the battery voltage would be fine).
I have seen a guide online that connects the following voltage detector to one pin of the Wemos D1 Mini, but I have no idea how to program ESPHome to detect the voltage and convert it to a battery percentage.
Could someone help me, please?
I will make a post with the finished project once it is completed and the case 3D printed.
It looks like I’m stalking you. Try adding this to esphome yaml. It will send the voltage as an MQTT. You may have to measure the voltage with an external meter and change that multiply factor to suit your needs. ( with esp12f I need to use a voltage divider as 3v would burn out the A0 pin. change anything else to suit your needs. I started with wemos D1 but it uses too much battery so I moved over to esp12f. My device )is outside so I charge it by small solar panel.
I created the battery % in yaml in HA as I had to adjust it a lot at start to get it accurate and didn’t want to keep flashing the ESP as I have to take it out of deep sleep and go to OTA mode. The 2.64 was the lowest voltage the esp could work at. It’s a start. You’ll work it out.
@Spiro when I will post the completed project, you’ll be for sure in the “thank you list”.
Any idea on how to calculate the multiplier based on the voltage sensor I’m using? I don’t really get how it works to be honest…
I use this voltage divider calculator to get roughly the right resistors so I don’t damage the A0 pin. I see what voltage then the esp sends out and I measure with a multimeter across the battery terminal. So if esp says 1 volt and I measure it at 4.2v the factor is 4.2. If you don’t have a multimeter then you just charge battery until it’s fully charged and assume it 4.2V. I think the D1 may be able to measure up to 3v due to internal resistor but not sure. I not an electrical engineer but I think the larger the resistors you use for the devider the less of the battery power gets used up by your measuring. If too big a resistance then tiny disturbances in the circuit currents will have big impacts on accuracy.
Vmax is the maximum that you want to measure.
Vesp for the 8266 is 1 Volt.
X kOhm would be the single resistor that you simply put in front of the ADC input of the D1 mini without any additional voltage divider resistors.
Example für 5 Volt max voltage: X kOhm
= (5 Volt * 100 kOhm) / 1 Volt - 100 k Ohm - 220 kOhm
= 500 kOhm - 100 kOhm - 220 kOhm = 180 kOhm
Example für 10 Volt max voltage: X kOhm
= (10 Volt * 100 kOhm) / 1 Volt - 100 k Ohm - 220 kOhm
= 1000 kOhm - 100 kOhm - 220 kOhm = 680 kOhm
Sorry guys, I know it wasn’t in the original question, but I can’t get my head around on how to send the mqtt message with the voltage measured by pin A0 when the wemos wakes up…