This is my first draft of a plugin for the Eyedro energy monitor. (it’s also my first plugin, so be kind on any obvious errors I have made) The Eyedro unit has two sensors, one for each electrical phase. When you access the URL of the device’s built-in webserver, you get back a JSON such as this:
{“data”:[[952,13081,8320,1035],[928,13079,4760,577]]}
This is all documented here: https://eyedro.com/eyefi-getdata-api-command-sample-code/
So far, I am missing a few things in my plugin. I want the plugin to create TWO virtual devices, one for each sensor. Then I need to figure out how to parse the data from the JSON array and get the valuse for each sensor.
This is what I have so far:
plugin.Name = "Eyedro";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 10000;
plugin.DefaultSettings = {
"Host": "10.0.0.140", "Port": "8080"
};
var http = new HTTPClient();
var url;
function onChangeRequest(device, attribute, value) {
switch (attribute) {
case "Switch":
device.Switch = value;
break;
default:
break;
}
}
function onConnect() {
url = "http://" + plugin.Settings["Host"] +":" + plugin.Settings["Port"] + "/getdata";
console.log("connected");
}
function onDisconnect() {
console.log("disconnected");
}
function onPoll() {
console.log("polling");
var response = http.get(url);
if (response.status != 200) { //Any response other than 200 indicates a problem with the request
console.log("Eyedro Plugin ERROR! Status " + response.status + ": " + response.statusText);
return;
}
var sensorDevice = plugin.Devices["1"];
if (sensorDevice != null) {
var Eyedrodata = response.data.sensor;
sensorDevice.PowerFactor =
sensorDevice.Voltage =
sensorDevice.Amperage =
sensorDevice.Wattage =
}
}
function onSynchronizeDevices() {
var eyedroSensor = new Device();
eyedroSensor.Id = "1";
eyedroSensor.DisplayName = "Eyedro Sensor";
eyedroSensor.Capabilities = ["CurrentMeasurement","EnergyMeter","PowerMeter","VoltageMeasurement"];
eyedroSensor.Attributes = ["PowerFactor","Voltage","Amperage","Wattage"];
eyedroSensor.Icon = "Gauge";
plugin.Devices[eyedroSensor.Id] = eyedroSensor;
}
Can someone point me in the right direction? Any feedback would be appreciated.