EyeDro Energy Monitor (Work in Progress)

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.

1 Like

The plugin has been updated to correctly pull in the Eyedro values and assign them to both devices. (Each Eyedro meter is actually two sensors).

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 to Eyedrop at " + url);
}

function onDisconnect() {
    console.log("Disconnected from Eyedro");
}

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 sensorDeviceA = plugin.Devices["1"];
	var sensorDeviceB = plugin.Devices["2"];
    if (sensorDeviceA != null) {
        //var Eyedrodata = response.data.sensor;
		sensorDeviceA.PowerFactor = response.data.data[0][0]/1000
		sensorDeviceA.Voltage = response.data.data[0][1]/100
		sensorDeviceA.Amperage = response.data.data[0][2]/1000
		sensorDeviceA.Wattage = response.data.data[0][3]
		console.log("EyedroA PowerFactor: " + response.data.data[0][0]/1000)
		console.log("EyedroA Voltage: " + response.data.data[0][1]/100)
		console.log("EyedroA Amperage: " + response.data.data[0][2]/1000)
		console.log("EyedroA Wattage: " + response.data.data[0][3])		
	}	
    if (sensorDeviceB != null) {		
		sensorDeviceB.PowerFactor = response.data.data[1][0]/1000
		sensorDeviceB.Voltage = response.data.data[1][1]/100
		sensorDeviceB.Amperage = response.data.data[1][2]/1000
		sensorDeviceB.Wattage = response.data.data[1][3]		
		console.log("EyedroB PowerFactor: " + response.data.data[1][0]/1000)
		console.log("EyedroB Voltage: " + response.data.data[1][1]/100)
		console.log("EyedroB Amperage: " + response.data.data[1][2]/1000)
		console.log("EyedroB Wattage: " + response.data.data[1][3])
	}
}

function onSynchronizeDevices() {
    var eyedroSensor = new Device();
    eyedroSensor.Id = "1";
    eyedroSensor.DisplayName = "Eyedro Port A";
    eyedroSensor.Capabilities = ["CurrentMeasurement","EnergyMeter","PowerMeter","VoltageMeasurement"];
    eyedroSensor.Attributes = ["PowerFactor","Voltage","Amperage","Wattage"];
	eyedroSensor.Icon = "Gauge";
    plugin.Devices[eyedroSensor.Id] = eyedroSensor;
	
	var eyedroSensor = new Device();
    eyedroSensor.Id = "2";
    eyedroSensor.DisplayName = "Eyedro Port B";
    eyedroSensor.Capabilities = ["CurrentMeasurement","EnergyMeter","PowerMeter","VoltageMeasurement"];
    eyedroSensor.Attributes = ["PowerFactor","Voltage","Amperage","Wattage"];
	eyedroSensor.Icon = "Gauge";
    plugin.Devices[eyedroSensor.Id] = eyedroSensor;
	
	
}

Any suggestions on how I can make it more efficient would be appreciated.