Closed tideline3d closed 3 years ago
Hi @tideline3d I don't have a HS300 on my side to test, but I read that it uses same kasa protocol and probably have an extra rpc function to pull power consumption for whole strip. Any dump will be helpful like using tools from https://github.com/softScheck/tplink-smartplug.
I somehow missed this notification, will get you some info soon.
Here's the output of a couple of the commands from that tool. Let me know if you need something else?
-c energy output
"emeter": { "get_realtime": { "voltage_mv": 121487, "current_ma": 785, "power_mw": 92388, "total_wh": 16769, "err_code": 0 } }
-c info output
"system": { "get_sysinfo": { "sw_ver": "1.0.19 Build 200224 Rel.090814", "hw_ver": "1.0", "model": "HS300(US)", "deviceId": "80065BD45F0CE05BE7807BA186CCB7871B25D4B2", "oemId": "5C9E6254BEBAED63B2B6102966D24C17", "hwId": "34C41AA028022D0CCEA5E678E8547C54", "rssi": -57, "longitude_i": 0, "latitude_i": -778794, "alias": "TP-LINK_Power Strip_0786", "status": "new", "mic_type": "IOT.SMARTPLUGSWITCH", "feature": "TIM:ENE", "mac": "D8:0D:17:D8:07:86", "updating": 0, "led_off": 0, "children": [ { "id": "80065BD45F0CE05BE7807BA186CCB7871B25D4B200", "state": 1, "alias": "E3-Green", "on_time": 843976, "next_action": { "type": -1 } }, { "id": "80065BD45F0CE05BE7807BA186CCB7871B25D4B201", "state": 1, "alias": "RPi-Red", "on_time": 822261, "next_action": { "type": -1 } }, { "id": "80065BD45F0CE05BE7807BA186CCB7871B25D4B202", "state": 0, "alias": "E3-Blue", "on_time": 0, "next_action": { "type": -1 } }, { "id": "80065BD45F0CE05BE7807BA186CCB7871B25D4B203", "state": 0, "alias": "Air Filter", "on_time": 0, "next_action": { "type": -1 } }, { "id": "80065BD45F0CE05BE7807BA186CCB7871B25D4B204", "state": 1, "alias": "RPi-Blue", "on_time": 1380538, "next_action": { "type": -1 } }, { "id": "80065BD45F0CE05BE7807BA186CCB7871B25D4B205", "state": 1, "alias": "E3-Red", "on_time": 1380537, "next_action": { "type": -1 } } ], "child_num": 6, "err_code": 0 } } }
@tideline3d Thanks! With that I guess we can at least have the children
status. I'm wondering if HS300 support per socket energy meter function. Are you able to view that using the Kasa app?
Yes, I can see individual power on the app. I use this plugin for OctoPrint that will pull energy from an individual plug for its statistics. But would much rather have all that flowing into Prometheus.
Here's the plugin code that does it, forgive me for not really knowing python well enough to point you any further :)
@tideline3d nvm, I find a similar one https://github.com/python-kasa/python-kasa/blob/master/kasa/smartstrip.py which appears to be more readable. I will draft a PR now.
@tideline3d wanna try https://github.com/fffonion/tplink-plug-exporter/pull/9 😄 ? I attached a linux-amd64 build below as well: tplink-plug-exporter.gz
@fffonion I threw it on DockerHub so I could test it easier (for me at least). It seems to work, but a few oddities. Here's the output that seems to be working!
Potential Issues I found:
1 - Duplicate plug names throw an error. I assume since they were just a string, they shouldn't be used for anything? Here I had two of my plugs labeled 'Empty'. Changing one to 'Empty2' got around this.
2 - I'm getting spotty results from the scrape. It seems to scrape fine, but after a few tries I'll get empty results. My scrape interval is ambitious at 5s. Though I can cause this reliably by just refreshing a browser. Is that a 'feature' of the Kasa device just not liking that much traffic?
3 - The 'TPLink _PowerStrip' item appears to be the aggregate, but that causes totals in your default dashboard to get weird. Not sure if this will cause problems later. I'd personally be fine ignoring the total from the device and only presenting the 6 plugs, ignoring the parent. But not sure if that works for all?
Occasionally I'll get a partial response when hitting the scrape endpoint as well.
Instead of
@tideline3d Woohoo it works! Thanks for taking time testing this!
I have made some improvement to the exporter. Now every metrics has an id
label, when calculating total, we should use sum(kasa_power_load{id=~".{40}")
to exclude child plugs.
I'll try this later today, but I'm not sure using the strip's power usage is actually accurate? Most of the time, mine doesn't add up to the sum of its children. However I'm running 3D printers here which fluctuate power ALOT in turning on/off the heaters, so its possible that its just an artifact of the really quick power spikes they generate?
An example from your dashboard. Note the orange is never the sum of the other items, its only as large as one of them at a given time? This is all from the original PR, not the update. Curious if that update approach is actually accurate given the data here? Another option might be to just ignore the parent and treat the strip as 6 HS110 plugs?
And another example from power total dashboard element. I would expect the purple line here to be a sum of all the other ones (and then as it stands, green being an aggregation of both of those)
Hmmmm that's interesting, I'd double check does the power number adds up in the Kasa app? If it does, then there must be either the strip or the child plugs has wrong number: could you share on which one doesn't match to that exports to prometheus?
@tideline3d I merged the PR and it closes this issue. Feel free to reopen or create a new issue if the feature is not working.
Loving this exporter, but I'm targeting it against my HS300 Power Strip and it appears to only be pulling one plugs power wattage. Is there a way to make it pull either each one individually (like its 6 HS110s) or just pull an aggregate for the whole strip?