This script runs on Shelly Gen3/Gen4/Pro devices and connects to the Deye Cloud OpenAPI (Personal User) to retrieve real-time energy data from your solar station. It supports:
- 🔐 OAuth token request using personal user credentials
- 🔄 Automatic token refresh every 60 days
- 💾 Token stored using Script.storage as a JSON object
- ⚡ Full power data read via
/v1.0/station/latest - 🔢 Virtual component updates (SOC, battery, generation, consumption, etc.)
| Feature | Status |
|---|---|
| Token authentication | ✅ |
| Script.storage token storage | ✅ |
| Token expiration handling | ✅ |
| Battery SOC (%) | ✅ |
| Battery Power (W) | ✅ |
| Consumption Power (W) | ✅ |
| Generation Power (W) | ✅ |
| Wire Power (W) | ✅ |
| Virtual Component output | ✅ |
| Memory-safe and async-aware | ✅ |
- Shelly Gen3/Gen4/Pro device (e.g., Shelly Plus 1, Shelly Pro 4PM, Shelly Pro 3EM, Shelly 3EM)
- Deye Cloud account (registered as Personal User)
appId,appSecret,email, and SHA256 hashed password from developer.deyecloud.com
Use a SHA256 hashing tool (like this one) to convert your Deye password to a lowercase hex string.
| ID | Name | Type |
|---|---|---|
number:200 |
Generation Power | Number |
number:201 |
Battery SOC | Number |
number:202 |
Battery Power | Number |
number:203 |
Consumption Power | Number |
number:204 |
Grid Power | Number |
text:200 |
Battery state | Text |
You can add them from Shelly Web UI → Settings → Components.
Edit these variables in the script:
let appId = "YOUR_APP_ID";
let appSecret = "YOUR_APP_SECRET";
let email = "your@email.com";
let passwordHash = "your_sha256_password"; // lowercase hex
let stationId = 12345678; // Your Deye station ID- Copy and paste the script into your Shelly Web UI → Script editor
- Save and enable it
- Watch logs: first it will request and store the access token, then fetch live data every 15 seconds
Example output:
🔐 Requesting new token...
✅ Token saved to Script.storage
✅ Deye Station Data:
⚡ Generation Power: 5020 W
🏠 Consumption Power: 240 W
🔋 Battery SOC: 88 %
🔋 Battery Power: 470 W
🧲 Wire Power: 37 W
| Key | Purpose |
|---|---|
deye_token |
JSON object with access_token and expires_at |
Token is stored via:
Script.storage.setItem("deye_token", JSON.stringify({
access_token: "xxx",
expires_at: 1749236567
}));And loaded via:
let raw = Script.storage.getItem("deye_token");
if (typeof raw === "string") {
let obj = JSON.parse(raw);
let token = obj.access_token;
}- 🟢 Control relays based on SOC or power usage
- 🟢 Push data to MQTT or HTTP endpoints
- 🟢 Expose
/rpc/GetDeyeStatusendpoint - 🟢 Integrate with Home Assistant via Shelly Virtual Components
This version uses Script.storage instead of KVS for simplicity, better memory handling, and more reliable long-token storage. Designed to be:
- Minimal memory footprint 🧵
- Shelly-compatible (all devices)
- Robust against token issues and cloud latency
For advanced use, consider offloading token handling to Home Assistant or a Node-RED local proxy.