Send Shelly data to emoncms

Hello everyone,

I would like to share my Shelly script, which can be used to send data from an energy meter directly (without MQTT detour) to emoncms.
If you don’t know the Shelly energy meters, they are small inexpensive devices (available from 15 €) based on an esp8266/esp32 and a dedicated energy measurement chip (AD7953).

Note: Only Pro and Plus devices support scripting.

 // Shelly GEN2 script: HTTP GET - Send energy meter watts to emoncms

// Settings
let user_apikey = "xxxxx"; // Copy from emoncms.org > my account > Read & Write API Key
let name = "shelly";  // set a custom name for your shelly

let url = "https://emoncms.org/input/post?node=";

// Define timespan: sec * 1000 milliseconds
let interval = 10 * 1000;

// Set timer which send the HTTP GET
Timer.set(
  interval,
  true,
  function () {let status = Shelly.getComponentStatus("switch", 0);
  let url_send = url + name + "&json={Power:" + JSON.stringify(status.apower) + ",Wh:" + JSON.stringify(status.aenergy.total) + ",V:" + JSON.stringify(status.voltage) + "}&apikey=" + user_apikey;
  Shelly.call("HTTP.GET", {"url": url_send});
}
);
2 Likes

Nice! Thanks for sharing.

The only thing I’d suggest is using HTTP POST so that the API key is not left exposed in the url.

Hi Tim, thanks for the feedback, you’re right, I’ll try the variant with post.

The switch to using HTTP POST has unfortunately not yet worked, but I have discovered that https connections also work, so the problem should no longer be that urgent.

I have updated the code so that Wh and voltage are now also transmitted. I also noticed that the values were not being updated at all (the same value was being sent every 10 seconds), so I have now moved the reading of the values to the timer, which solves the problem.

Thank you for this! I have 20 of the things mqttt ing into emoncms via node red…busy and fragile. I will look forward to having a go over the weekend. Cheers!