tplink-cloud-api icon indicating copy to clipboard operation
tplink-cloud-api copied to clipboard

what metric is the power property on getPowerUsage()?

Open thanhvuong opened this issue 7 years ago • 6 comments

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

thanhvuong avatar Nov 15 '18 06:11 thanhvuong

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.

adumont avatar Nov 15 '18 06:11 adumont

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

thanhvuong avatar Nov 15 '18 07:11 thanhvuong

Any updates on this?

Jackthomsonn avatar Nov 26 '18 08:11 Jackthomsonn

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.

zoernert avatar Aug 25 '19 14:08 zoernert

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.

ironsm4sh avatar Jan 17 '20 08:01 ironsm4sh

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

tnmendes avatar Dec 01 '20 00:12 tnmendes