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});
}
);
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!
Having just been coding some emoncms POSTing, how does this work without HTTPS being set up?
I couldn’t get data to go to emoncms without it being secured in some way.
In ESP32 (for an M5StickCPlus2) I had to do define the rootcertificate of emoncms in code then use specific https libraries to get the data to go:
Just as additional confirmation, this definitely works as you describe. Doing it from an ESP32 programmed with Arduino C++ and no https. Apikey at the end and that’s it