Hijacking a little here, as this just popped up new again. I ended up doing this for a hs110 energy monitor, and didn’t find this post so I came up with the following script. Call it with the IP address of your plug, and the MQTT service you want to publish to. It assumes you still have your mqtt password set to the default.
You’ll need paho-mqtt and python-kasa installed. I run this from cron with something like:
/home/pi/kasa-upload.py 192.168.1.244 drier >/dev/null 2>&1
Here’s the script:
#!/usr/bin/python3
import asyncio;
from kasa import SmartPlug
import paho.mqtt.publish as publish
import sys
plug = SmartPlug(sys.argv[1])
asyncio.run(plug.update())
power = plug.emeter_realtime.get('power_mw')
power = power / 1000
publish.single("emon/kasa/%s" % sys.argv[2], payload=power,
auth = {'username':"emonpi", 'password':"emonpimqtt2016"})