A quick & small POC in Python on how to use the Shelly Cloud Control API (and more specifically the WebSocket API) to get data from a Shelly device (tested with a Shelly Plug S + Python 3.10).
The aim is to get realtime data (temperature, power in watts) from the device directly from the Shelly Cloud, like the official Shelly Home website, which seems to use the same API to display realtime data.
Once the setup is done, the poc.py
file will try to get OAuth credentials and fetch events through the WebSocket API. As it doesn't handle OAuth session management it will probably crash once the access token expires.
You need to:
- In your Python environments, install the dependencies listed in
requirements.txt
(pip install -r requirements.txt
) - Set two environment variables that will be used for the OAuth login:
SHELLY_EMAIL
with the email you use on your Shelly Cloud accountSHELLY_PASSWORD_SHA1
with the sha1 of your Shelly Cloud account password (can be obtained withecho -n "my_password" | sha1sum
for example, or you can find it stored in thepassword
field in theuser_data
entry of your browser local storage for home.shelly.cloud).
- Change the
SERVER
variable with the server used for your account. You can obtain it by looking at the network requests done on the official Shelly Home Website. It should be something likeshelly-49-eu.shelly.cloud
. You can also find it stored in theuser_api_url
field in theuser_data
entry of your browser local storage for home.shelly.cloud. - You can then launch the script