{"id":552,"date":"2023-12-09T20:27:02","date_gmt":"2023-12-10T04:27:02","guid":{"rendered":"https:\/\/www.cafeelectric.com\/blog\/?p=552"},"modified":"2025-01-22T17:45:12","modified_gmt":"2025-01-23T01:45:12","slug":"let-batteries-live-longer","status":"publish","type":"post","link":"https:\/\/www.cafeelectric.com\/blog\/2023\/12\/09\/let-batteries-live-longer\/","title":{"rendered":"Let Batteries Live Longer &#8211; Sonoff S31 with Tasmota for charge limiting"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Key Points before I get into it:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This post includes instructions to hack a low cost (&lt;$10) Sonoff S31 device enabling the S31 to turn off battery chargers before the battery reaches full charge.<\/li>\n\n\n\n<li>USB powered devices are simpler to charge limit using a <a href=\"https:\/\/chargie.org\/\">Chargie<\/a>. Some devices, like Tesla EVs, some phones and other devices have charge limiting built in.<\/li>\n\n\n\n<li>If your device uses a LFP (lithium iron phosphate) battery, then full charge has much less detrimental effect on lifetime and so this may not be needed.<\/li>\n\n\n\n<li>The S31 mod requires potential soldering and some code loading. It may be an adventure for a beginner in electronics. <\/li>\n\n\n\n<li>Once the S31 is programmed, it works stand-alone with no WiFi connection needed. The button on the side turns it on and the programmed script will turn it off again.<\/li>\n\n\n\n<li>In addition to a computer, you will need a <a href=\"https:\/\/amzn.to\/48PM83z\">Sonoff<\/a><a href=\"https:\/\/amzn.to\/4afaYdq\"> S31<\/a>, not the Lite version, and a 3.3V USB to TTL serial converter as well as some way to connect the serial converter to the board like wires and solder. I used an obsolete LilyPad FTDI TTL converter since I had one, a newer versions seems to be the <a href=\"https:\/\/amzn.to\/3RubXh0\">Beefy 3<\/a>. I hear that unlike some converters the <a href=\"https:\/\/amzn.to\/3RAsHVi\">DSD TECH SH-U09C2<\/a> also works well.<\/li>\n\n\n\n<li>Although the modification and programming process is a bit tedious, I get great satisfaction from the empowerment of being able to overcome the planned obsolescence of the batteries things that I own. <\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Why:<\/h2>\n\n\n\n<p>Lithium batteries have shorter lifetimes when stored hot and at high state of charge. I like to optimize the life of batteries in my computers, phones, power tools and other devices by limiting the how fully they are charged most of the time since I rarely need full capacity. Tesla is known for making lithium batteries last a very long time. You can see below that the car allows setting the charge limit, and that 80% is the suggested maximum unless needed for longer trips. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2211-1024x768.jpeg\" alt=\"\" class=\"wp-image-563\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2211-1024x768.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2211-300x225.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2211-768x576.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2211.jpeg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Unfortunately, most devices don&#8217;t give an option for limiting charge level, and fully charged batteries are slowly destroying themselves much faster than necessary. Sometimes it&#8217;s possible to unplug a device charger before the battery is fully charged and it would be nice to automate that. That&#8217;s what we are accomplishing here. <\/p>\n\n\n\n<p>For my cell phone and many USB charged devices, the <a href=\"https:\/\/chargie.org\/\">Chargie<\/a> is an option I use. From Chargie: &#8220;The Chargie app normally runs on your smartphone, but now you can limit the charging of any kind of lithium ion battery, or of a phone that\u2019s been shut off. It will cut power at about 90%, based on power measurements done automatically and continually by Chargie\u2019s hardware.&#8221; <\/p>\n\n\n\n<p>That still leaves a lot of devices that are not USB powered. Electric bikes, laptops, power tools and even the ride on mower all charge on a 120V plug. I have not seen a commercial device for controlling those.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2209.jpeg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" data-id=\"560\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2209-1024x768.jpeg\" alt=\"\" class=\"wp-image-560\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2209-1024x768.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2209-300x225.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2209-768x576.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2209.jpeg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2202.jpeg\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" data-id=\"558\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2202-1024x768.jpeg\" alt=\"\" class=\"wp-image-558\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2202-1024x768.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2202-300x225.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2202-768x576.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2202.jpeg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Recently, my good friend <a href=\"https:\/\/www.linkedin.com\/in\/hai-yue-han-9a403014\/\">Hai-Yue Han<\/a> shared that he was modifying the <a href=\"https:\/\/amzn.to\/48PM83z\">Sonoff S31<\/a> to do charge limiting. Fortunately for us all he has already done the work of compiling a special version of the Tasmota firmware that can handle the scripts. This allows us to write custom scripts tailored to individual devices that turn off the chargers before the battery is full.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"644\" height=\"523\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/DualSonoffS31.jpeg\" alt=\"\" class=\"wp-image-577\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/DualSonoffS31.jpeg 644w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/DualSonoffS31-300x244.jpeg 300w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/figure>\n\n\n\n<p>The <a href=\"https:\/\/amzn.to\/48PM83z\">Sonoff S31<\/a> is a wonderful Wifi Smart Socket that can monitor power consumption. It comes with factory firmware that I found unusable. Fortunately Tasmota offers open source firmware for ESP devices and has a console that allows loading custom code called Rules to control the output using various parameters. <br>A quick test with a Kill-A-Watt (The Sonoff doesn&#8217;t measure low enough values) indicates that the Sonoff draws 0.7W to 0.9W when the relay is on, and less than 0.5W when the relay is off with much variability in time. <br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"1024\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_1299-768x1024.jpeg\" alt=\"\" class=\"wp-image-555\" style=\"width:819px;height:auto\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_1299-768x1024.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_1299-225x300.jpeg 225w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_1299.jpeg 960w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>I temporarily soldered on pins and a wire to program my first units. A programming clip described below eliminates the need to solder at all and makes programming multiple units much easier. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How:<\/h2>\n\n\n\n<p>Here&#8217;s an overview of the process. Please review all the notes below this list before starting. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Review overview of process and safety concerns<\/li>\n\n\n\n<li>Flash firmware<\/li>\n\n\n\n<li>Configure the module<\/li>\n\n\n\n<li>Analyze battery charge profile<\/li>\n\n\n\n<li>Modify a script for your use<\/li>\n\n\n\n<li>Load script<\/li>\n\n\n\n<li>Test functionality<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Review Overview:<\/h3>\n\n\n\n<p>We will be doing the flashing differently than usual, but before we start Tasmota has a page on the S31 that is worth reviewing. It has important safety notes and links to the video below as well as other resources. <br><a href=\"https:\/\/tasmota.github.io\/docs\/devices\/Sonoff-S31\/\">https:\/\/tasmota.github.io\/docs\/devices\/Sonoff-S31\/<\/a><\/p>\n\n\n\n<p>The first 6 minutes of the video below do a great job of covering how to open up the unit and connect the FTDI USB to serial adaptor. Once the unit is flashed with the new code, the wires can be removed and the case reassembled before plugging it in.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-embed-handler wp-block-embed-embed-handler wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"nv-iframe-embed\"><span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe loading=\"lazy\" class=\"youtube-player\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/IvfiLcHMekQ?si=dypDSZteKZlvOa3k&#038;version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en-US&#038;autohide=2&#038;wmode=transparent\" allowfullscreen=\"true\" style=\"border:0;\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox\"><\/iframe><\/span><\/div>\n<\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Flash Firmware:<\/h3>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccb03d&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccb03d\" class=\"wp-block-image size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"623\" height=\"760\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"603\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Screen-Shot-2023-12-15-at-11.22.38-AM.png\" alt=\"\" class=\"wp-image-603\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Screen-Shot-2023-12-15-at-11.22.38-AM.png 623w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Screen-Shot-2023-12-15-at-11.22.38-AM-246x300.png 246w\" sizes=\"auto, (max-width: 623px) 100vw, 623px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccb239&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccb239\" class=\"wp-block-image size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"841\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"604\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Screen-Shot-2023-12-15-at-11.22.56-AM.png\" alt=\"\" class=\"wp-image-604\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Screen-Shot-2023-12-15-at-11.22.56-AM.png 745w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Screen-Shot-2023-12-15-at-11.22.56-AM-266x300.png 266w\" sizes=\"auto, (max-width: 745px) 100vw, 745px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/figure>\n\n\n\n<p>The standard Tasmota build is not capable of the functions we need and therefore my process for loading the new Tasmota firmware in the S31 is a bit different than shown in the video above. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First you&#8217;ll need to unzip this binary file my friend Hai-Yue Han compiled. It enables the more complex programming: <a href=\"http:\/\/cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/tasmota.bin_.zip\">tasmota.bin<\/a><\/li>\n\n\n\n<li>Open up the S31 and solder wires connecting the USB to TTL converter to the board inside. Or use the clip setup shown below.<\/li>\n\n\n\n<li>Warning: Do not plug the unit into AC when the cover is off! Programming power for the device comes from the USB to TTL adaptor connection.<\/li>\n\n\n\n<li>Insure your computer has the proper drivers installed to run your USB TTL converter. <\/li>\n\n\n\n<li>Unlike what the video shows, go to <a href=\"https:\/\/jason2866.github.io\/WebSerial_ESPTool\/\">https:\/\/jason2866.github.io\/WebSerial_ESPTool\/<\/a>  It&#8217;s important to press and hold the reset button as you plug in the USB. Hold the button until after it has connected indicated by the GUI changing to allow for file upload.<\/li>\n\n\n\n<li>Erase the chip<\/li>\n\n\n\n<li>Flash the unzipped <a href=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/tasmota.bin_.zip\">tasmota<\/a><a href=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/tasmota.bin.zip\">.bin<\/a> with offset of 0x0 and baud rate of 115200.<\/li>\n\n\n\n<li>After programming the GUI should say: &#8220;To run the new firmware, please reset your device.&#8221;<\/li>\n\n\n\n<li>Reset the S31 by cycling power on the USB. Or, go ahead and remove the TTL adaptor, reassemble the protective cover and plug it into 120V. <\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Optional Programming Clip:<\/h4>\n\n\n\n<p>A friend shared this <a href=\"https:\/\/amzn.to\/3AJTOY1\">programming clip available from Amazon<\/a>. It&#8217;s a simple solution for avoiding soldering and desoldering the USB to TTL converter to each part. You will still need one of the converters listed in the first section of this blog. <\/p>\n\n\n\n<p><a href=\"https:\/\/amzn.to\/3AJTOY1\"><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"161\" class=\"wp-image-803\" style=\"width: 150px;\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/51RIMD8A8GL._AC_SL1000_.jpg\" alt=\"Programming adaptor\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/51RIMD8A8GL._AC_SL1000_.jpg 602w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/51RIMD8A8GL._AC_SL1000_-280x300.jpg 280w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><br><br>Before I knew about the above part, I made mine as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccb669&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccb669\" class=\"wp-block-image size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"610\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2247-1024x768.jpeg\" alt=\"\" class=\"wp-image-610\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2247-1024x768.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2247-300x225.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2247-768x576.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2247-1536x1152.jpeg 1536w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2247-2048x1536.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccb7a4&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccb7a4\" class=\"wp-block-image size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"609\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2248-1024x768.jpeg\" alt=\"\" class=\"wp-image-609\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2248-1024x768.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2248-300x225.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2248-768x576.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2248-1536x1152.jpeg 1536w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2248-2048x1536.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccb8ce&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccb8ce\" class=\"wp-block-image size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"611\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2249-1024x768.jpeg\" alt=\"\" class=\"wp-image-611\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2249-1024x768.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2249-300x225.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2249-768x576.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2249-1536x1152.jpeg 1536w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2249-2048x1536.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccbbb6&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccbbb6\" class=\"wp-block-image size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"999\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"617\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2251-1-1024x999.jpeg\" alt=\"\" class=\"wp-image-617\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2251-1-1024x999.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2251-1-300x293.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2251-1-768x749.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2251-1.jpeg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccbcde&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccbcde\" class=\"wp-block-image size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"785\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"616\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2252-1-1024x785.jpeg\" alt=\"\" class=\"wp-image-616\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2252-1-1024x785.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2252-1-300x230.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2252-1-768x589.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2252-1.jpeg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccbe6a&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccbe6a\" class=\"wp-block-image size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"615\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2260-1024x768.jpeg\" alt=\"\" class=\"wp-image-615\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2260-1024x768.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2260-300x225.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2260-768x576.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2260.jpeg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/figure>\n\n\n\n<p>This 3D printable tool plus some pogo pins is handy for programming a bunch of them. It has very small pogo pin holes that I drilled out with a #55 drill in order to use larger 1.5mm pogo pins. You&#8217;ll have to print your own clip or like me find someone to print one for you. <br><a href=\"https:\/\/www.stlfinder.com\/model\/pogo-pin-programming-clip-for-sonoff-s31-modules-EBKP2Nhz\/2282906\/\">Pogo-pin-programming-clip<\/a> file on thingiverse.<\/p>\n\n\n\n<p>I had pogo pins and sleeves left over from long ago, these may not be easily available parts. The four contact probes are a &#8220;headless spear&#8221; <a href=\"https:\/\/www.mouser.com\/ProductDetail\/Smiths-Interconnect-IDI\/S-100-B-8-G?qs=rgGO2PQ3oWGYxIIDX39X8g%3D%3D\">PN S-100-B-8-G<\/a> which allows them to be tightly pressed into the plastic after it has been drilled with a #55 drill bit (0.052&#8243; diameter.) The short space available on this clip design doesn&#8217;t allow for pressing in the sockets, so I slide them over the end of the probes after they are in the plastic. I used three square pin sockets<a href=\"https:\/\/www.testequity.com\/product\/QA-100-SDG250W-100-SDG250W\"> PN SDG250W<\/a>, and a solder cup socket for the ground wire (no PN available.) <br>If your USB to TTL converter has a similar pinout to mine, like this <a href=\"https:\/\/amzn.to\/3RubXh0\">SparkFun Beefy 3<\/a>, then you can slide it directly onto the three square pin sockets and only have to add a ground wire, as shown in the pictures above. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configure the module:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Power up the S31 without holding reset button. Log into a Wifi access point named Tasmota. Eventually an automatic &#8220;login&#8221; page (captive portal) pops up for wifi configuration. The captive portal that pops up on the iPhone has a bug in that it won&#8217;t let me paste into the password field, expecting me to try to type in my complex wifi password I guess. If your password is complex it may be better to perform configuration on a desktop machine.<br>Select your local WiFi Network, enter the password and watch for and remember the IP address that it shows before the page vanishes. <\/li>\n\n\n\n<li>Switch your computer WiFi back to your own local access point. <\/li>\n\n\n\n<li>Navigate to the noted IP address in a browser and navigate into the configuration menu.<\/li>\n\n\n\n<li>Configure Module in the Configuration menu to a S31 and save, device will restart. <\/li>\n\n\n\n<li>I like to configure the WiFi by adding a Hostname of S31-1, S31-2 etc so I don&#8217;t have to remember the IP address. I found that underscores didn&#8217;t work properly, so don&#8217;t do S31_1. The ability for hostnames to work may depend on your local router configuration. Configuring routers is beyond the scope of this document.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-4 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccc0e5&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccc0e5\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"408\" height=\"388\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"562\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/ModuleType.png\" alt=\"\" class=\"wp-image-562\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/ModuleType.png 408w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/ModuleType-300x285.png 300w\" sizes=\"auto, (max-width: 408px) 100vw, 408px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccc238&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccc238\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"862\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"557\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Wifi-Setup.png\" alt=\"\" class=\"wp-image-557\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Wifi-Setup.png 586w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Wifi-Setup-204x300.png 204w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Analyze charge profile:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>At this time you should be able to manually control the output switch and view the power parameters as in the image below. <\/li>\n\n\n\n<li>Plug in the device that you want to make a profile for. <\/li>\n\n\n\n<li>I find it helpful to make a screen video recording of a full charge cycle using my target battery and charger so I can go back and review the charge session quickly figuring out what power levels coincide to a 80% to 90% state of charge. Subtracting the starting from ending values for &#8216;Energy Total&#8217; gives the battery capacity minus losses. Finding a time in the screen recording that&#8217;s 80% of that value is a good place to look for trends in power draw changing. Some chargers with constant current outputs will slowly increase the AC power draw as the battery voltage increases, while others may run at constant power until almost full and then taper off.  An important point when using the scripts below is to see if the power is rising or falling, and what numerical power level represents a good cutoff point. <\/li>\n\n\n\n<li>On my Bauer 20V power tool batteries the &#8220;Fast&#8221; charger power jumped around a lot, making it difficult to make an algorithm to fit. Fortunately the &#8220;Rapid&#8221; (Slow) and &#8220;Dual Port&#8221; (Fastest) chargers behaved better. <\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"474\" height=\"1024\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2203-474x1024.jpeg\" alt=\"\" class=\"wp-image-559\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2203-474x1024.jpeg 474w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2203-139x300.jpeg 139w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_2203.jpeg 592w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Modify the script:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Tasmota has a scripting language called Rules. Rules don&#8217;t seem to allow comments, so I&#8217;ll show an example script for an Ebike below with translations:<\/li>\n\n\n\n<li>Ebike rule: \u2028<br>Rule1<br>ON system#boot DO var1 0 ENDON<br>ON ENERGY#Current==0.0 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK<br>ON ENERGY#Current&gt;=1.4 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK<br>ON ENERGY#Current&lt;1.4 DO if (var1!=1) RuleTimer1 30; var1 1 endif ENDON<br>ON Rules#Timer=1 DO Power1 OFF ENDON<\/li>\n\n\n\n<li>This script turns off the outlet when current is not 0 and continuously under 1.4 Amps for 30 seconds. It uses the variable var1 and RuleTimer1. My comments for each line follow:<br><br>Reset at boot var1 to 0. 1 indicates the timer is in countdown mode<br>if current is 0, it clears the countdown and resets timer to 0, don\u2019t continue<br>if current is over 1.4, it clears the countdown and resets timer to 0, don\u2019t continue<br>If current below 1.4 and countdown has not started, start countdown and set timer to 30<br>If timer drops to 1, turn off outlet.<\/li>\n\n\n\n<li>The script can easily be changed to trigger on higher than a value instead of lower than by swapping the  &lt; &gt; symbols in lines 3 and 4. <\/li>\n\n\n\n<li>I&#8217;m now using ENERGY#Power as a determining variable instead of ENERGY#Current since I figure it won&#8217;t change so much when the line voltage changes.<\/li>\n\n\n\n<li>The adjustability of this method is pretty coarse on some devices, but it seems to be relatively repeatable, though I&#8217;d be sure to recheck function when using a script on a new device that may have different calibration. <\/li>\n\n\n\n<li>I will post more sample scripts (Rules) further below. <\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default wp-block-gallery-5 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a2d6e0ccc687&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a2d6e0ccc687\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"559\" height=\"639\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" data-id=\"569\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Console2.png\" alt=\"\" class=\"wp-image-569\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Console2.png 559w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/Console2-262x300.png 262w\" sizes=\"auto, (max-width: 559px) 100vw, 559px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Example of the Console window, near the bottom I sent the command to turn off Rule1<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Load script:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Rules are loaded, turned on and monitored in the Console. I&#8217;m only using Rule1 of three available ones. <\/li>\n\n\n\n<li>In order to load a Rule it is only necessary to paste the rule into the console command area starting with Rule1&#8230; it&#8217;s ok to paste in a Rule with line feeds. Use the return key to enter the command or Rule. <\/li>\n\n\n\n<li>Pasting in a new Rule1 overwrites the old one. <\/li>\n\n\n\n<li>Once Rule1 is entered, it should be turned on with the command: Rule1 ON<\/li>\n\n\n\n<li>Rules can be disabled with the command: Rule1 OFF<\/li>\n\n\n\n<li>Once a Rule is loaded and running, the console will show lines being run about every 3 seconds.<\/li>\n\n\n\n<li>Rules and settings stay in memory through power cycles. Once you have a working system there is no need to connect to the unit to WiFi unless you want to monitor or change something. <\/li>\n\n\n\n<li>Usage is as simple as pushing the button on the side to turn on the output and the Rule will turn it off when conditions are met. <\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Test functionality:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Once you have a Rule running, all that&#8217;s left is to insure that it is doing what you want.<\/li>\n\n\n\n<li>On laptops, or devices with state of charge displays it&#8217;s easy to see how full they got before shutting off. <\/li>\n\n\n\n<li>For other devices like power tool batteries I measure the terminal voltage and divide it by the number of cells to estimate how full they are. Generally I like to see 3.8V to a maximum of 4V per cell. Some batteries need to be in the tool to turn on and allow a Voltage reading and for those I go by the Watt Hours charged since empty. <\/li>\n\n\n\n<li>Caution: Watching batteries charge is a very tedious thing! <\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-1 wp-block-gallery-6 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"797\" data-id=\"578\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerSwitchOff-1024x797.png\" alt=\"\" class=\"wp-image-578\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerSwitchOff-1024x797.png 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerSwitchOff-300x234.png 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerSwitchOff-768x598.png 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerSwitchOff.png 1166w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" data-id=\"575\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerV-1024x768.jpeg\" alt=\"\" class=\"wp-image-575\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerV-1024x768.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerV-300x225.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerV-768x576.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerV.jpeg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" data-id=\"573\" src=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerSetup-1024x768.jpeg\" alt=\"\" class=\"wp-image-573\" srcset=\"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerSetup-1024x768.jpeg 1024w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerSetup-300x225.jpeg 300w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerSetup-768x576.jpeg 768w, https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/BauerSetup.jpeg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>The above screen shot shows the console just after the device shut off the Bauer 20V battery charger for being at or over 44 Watts for 30 seconds. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Rules:<\/h2>\n\n\n\n<p>Here are my notes followed by the rules that can be used as-is or serve as examples for further modification or testing.<\/p>\n\n\n\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<br>Ryobi 40V rule: For http:\/\/s31-1\/<br>Current&lt;0.800 charged almost to full. Taper is right at the last few wH. Want to try cutting off when over 84W since Wattage climbs as voltage rises. Once full, with SOC lights off and green light solid, charger seems to be equalizing cells, toggling between about 5W and 30W (dropping over time) with reducing duty cycle. Over 84W cutoff seemed to cut it off too early. Recorded video of full charge (Only used 83 Wh) and 90% seems to be when Power is at 60W or below. Wait until Watts drops to below 61W for 30 seconds to shut off. The following code seems to be shutting off correctly. \u2028<br><br>Rule1 <br>ON system#boot DO var1 0 ENDON ON ENERGY#Current==0.0 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK <br>ON ENERGY#Power&gt;=61 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK<br>ON ENERGY#Power&lt;61 DO if (var1!=1) RuleTimer1 30; var1 1 endif ENDON<br>ON Rules#Timer=1 DO Power1 OFF ENDON<\/p>\n\n\n\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<br>Bauer 20V Rule, use on black topped Rapid Charger.<br>Fast charger current draw is too variable to be easy.<br>Charge on slower \u201crapid\u201d charger and record. 10\/10\/23<br>Starts at 36W, climbs as charge progresses, wattage is smooth. \u2028108 Wh AC charge in<br>80% would be 86 Wh,<br>Limit should be set to stop at or above 45 watts for 30 seconds.<br>Voltage after charge to 45W limit is 20.298 average 4.06V per cell.<br>Voltage after charge to 44W limit is 19.8V average 3.96V per cell.<\/p>\n\n\n\n<p>Rule1<br>ON system#boot DO var1 0 ENDON<br>ON ENERGY#Current==0.0 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK<br>ON ENERGY#Power&lt;44 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK <br>ON ENERGY#Power&gt;=44 DO if (var1!=1) RuleTimer1 30; var1 1 endif ENDON<br>ON Rules#Timer=1 DO Power1 OFF ENDON<\/p>\n\n\n\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<br>Bauer 20V Dual Fast Charger, 4A each<br>Plan to only limit charge when one is charging, and keep running if 2 batteries are in.<br>1W standby. .2 pf<br>84-86W starting with new shipped battery.<br>133W .65pf two batteries (one cold that draws 50W on its own)<br>Wattage rises as it charges to 93, after which it rapidly tapers off with 9Wh left to charge, so when it hits 90W that seems like a good shut off, but if it\u2019s over 95W keep charging since that would be 2 batteries.<br>The second line in this Rule uses ENERGY#Power&lt;3 to indicate no battery present since the idle consumption of this charger is high. <\/p>\n\n\n\n<p>Rule1<br>ON system#boot DO var1 0 ENDON<br>ON ENERGY#Power&lt;3 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK <br>ON ENERGY#Power&gt;100 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK<br>ON ENERGY#Power&lt;90 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK <br>ON ENERGY#Power&gt;=90 DO if (var1!=1) RuleTimer1 30; var1 1 endif ENDON<br>ON Rules#Timer=1 DO Power1 OFF ENDON<\/p>\n\n\n\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<br>Macbook Pro, this rule only works for charging when sleeping. During use it will not limit charge level. <br>At 78% SOC power dropped to 22W, goes higher and stays there a while when woken up.<br>Drops to 21W and then rapidly drops at about 90%, try that cutoff.<br>Tested at 65% SOC, Charged to 78% and turned off. Seems close enough for me.<br>22W gave 75%, Lets try 21W.<br>21W gave a perfect 89% SOC starting in the 60\u2019s. Looks good.<\/p>\n\n\n\n<p>Rule1<br>ON system#boot DO var1 0 ENDON<br>ON ENERGY#Current==0.0 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK<br>ON ENERGY#Power&gt;21 DO if (var1!=0) RuleTimer1 0; var1 0 endif BREAK<br>ON ENERGY#Power&lt;=21 DO if (var1!=1) RuleTimer1 30; var1 1 endif ENDON<br>ON Rules#Timer=1 DO Power1 OFF ENDON<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">END:<\/h2>\n\n\n\n<p>Thanks for reading, I hope you find fun in this project. <br>Please comment with issues\/corrections that you notice and let me know if it worked for you. <br>-Otmar<\/p>\n\n\n\n<p>Last edited and updated on 11\/16\/2024<\/p>\n\n\n\n<p>This site contains paid links, by buying through these links I may receive a commission for the sale. This has no effect on the price for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The post provides a detailed guide on how to modify a Sonoff S31 device to limit battery charging and extend the lifespan of lithium batteries commonly used in devices like phones, laptops, and tools. This DIY hack requires some soldering and code loading: it automates the turning off of device chargers before the battery reaches full charge. The modified S31 works independently and does not require a WiFi connection. The post also includes specific scripts for various devices and comprehensive steps for loading and testing these scripts.<\/p>\n","protected":false},"author":1,"featured_media":556,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[38,34,35,36,33,37],"class_list":["post-552","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hacks-fixes-and-upgrades","tag-120v","tag-battery-life","tag-charge-limiting","tag-hacking","tag-sonoff-s31","tag-tasmota"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.cafeelectric.com\/blog\/wp-content\/uploads\/2023\/12\/IMG_1305.jpeg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paSKPd-8U","_links":{"self":[{"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/posts\/552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/comments?post=552"}],"version-history":[{"count":42,"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/posts\/552\/revisions"}],"predecessor-version":[{"id":875,"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/posts\/552\/revisions\/875"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/media\/556"}],"wp:attachment":[{"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/media?parent=552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/categories?post=552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cafeelectric.com\/blog\/wp-json\/wp\/v2\/tags?post=552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}