Skip to content

Create Read data from another Plus via HTTP GET.js #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Read data from another Plus via HTTP GET.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Read values from another Shelly Plus (Shelly call them also 'Gen2') via HTTP GET.

// Settings
let ip = 'ip';
let username = 'admin'; // do not change, it is always admin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, since as the comment said its always 'admin'.

let password = 'password';

// Send HTTP get request with authentication
Shelly.call(
"HTTP.GET", {
"url": "http://" + username + ":" + password + "@" + ip + "/rpc/Switch.GetStatus?id=0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the url compilation outside of the request params.

},
function(result) {
// print(result.body); // Uncomment to see all available values.
let totalwh = JSON.parse(result.body).aenergy.total; // Reminder: On a Plus device energy total is in Watt-hours. On Gen1 device it is Watt-minutes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save the parsed body to an variable and then use it

let totalkwh = JSON.parse(result.body).aenergy.total / 1000;
let tempe = JSON.parse(result.body).temperature.tC; // tC is in celsius, tF is in Fahrenheit.
print(totalwh);
print(totalkwh);
print(tempe);
}
);