Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

what metric is the power property on getPowerUsage()? #25

Open
thanhvuong opened this issue Nov 15, 2018 · 6 comments
Open

what metric is the power property on getPowerUsage()? #25

thanhvuong opened this issue Nov 15, 2018 · 6 comments
Labels

Comments

@thanhvuong
Copy link

thanhvuong commented Nov 15, 2018

Is this kWh?
{"power": 304.581534, "total": 0.879, "current": 4.13536, "voltage": 121.355707, "err_code": 0}

@adumont
Copy link
Owner

adumont commented Nov 15, 2018

Could you check in the Kasa app at the same time and see how it represents the same data? There should be a relation. Maybe you can send a screen shot of the app showing the power usage, and the result of the API method call, both taken at approximately the same time? Thanks.

@thanhvuong
Copy link
Author

thanhvuong commented Nov 15, 2018

This is all I see in the app. Is it watts?
image

@Jackthomsonn
Copy link

Any updates on this?

@zoernert
Copy link

It is Watts - however I wonder what the "total" value is as this one does not sum up to any of the values presented in Kasa APP - nor does it fit to the real total (lifetime) value.

@ironsm4sh
Copy link

ironsm4sh commented Jan 17, 2020

I have a new HS110, with (presumably) newer firmware. This plug will return a different JSON. it is structured to show the unit of a measurement too.

{"power_mw": 0.0, "total_wh": 0.0, "current_ma": 0.0, "voltage_mv": 0.0, "err_code": 0}

The units being milliwatts, watthour, milliampere and millivolt.
However, while the Kasa app reports a total usage of 1.8kWh, the HS110's API will report a total of 4,1 kWh (in wh). I have not checked carefully, but this may be a constant offset.

I would like to add to this that I am NOT using the tplink-cloud-API, but that I am reading this data directly from the device by opening a socket connection to it over the local network. But this shouldn't make a big difference.

@tnmendes
Copy link

tnmendes commented Dec 1, 2020

Hey guys maybe I can help with this, for example, the UK plug HS110 uses the string "total" and the EU use "total_wh".
So you have to multiply by 1000 to have the same value.

I am also developing a small project for the TP-link community that have iOS/iPad
https://watt-app.com/

Here is the Swift class that I use to convert JSON to object, I think it can help.

class GetRealtime: Codable {
    let voltage: Double? // voltage  E.G. 123.965090   (US plug)
    let voltageMv: Int?  // voltage  E.G. 243512
    let current: Double? // current  E.G. 0.915185     (US Plug)
    let currentMa: Int?  // current  E.G. 77
    let powerMw: Int?    // Power    E.G. 7538
    let power: Double?   // Power    for HS110(UK) "power\":6.947870
    let totalWh: Int?    // Total
    let total: Double?   // Total for HS110(UK) "total\":0.259000
    let errCode: Int
    
    enum CodingKeys: String, CodingKey {
        case voltage
        case voltageMv = "voltage_mv"
        case current
        case currentMa = "current_ma"
        case powerMw = "power_mw"
        case power
        case totalWh = "total_wh"
        case total
        case errCode = "err_code"
    }
    
    init(voltage: Double?, voltageMv: Int?, current: Double?, currentMa: Int?, powerMw: Int?, power: Double?, totalWh: Int?, total: Double?, errCode: Int) {
        self.voltage = voltage
        self.voltageMv = voltageMv
        self.current = current
        self.currentMa = currentMa
        self.powerMw = powerMw
        self.power = power
        self.totalWh = totalWh
        self.total = total
        self.errCode = errCode
    }
    
    
    // Return power in mW
    func getPower() -> Int {
        
        if let power = self.powerMw {
            return power
        }
        if let power = self.power {
            return Int(power*1000)
        }
        return 0
    }
    
    
    // Return voltage in mV
    func getVoltage() -> Int {
        
        if let voltage = self.voltageMv {
            return voltage
        }
        if let voltage = self.voltage {
            return Int(voltage*1000)
        }
        return 0
    }
    
    
    // Return current in mA
    func getCurrent() -> Int {
        
        if let current = self.currentMa {
            return current
        }
        if let current = self.current {
            return Int(current*1000)
        }
        return 0
    }
    
    // Return in total Wh
    func getTotal() -> Double {
        
        if let total = self.totalWh {
            return Double(total)
        }
        if let total = self.total {
            return total*1000
        }
        return 0.0
    }
    
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants