Greenhouse irrigation almost there

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
johnny_boy_1984
Posts: 9
Joined: 08 Feb 2019 18:33

Greenhouse irrigation almost there

Post by johnny_boy_1984 »

Hello,
I've been busy with a project to water all my plants in the greenhouse.
The system is stand alone with a water tank instead of a connection on the water mains. So first the program has to check if the water level is not low, this to protect the waterpump.
If the water level is ok, the irrigation sequence can start with a delay for the pump to build up pressure. Then 8 valves are sequentialy opened and closed after another. The delays can be changed to determain the amount of water every valve is providing.
And I also want to monitor the temperature and humidity.
Evereything is working now, except the temperature and humidity, i can monitor them by serial print, but it is not visible in Domoticz. Please help me with this last detail.

Code: Select all

/* Z-kas
 * Z-wave controlled irrigation system for greenhouse.
 * Input:   watertank level
 *          temperature (DHT22)
 *          humidity    (DHT22)
 * Outputs: waterpump switch (z-wave) 
 *          8 valves for 8 water circuits
 * 8 valves for different irrigation 
 * 
 * When irrigation is started by user or timer in Domoticz:
 *  Measure waterlevel
 *  When waterlevel is not low start pump
 *  After ... seconds start valve sequence
 */
#include "ZUNO_DHT.h"

// pin number, where relay valves are connected
#define DHTPIN          9
#define IRRIGATION      11   // irrigation system active LED
#define VALVE_1         12  // valve circuit 1
#define VALVE_2         13  // valve circuit 2
#define VALVE_3         14  // valve circuit 3
#define VALVE_4         15  // valve circuit 4
#define VALVE_5         16  // valve circuit 5
#define VALVE_6         17  // valve circuit 6
#define VALVE_7         18  // valve circuit 7
#define VALVE_8         19  // valve circuit 8

DHT dht(DHTPIN, DHT22);

int   humidity;               // here we will store the humidity
int   temperature;            // here we will store the temperature

byte  pin10SensorBinaryState; // waterlvl sensor
int   WtrLVL;                 // integer to store low water level warning

byte  lastSetValue;           // variable to store current switch state
int   IrrigationOn;           // integer to store the switch value
int   T_PumpDelay;            // integer to store pump delay before start irrigation
int   T_Valve1;               // integer to store the opening time of valve 1
int   T_Valve2;               // integer to store the opening time of valve 2
int   T_Valve3;               // integer to store the opening time of valve 3
int   T_Valve4;               // integer to store the opening time of valve 4
int   T_Valve5;               // integer to store the opening time of valve 5
int   T_Valve6;               // integer to store the opening time of valve 6
int   T_Valve7;               // integer to store the opening time of valve 7
int   T_Valve8;               // integer to store the opening time of valve 8

// macro sets up the Z-Uno channels
ZUNO_SETUP_CHANNELS(
      ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_GENERAL_PURPOSE, pin10SensorBinaryGetter),
      ZUNO_SWITCH_BINARY(getter, setter),
      ZUNO_SENSOR_MULTILEVEL_TEMPERATURE(getterTemperature),
      ZUNO_SENSOR_MULTILEVEL_HUMIDITY(getterHumidity) 
      );

void setup() {

  pinMode(10, INPUT);
  pin10SensorBinaryState = !digitalRead(10);
                    
  pinMode(IRRIGATION, OUTPUT);  // Irrigation active
  pinMode(VALVE_1, OUTPUT);     // set up relay pin as output
  pinMode(VALVE_2, OUTPUT);     // set up relay pin as output
  pinMode(VALVE_3, OUTPUT);     // set up relay pin as output
  pinMode(VALVE_4, OUTPUT);     // set up relay pin as output
  pinMode(VALVE_5, OUTPUT);     // set up relay pin as output
  pinMode(VALVE_6, OUTPUT);     // set up relay pin as output
  pinMode(VALVE_7, OUTPUT);     // set up relay pin as output
  pinMode(VALVE_8, OUTPUT);     // set up relay pin as output

  dht.begin();
  Serial.begin(); 
  Serial.println("start");

// defining valve opening times (delays)
  T_PumpDelay = 2000;
  T_Valve1    = 2000;
  T_Valve2    = 1000;
  T_Valve3    = 2000;
  T_Valve4    = 1000;
  T_Valve5    = 1000;
  T_Valve6    = 1000;
  T_Valve7    = 1000;
  T_Valve8    = 1000;
}

void loop() {                       // loop used for reading waterlevel
  
  byte _pin10SensorBinaryState = digitalRead(10);
  if (pin10SensorBinaryState != _pin10SensorBinaryState) {
      pin10SensorBinaryState = _pin10SensorBinaryState;
      WtrLVL = pin10SensorBinaryState;
      zunoSendReport(1);
  }
if (WtrLVL == HIGH) {
  Serial.println("Waterlevel HIGH");
}else {            // if equals zero
   Serial.println("Waterlevel LOW");
     }
  
// loop used for delayed port sequence
  
  if (IrrigationOn == 1 && WtrLVL == HIGH) {          // if irrigation activated & waterlevel is not low
    Serial.println("Normal water level");
    digitalWrite(IRRIGATION, HIGH); //turn irrigation system on
            Serial.println("-= Start irrigation sequence =-");
            Serial.print("Pump delay = ");
            Serial.print(T_PumpDelay);
            Serial.println(" ms");
    delay (T_PumpDelay);            //delay to allow pump to pressurise
    digitalWrite(VALVE_1, HIGH);    //turn relay valve on
            Serial.print("Open irrigation valve 1 for ");
            Serial.print(T_Valve1);
            Serial.println(" ms");
    delay (T_Valve1);
    digitalWrite(VALVE_1, LOW);
      Serial.println("Close irrigation valve 1");
    digitalWrite(VALVE_2, HIGH);    //turn relay valve on
            Serial.print("Open irrigation valve 2 for ");
            Serial.print(T_Valve2);
            Serial.println(" ms");
    delay (T_Valve2);
    digitalWrite(VALVE_2, LOW);
            Serial.println("Close irrigation valve 2");
    digitalWrite(VALVE_3, HIGH);    //turn relay valve on
            Serial.print("Open irrigation valve 3 for ");
            Serial.print(T_Valve3);
            Serial.println(" ms");
    delay (T_Valve3);
    digitalWrite(VALVE_3, LOW);
           Serial.println("Close irrigation valve 3");
    digitalWrite(VALVE_4, HIGH);    //turn relay valve on
           Serial.print("Open irrigation valve 4 for ");
           Serial.print(T_Valve4);
           Serial.println(" ms");
    delay (T_Valve4);
    digitalWrite(VALVE_4, LOW);
           Serial.println("Close irrigation valve 4");
    digitalWrite(VALVE_5, HIGH);    //turn relay valve on
           Serial.print("Open irrigation valve 5 for ");
           Serial.print(T_Valve5);
           Serial.println(" ms");
    delay (T_Valve5);
    digitalWrite(VALVE_5, LOW);
            Serial.println("Close irrigation valve 5");
    digitalWrite(VALVE_6, HIGH);    //turn relay valve on
            Serial.print("Open irrigation valve 6 for");
            Serial.print(T_Valve6);
            Serial.println(" ms");
    delay (T_Valve6);
    digitalWrite(VALVE_6, LOW);
            Serial.println("Close irrigation valve 6");
    digitalWrite(VALVE_7, HIGH);    //turn relay valve on
            Serial.print("Open irrigation valve 7 for ");
            Serial.print(T_Valve7);
            Serial.println(" ms");
    delay (T_Valve7);
    digitalWrite(VALVE_7, LOW);
            Serial.println("Close irrigation valve 7");
    digitalWrite(VALVE_8, HIGH);    //turn relay valve on
            Serial.print("Open irrigation valve 8 for ");
            Serial.print(T_Valve8);
            Serial.println(" ms");
    delay (T_Valve8);
    digitalWrite(VALVE_8, LOW);
            Serial.println("Close irrigation valve 8");
    IrrigationOn = 0;
            Serial.println("-= End irrigation sequence =-");
    digitalWrite(IRRIGATION, LOW); //turn irrigation system off
    } else if (IrrigationOn == 1 && WtrLVL == 0){                  //if irrigation activated & waterlevel is low
            Serial.println("Low water level!");
            Serial.println("-= Irrigation sequence not started =-");
            Serial.println("Close all irrigation valves");
    digitalWrite(VALVE_1, LOW);     //switch off all relay valves and irrigation system 
    digitalWrite(VALVE_2, LOW);
    digitalWrite(VALVE_3, LOW);
    digitalWrite(VALVE_4, LOW);
    digitalWrite(VALVE_5, LOW);
    digitalWrite(VALVE_6, LOW);
    digitalWrite(VALVE_7, LOW);
    digitalWrite(VALVE_8, LOW);
    digitalWrite(IRRIGATION, LOW);
    IrrigationOn = 0;
            Serial.println("-= End irrigation sequence =-");
     }
     
     // obtaining readings from the sensor DHT
  humidity = dht.readHumidity();
  temperature = dht.readTemperature();
  Serial.print("Humidity = "); 
  Serial.print(humidity);
  Serial.print(" %  ");
  Serial.print("Temperature = "); 
  Serial.print(temperature);
  Serial.println(" *C");
  
  // send data to channels
  zunoSendReport(1);
  zunoSendReport(2); 
  // send every 30 second
  delay(1000);

  }


// function, which returns the previously saved relay value
// this function runs only once the controller asks

byte pin10SensorBinaryGetter() {
  return pin10SensorBinaryState;
}

byte getter() {
    return lastSetValue;
}
byte getterTemperature() {
  return temperature;
}

byte getterHumidity() {
  return humidity;
}


// function, which sets new relay state
// this function runs only once the controller sends new value
void setter(byte newValue) {
  // newValue is a variable, holding a "value"
  // which came from the controller or other Z-Wave device
  if (newValue > 0) { // if greater then zero
    IrrigationOn = 1;
      } else {            // if equals zero
    IrrigationOn = 0;
     }

  // save the new value in a variable
  lastSetValue = newValue;
}
User avatar
PoltoS
Posts: 7624
Joined: 26 Jan 2011 19:36

Re: Greenhouse irrigation almost there

Post by PoltoS »

Domoticz is based on Open Z-Wave. It has issues with many different channels in one device. A custom XML is required.
johnny_boy_1984
Posts: 9
Joined: 08 Feb 2019 18:33

Re: Greenhouse irrigation almost there

Post by johnny_boy_1984 »

I got it working a few earlier versions ago, after combining different codes it isn't working anymore. I suspect a fault in my code.
User avatar
PoltoS
Posts: 7624
Joined: 26 Jan 2011 19:36

Re: Greenhouse irrigation almost there

Post by PoltoS »

The problem is certainly in the combination of channels not supported by Domoticz
johnny_boy_1984
Posts: 9
Joined: 08 Feb 2019 18:33

Re: Greenhouse irrigation almost there

Post by johnny_boy_1984 »

That's a bit disapointing, guess i have to measure it with another device.

Can you then help me to point me out on how to set the switch 'off' after the irrigation sequence is done.
I thought this must be done in the 'byte pin10SensorBinaryGetter()' but i don't know how.
johnny_boy_1984
Posts: 9
Joined: 08 Feb 2019 18:33

Re: Greenhouse irrigation almost there

Post by johnny_boy_1984 »

I got it working again by excluding and includig the z-uno again. But only for an hour or so, then no new data is received.
Would it be an option to use a DS18B20 or will that not do the trick, because it is also a Multi level sesor?
User avatar
PoltoS
Posts: 7624
Joined: 26 Jan 2011 19:36

Re: Greenhouse irrigation almost there

Post by PoltoS »

Sure, you can use ds18b20
johnny_boy_1984
Posts: 9
Joined: 08 Feb 2019 18:33

Re: Greenhouse irrigation almost there

Post by johnny_boy_1984 »

Results are the same, it works for an hour or so. i used the example, but that is also a Multilevel, so guess that doesn's work also
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE,
SENSOR_MULTILEVEL_SCALE_CELSIUS,
SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS,
getterTemp)
User avatar
PoltoS
Posts: 7624
Joined: 26 Jan 2011 19:36

Re: Greenhouse irrigation almost there

Post by PoltoS »

Do you mean your code stops working after an hour? Does it stop sending reports to your controller? Does it still blink? Please provide more sympthoms.
Post Reply