Vegetronix, VegeCloud plugin

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 :wink:
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 !!
                //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";
}] ```

This is very, very cool! I’m excited to try it out (when I have time!). Thank you so much for sharing. Because of the long delays, I will probably write a script to run on a raspberry pi and then use HR to trigger it. This way the heavy lifting is done on the RPi and HR stays light.

Greg, thank you very much for your suggestion of using Vegetronix, I think it will work very well.
It would be nice to try your own server to see if the delay time could be quite reduced and get unlimited queries, but I have no idea of how to build the server…
I will actually have HR to run the program as well as the Shelly relay, which will work on a schedule automatically every day 1-2 times to water the garden.
I will post my final program, in case it might be helpful to others.

Using your own server would not reduce time or increase queries but having that long delay in HR software would be my only concern. Excited to hear how it performs though!

1 Like