Greg, this is the first test script in Home Remote to make it control a garden watering system using the Vegetronix hub and sensors (tank water level sensor to control whether there is enough water, soil moisture sensor to check whether the garden needs to be watered, and water flow sensor to monitor the water pumps running) and the Shelly relays to open and close the sprinkler valves of each watering zone and the water tank fill valve in case there is not enough accumulated rain water from the house roof.
The script uses the Shelly 1Pro relay (with dry contacts connected to VegeHub’s port 4 configured as “Edge Trigger Mode”) to force VegeHub update and send all sensors’ data to VegeCloud (it is configured to send the latest 10 readings of all sensors because there is a limit of 2 calls to the server every 15 minutes, I just need to read the latest information of each sensor), and then query VegeCloud from Home Remote (or the Shellys in the final version) to read the latest data of all sensors and, finally, water the garden if needed, and/or previously fill some water to the tank before watering the garden. The thing is that VegeCloud needs around 41-45 seconds to get updated! It is not a big problem though, although the script needs to wait, which is not very elegant… I guess it is due to processing time and latencies?
Right now the script only shows the sensors’ logs with the latest sensor values and times, the rest still needs to be implemented, but I think you might enjoy the possibilities! I hope it will be useful to somebody
I have also added some screen shots where you can see that you can embed views of the sensors’ data in HR using each sensor’s VegeCloud link.
function onChangeRequest(device, attribute, value) {
switch (attribute) {
case "Switch":
device.Switch = value;
if (value == "On") {
//get time now
//"2022-08-31T20:26:38.088Z" now_time example
var now_time = new Date();
//update data to VegeCloud from Shelly "Vegehub Control", configured with a timer of 1 second to close the dry contact
http.get("http://" + ShellyIP + "/relay/0?turn=on");
//VegeCloud needs 44 seconds to be updated !!
sleep(50000);
//getVegehubData fromVegeCloud
VegehubData = HttpGetVegehubData("?limit=10&order=desc");
if (!VegehubData) {
console.log("Error getting Vegehub data, HttpGetVegehubData");
throw "Error getting Vegehub data, HttpGetVegehubData";
} else {
//getVegehubPortData for Port 1 = Water Level sensor, Port 2 = Moisture sensor, Port 3 = Flow sensor
var InfoPort1 = getVegehubPortData(VegehubData, 1);
var InfoPort2 = getVegehubPortData(VegehubData, 2);
var InfoPort3 = getVegehubPortData(VegehubData, 3);
console.log("Data_1 = " + InfoPort1[0] + " , Volts_1 = " + InfoPort1[1] + " , Data_2 = " + InfoPort2[0] + " , Volts_2 = " + InfoPort2[1] + " , Data_3 = " + InfoPort3[0] + " , Volts_3 = " + InfoPort3[1]);
//check time difference, 1 minute = 60000 ms
//"2022-08-30T21:54:32.000Z" JSON date = Tue Aug 30 2022 23:54:32 GMT+02:00
var vege_date = new Date(InfoPort1[0]);
var DateDiffSeconds = (now_time - vege_date) / 1000;
console.log(" ---> DateDiffSeconds = " + DateDiffSeconds + " , now_time = " + now_time);
//Turn Off switch
//device.Switch = "Off";
}
}
break;
default:
break;
}
}] ```