SwitchBotAPI icon indicating copy to clipboard operation
SwitchBotAPI copied to clipboard

API to get power consumption from SwitchBot Plug

Open mongonta0716 opened this issue 4 years ago • 18 comments

Is your feature request related to a problem? Please describe.

The function to know the power consumption is useful, but there are too many steps to operate the application.

Describe the solution you'd like

I would like to see not only power ON/OFF, but also current, voltage, and power consumption items.

Describe alternatives you've considered

I take my smart phone and operate it at least five times to find out.

Additional context

mongonta0716 avatar Jan 24 '21 07:01 mongonta0716

I am also interested in this functionality. Is there any other way of obtaining these readings directly from the device? e.g. direct access point to the plug in WiFi, while being paired in WiFi setup mode, BLE (not sure if the plug has BT..)

anoff avatar Jul 24 '21 14:07 anoff

I think so too. I want to check the operating status of the device by power consumption, so I want to get the power consumption.

idaitoshi avatar Aug 07 '21 07:08 idaitoshi

I am interested in getting information about consumption too. I want to know if an appliance is on or off which has only "toggle button" for power on/off.

himawari2021 avatar Oct 10 '21 03:10 himawari2021

Is the management team making the API private due to concerns about concentrated access to the system?

cosura avatar Nov 29 '21 12:11 cosura

I think so too. In the app, displayed power consumption(W), voltage(V), and current(A). I want to get the same data with API.

kmikage avatar Dec 26 '21 05:12 kmikage

I'm surprised and disappointed to find out the power consumption information is not part of the API. I was hoping to feed the power usage information into grafana for closer inspection, but no luck I guess :(

larpo avatar Dec 29 '21 17:12 larpo

this is unfortunate if not planning to be added would have expected this to be available considering they clearly are capturing/storing the information. not making it available seems odd considering how useful it would be to get combined home or room total kWh used vs having to calculate it manually from reviewing the app per device and tally it up.

meramsey avatar Aug 22 '22 00:08 meramsey

Sorry guys, this feature will not be added for SwitchBot Plug. If you happen to have purchased Plug Mini (US) / Plug Mini (JP), u can get the data through the API.

Minsheng avatar Nov 30 '22 08:11 Minsheng

@Minsheng Partially correct in my opinion. As far as I know, the API can provide the electricCurrent (Current), voltage(Voltage), weight(Power), etc. but not the Energy which is available in the App along with its History (not sure how long those data are stored). Obviously it's possible to constantly (e.g. every 1 min for high resolution) get weight(Power) and time, put those a DB and calculate the Energy along a timeframe, but it needs more effort than making a single call per day to get the Energy, or better its history. I am wondering if it's possible to capture the packets and see which API is used by the App to get those. 🤔

Examples:

EDIT: connection by App and API server seems using TLS resulting on encrypted data (including the API call to get Energy along with its History), so I am not sure if it's possible to retrieve those details easily.

masterlog80 avatar Dec 01 '22 00:12 masterlog80

@masterlog80 Based on the documentation, weight should be exactly what you are looking for, but for whatever reason it seems to return power instead. Not to mention the API returns also a 10x value for the electricCurrent... image

larpo avatar Dec 07 '22 07:12 larpo

@larpo To better clarify, the weight is indeed the instant power (not the daily one as mentioned in the documentation which at this point seems to be wrong). However, the power is considered an instant value and measured in W (Watt), while the energy is expressed in a specific time frame like KWh (KW per hours). However on my side all the parameters shown (e.g. electricCurrent, voltage, etc.) are correct and legit. What I am looking for is the energy and its History (in order to eventually calculate the costs) which indeed can be retrieved from the cloud (the App can do that), but the target API and its output are not available in the documentation.

masterlog80 avatar Dec 08 '22 02:12 masterlog80

@larpo & @masterlog80 given the voltage and current you should be able to track power usage over time and get a "energy" over whatever time frame you want.

Ex: power = voltage x current = 120V x 5A

If you integrate this API into a home automation software like home assistant you could track the cumulative power usage over an hour and then make a cumulative sum over a day and then you have that day's KWh usage.

maxlingenfelter avatar Jul 20 '23 03:07 maxlingenfelter

@maxlingenfelter that's actually not correct. To calculate the power on AC, you need to consider also the power factor which is not a static or fixed value. The point here is to get the Energy and its History trough the API, in the easiest way as possible.

masterlog80 avatar Jul 30 '23 02:07 masterlog80

@masterlog80 , you are right about considering the power factor for accurate power calculations on AC circuits. I apologize for not explicitly mentioning that earlier.

To track power usage over time and calculate energy (KWh) accurately, the formula is:

Real Power (kW) = Apparent Power (VA) × Power Factor where:

Apparent Power (VA) = Voltage (V) × Current (A)

Since the power factor can vary over time due to different loads, continuously monitoring the power factor and using its real-time value in energy calculations is essential. By doing this and integrating the API into home automation software like Home Assistant, you can track cumulative power usage over time, accounting for fluctuations in the power factor, and obtain a more precise representation of energy consumption in KWh for any desired time frame.

While dedicated energy meters with power factor measurements can provide more accurate results, the API-based approach is still valuable for many monitoring scenarios, as long as the dynamic nature of the power factor is taken into consideration.

maxlingenfelter avatar Jul 30 '23 03:07 maxlingenfelter

I wasn't sure that the power factor can be retrieved by API, I need to check that. However, thanks for your update.

I would suggest you providing some instructions to integrated this into automation software (e.g. Home Assistant, etc.) to get the values required as for not developers this can be pretty troublesome.

Regards,

masterlog80 avatar Jul 31 '23 01:07 masterlog80

@masterlog80 , @maxlingenfelter , I don't think so that the API returns a power factor. I am using a switcbot plug mini US, and I dont see power-factor being returned in the response.

HERE IS MY SAMPLE RESPONSE { "statusCode": 100, "body": { "deviceId": "A0764E357656", "deviceType": "Plug Mini (US)", "hubDeviceId": "A0764E357656", "power": "off", "voltage": 123.1, "weight": 0, "electricityOfDay": 20, "electricCurrent": 0, "version": "V1.5-1.5" }, "message": "success" }

kganjoo avatar Aug 02 '23 21:08 kganjoo

@kganjoo no it does not, that's the whole point of the back-and-forth @masterlog80 where having.

maxlingenfelter avatar Aug 03 '23 03:08 maxlingenfelter