20221212: Tapo Users, update from reader Roman below: The Tapo app on Android now has a software/firmware update that lets you reset the energy consumption from the app. Hopefully, iOS is the same.
20220914: Note: If you have an Apple device, you no longer have to use my laborious procedure documented below. The Watt for Smart Devices app can reset the energy and usage stats of both Kasa and Tapo devices.
WARNING: This method DOES NOT work the Tapo devices. They use an entirely different API. I wrote some code to try sending reset_energy_usage to a Tapo plug, but it rejected the command. If anyone knows the command to reset the energy usage of a Tapo, please leave a message below. Also, I might be able to find the correct command if someone can send me a firmware file for a Tapo plug with energy monitoring.
I recently acquired a few TP-Link Kasa KP115 smart plugs with energy metering. It was a bit disappointing to find that they barely show any data. There are no graphs, no voltage or current, just instantaneous power and summary energy stats and runtime:
I wanted to find the daily energy consumption of various appliances, so I needed a way to reset the energy counter to zero. Believe it or not, TP-Link doesn’t provide a way to reset the energy. TP-Link support says that you have to delete the plug from Kasa, factory reset, and then add it back to Kasa.
The most ridiculous part is, the smart plugs actually have a command to reset the energy without resetting the whole device! They’re just too lazy to add it to their app!
I found a github repo with a list of the commands available in the TP-Link protocol. It turns out that there’s a command to reset the energy monitor!
Erase All EMeter Statistics
{"emeter":{"erase_emeter_stat":null}}
The repo contains a Python3 script that can query the energy stats, but it doesn’t have an option to send the emeter reset command. Fortunately, it has a command line option to send an arbitrary JSON command to the plug. I tried sending the above to my KP115, and the energy meter was instantly reset to 0!
# python3 ./tplink-smartplug.py -t <ipaddr> -j {\"emeter\":{\"erase_emeter_stat\":{}}}
Although I don’t have one, the same command should also work on the older HS110 smart plug.
For your convenience, I have forked the github repo, and added a command to reset the emeter, so you don’t have to type the ugly JSON command.
Here’s how to reset your energy meter:
- Download and install Python 3.x: Python Downloads
- Download tplink_smartplug.py
- Next you need to know the IP address of the smart plug you want to reset. If you don’t know how to find it from your WiFi router, you can scan for it with an IP scanner, such as Fing. Look for a device named KP115 (or HS110).
- open up a command shell and type:
python3 ./tplink_smartplug.py -t <ipaddr> -c energy_reset
substituting the IP address of your smart plug for “<ipaddr>.”
Example:
# python3 ./tplink_smartplug.py -t 192.168.1.36 -c energy_reset
Sent: {"emeter":{"erase_emeter_stat":{}}}
Received: {"emeter":{"erase_emeter_stat":{"err_code":0}}}
The Python script returns “err_code: 0” if it’s successful. Next, open up your Kasa app, and check to see if the energy meter was reset successfully.
To erase runtime statistics, use runtime_reset instead of energy_reset.
Just got a KP115 and this is totally what I needed. Thanks for writing this up!
cool glad you found it useful. i was really pissed when TP-Link wanted me to do a factory reset every time!
It worked! Thank you for sharing this.
Doesn’t work for me.
I get “Received: {}” but the plug data doesn’t reset π
Which model/hardware version/firmware version did you try it on?
Just tried this on KP115 (hardware1.0 / firmware 1.0.16) and got the same results
I have updated the post above. It turns out that you need to escape the ” characters or Python3 will strip them out.
To make things easier, I added an energy_reset command to tplink_smartplug.py. Please download the new version, and follow the revised instructions above.
Thanks. It worked as advertised.
Thank you, works now
Many thanks for this. Absolutely incredible that this isn’t included in the app among other things.
These work well in HomeAssistant too, which will then get you the cumulative kWh usage (as well as watts, volts, amps and on/off control) to graph in daily chunks, without having to reset the plug
thanks. yes, i’m familiar with HA. But I wanted to use the plug to measure the exact energy usage of the plug over a specific time interval. it’s a lot easier to just reset the plug than to go digging through graphs and data logs. I’m actually using Prometheus/Grafana rather than HA to log the data
Do you think it could work on a TP-link Tapo p110 ?
(i could try …)
It might, if it has energy metering built in. Doesn’t hurt to try.
It does not seem to work with the P110 .i get no answer at all,no error …nothing!
i don’t much about python but i made sure the script was in the working directory and that the ip was correct but despite this …zilch !
That’s too bad. I wonder if it just doesn’t respond to the emeter command, or is it rejecting the whole API. Can you try one of the other commands from https://github.com/softScheck/tplink-smartplug/blob/master/tplink-smarthome-commands.txt ?
Just thank you. Very useful!
I have installed Python, downloaded the tplink_smartplug.py to the python folder but when typing the command (python3 ./tplink_smartplug.py -t -c energy_reset) into a command shell window I get invalid syntax at the start of the ./tplink_smartplug.py (the error indicator is under the /) was replaced with IP address. Anyone any ideas what I’m doing wrong?
can you send me the exact command line you’re typing and the full response?
i seem to have the same issue – see below:
Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> python3 ./tplink_smartplug.py -t 192.168.215 -c energy_reset
File “”, line 1
python3 ./tplink_smartplug.py -t 192.168.215 -c energy_reset
^
SyntaxError: invalid syntax
>>>
The problem is that you’re invoking Python, and then trying to typing the command line into Python.
What we want to do is to have Python execute the script. So want to type the line
python3 ./tplink_smartplug.py -t 192.168.215 -c energy_reset
in the Windows Command Prompt or Powershell. Don’t type python first.
Sorry for not replying to my issue earlier, but you are correct. I tried again the following morning and realised I wasn’t typing in a DOS command window. It worked once doing that, although I didn’t actually have the plug at the time, I was just checking it looked like it would work. I now ended up with a Tapo P110 so probably won’t work but will give it a go hopefully later on today.
energy_reset works on plug 1 of the TP-Link Kasa Smart Plug HS300 (6 plug power strip). Resets power stats, but not runtime. Thank you for your work!
I was looking to do the same thing, add the following command in the python script (on line 66 in the current version):
‘runtime_reset’ : ‘{“schedule”:{“erase_runtime_stat”:null}}’
And then you’ll be able to run the following to reset the runtime data:
python3 ./tplink_smartplug.py -t -c runtime_reset
Thanks for sharing this script, works like a charm. It did fail for me initially with a connection error on the default port, I tried from another (non-work) computer and it worked straight away. Thanks again!
I have tried on the P110 but get ‘Could not connect to host 192.168.0.153:9999’ I know the ip is correct but don’t know what port it is on. Is this simply not going to work or could adding the port to the command line help or has it detected the port as 9999 ?
Hello, this is exactly what I need, thank you, but I get an error when i run the script.
PS C:\Users\darre\Documents\PythonProjects> python3 ./tplink_smartplug.py -t 192.168.0.46 -c energy_reset
File “C:\Users\darre\Documents\PythonProjects\tplink_smartplug.py”, line 133
print(“Received: “, decrypted)
SyntaxError: expected ‘except’ or ‘finally’ block
I’m not experience in Python so cant seem to debug the issue.
It looks like the file got corrupted when you downloaded it. Try downloading it again with a different web browser. Python is very sensitive to white space. It looks like when you downloaded it, some of the spaces got changed to tabs, or something weird like that
Hi, so downloaded again and it went further so thank you for that. However, I now get the following error
“Could not connect to host 192.168.0.46:9999”
The IP address is correct, I doubled checked, but then it dawned on me that I have the TP-Link Tapo P110 and not KASA HS110. Unless you know differently.
Sorry, I don’t think this method works w/ Tapo, from what others are saying. But I found some code for Tapo plugs. I don’t have one myself, but if someone who has Tapo is willing to test, I can try to make it work. I found a library that works w/ Tapo, but it doesn’t have a reset energy command. So what i want to do is try adding that command, and seeing if Tapo will accept it
Hi, I am happy to try
Thanks for this worked great for me (hs110) and I have now added some more commands (I found amongst the info you provided) to some python scripts, to retrieve data for my power monitoring solution at home. A small 5 min fix you provided led to hours of me playing around with python, json, Grafana etc:)
I wonder if you have come across an issue of incorrect values in the power consumption figures on the Kasa? I just erased the hs110 and ran the Emeter command and got this? the total power figure doesnβt match up with anything on the Kasa app as I just erased the counters??
EmeterStatus power=0.0 voltage=247.633 current=0.016 total=9.553>
PS For anyone that maybe interested and doesnβt already know, I just found some Kasa library that you can add to raspberry pi which lets you run commands from shell and also (I think) python scripts. βpip install python-kasaβ
Thanks once again for helping me sort the counter reset issue & inspiring me to dust off my raspberry pi and do something useful with it:)
For those that are interested about TAPO devices.
To delete data is now available in the lates firmware P110 1.1.2 Build 220930 Rel. 144500
when looking at one of the monitoring graphs click on the 3 dots menu top right of the screen to show a “Delete All Data” option. It works!!
Guess some are not compatible ?
python3 ./tplink_smartplug.py -t 192.168.4.206 -c energy_reset
Sent: {“emeter”:{“erase_emeter_stat”:{}}}
Received: {“emeter”:{“err_code”:-2001,”err_msg”:”module not support”}}
Kasa KL420 RGBIC Strips… (have 5 of them), bought as used from AMZ, so wanted to reset them for homeassistant.
I am completely ignorant about python and only basics from pc. I am trying to use this script but no luck. I have installed python 311 on pc and saved the tplink_smartplug.py in the same folder as the python 311. When I enter βpythonβ in CMD it does tell me the version, but when I enter the script βpython3 ./tplink_smartplug.py -t 192.168.1.2 -c energy_resetβ it says the system cannot find the file specified. What am I doing wrong? Can someone help me please by providing exact steps. Thank you
you need to put the tplink_smartplug.py into the the current directory of the command prompt to use the command I specified.
if it’s in your python directory instead, put in the full path to the file, e.g.
python3 c:\python311\tplink_smartplug.py -t 192.168.1.2 -c energy_resetβ
Okay thank you a lot, it worked fine and reset the energy stats. Is there any way to reset the runtime stats ?
I finally managed to reset the runtime stats. For anyone that is interested, this how I did it. I opened the tplink_smartplug.py with notepad saved it as txt and then I added the following line in the Predefined Smart Plug Commands section, before the ‘energy_reset’ line.
‘runtime_reset’ : ‘{“schedule”:{“delete_all_rules”:null,”erase_runtime_stat”:null}}’,
Next I saved it as tplink_smartplug.py and replaced with it, the old one.
So in the command, python3 ./tplink_smartplug.py -t -c energy_reset , just replaced the word reset with runtime. So the new command is
python3 ./tplink_smartplug.py -t -c runtime_reset.
Thanks for your feedback! I updated my script to also support your runtime_reset command.
Good news for android users for the tp-link tapo p110:
The software on the smartphone and the firmware of the plug have been updated .So if you upgrade to the latest
software and firmware you’ll now have ernergy reset included in the software with more detail on consumption.
you can even add your Kwh rate in your currency . π
Thanks for the code snippets! Both energy_reset & runtime_reset work flawlessly on my new KP125.
Can’t believe they haven’t provided this facility in the Kasa app. Thanks for documenting this.
Yeah, even more annoying that their tech support says it isn’t possible!
Took a bit to figure out where to put the files, BUT i got it to work! thank you
I downloaded Python 3.11 to my Macintosh, and downloaded the “tplink_smartplug” script into the Python folder. I entered the Terminal command “cd ” && ‘/usr/local/bin/python3′ β\tplink_smartplug.py -t 192.168.1.4 -c energy_reset’ && echo Exit status: $? && exit 1″ and the reply was “/Library/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python: can’t open file ‘/Users/Macintosh/βtplink_smartplug.py’: [Errno 2] No such file or directory”
What am I doing wrong? Thanks…
it can’t find the .py file. copy it to the /Users/Macintosh folder
Which I have done, and now the Terminal reply is “-bash: cd: β: No such file or directory
Macintoshs-Pro:~ Macintosh$”
Please note that “Macintosh” is also the name of the “User”.
Hey, I have no idea how to do any of this. But, I managed to figure it out; and, it worked! Thank you so much!!!
This worked perfectly for TP-Link HS103 and HS105 Plugs thank you! Added into a batch script for easily resetting them all at once π
Thank you for this! It took a little bit to get this to work but finally got it. I have never used or ran python commands and what I had learned following these directions is you cant use the python cmd to run the exact code and I was always getting errors and syntax errors. A little more digging and I found that the code is using power shell commands and once I used that code in powershell and had the script in the correct directory, it worked perfectly.
Will this work on a Kasa HS300? It has 6 outlets. Each with energy use info. Is there a way to target a specific outlet?
sorry, i have no idea.. i don’t have one of those