Code Monkey home page Code Monkey logo

Comments (14)

tideline3d avatar tideline3d commented on July 24, 2024 1

I somehow missed this notification, will get you some info soon.

from tplink-plug-exporter.

fffonion avatar fffonion commented on July 24, 2024

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.

from tplink-plug-exporter.

tideline3d avatar tideline3d commented on July 24, 2024

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
    }
}

}

from tplink-plug-exporter.

fffonion avatar fffonion commented on July 24, 2024

@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?

from tplink-plug-exporter.

tideline3d avatar tideline3d commented on July 24, 2024

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 :)

https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/blob/master/octoprint_tplinksmartplug/__init__.py

from tplink-plug-exporter.

fffonion avatar fffonion commented on July 24, 2024

@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.

from tplink-plug-exporter.

fffonion avatar fffonion commented on July 24, 2024

@tideline3d wanna try #9 😄 ?
I attached a linux-amd64 build below as well:
tplink-plug-exporter.gz

from tplink-plug-exporter.

tideline3d avatar tideline3d commented on July 24, 2024

@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!

Screen Shot 2020-11-30 at 2 46 30 PM

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.

image

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?

Screen Shot 2020-11-30 at 3 10 54 PM

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?
Screen Shot 2020-11-30 at 3 16 49 PM

from tplink-plug-exporter.

tideline3d avatar tideline3d commented on July 24, 2024

Occasionally I'll get a partial response when hitting the scrape endpoint as well.
Screen Shot 2020-11-30 at 3 29 06 PM

Instead of

image

from tplink-plug-exporter.

fffonion avatar fffonion commented on July 24, 2024

@tideline3d Woohoo it works! Thanks for taking time testing this!

  1. Yeah that's an issue we need to address. I'll probably add the child_id as a label to child plugs. Since for HS1xx the IP address is also attached as label automatically, so they are not affected before.
  2. It appears from my test that the TCP server on those plugs are single-threaded, if the previous scrape didn't end, then your next scrape will hang. It's a good idea to consult "Targets" page of your prometheus, and see how long does prometheus finish a scrape for one target, then use a scrape interval longer than the single scrape. But it could also be some bug with exporter, I'll log out the err in next commit.
  3. That's a good point, I was thinking this yesterday as well. It probably makes sense to use a different metrics for the total if it's a powerstrip. Since we now have child_id label on child plugs, we can just exclude them children and only use the powerstrip for computing total. I will update the dashboard.

from tplink-plug-exporter.

fffonion avatar fffonion commented on July 24, 2024

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.

from tplink-plug-exporter.

tideline3d avatar tideline3d commented on July 24, 2024

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?

Screen Shot 2020-12-01 at 10 16 54 AM

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)
Screen Shot 2020-12-01 at 10 19 46 AM

from tplink-plug-exporter.

fffonion avatar fffonion commented on July 24, 2024

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?

from tplink-plug-exporter.

fffonion avatar fffonion commented on July 24, 2024

@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.

from tplink-plug-exporter.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.