SwitchBotAPI
SwitchBotAPI copied to clipboard
API to get power consumption from SwitchBot Plug
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
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..)
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.
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.
Is the management team making the API private due to concerns about concentrated access to the system?
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.
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 :(
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.
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 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 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
...
@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.
@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
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 , 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.
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 , @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 no it does not, that's the whole point of the back-and-forth @masterlog80 where having.