Surpassing a condition from a Jeedom board

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
fredfit
Posts: 22
Joined: 17 Jun 2020 12:50

Surpassing a condition from a Jeedom board

Post by fredfit »

Hi all,

Here is my code for a watering system that includes:
- a moisture sensor
- a valve
- a water tank with a level sensor

Code: Select all


#include "Wire.h"

#define pinValve 19
#define pinMoisture 4 // Moisture sensor on ADC1
#define pinLevel 12 // Water tank sensor (0 when full)




byte valveValue;
byte lastLevelState;
byte currenLevelState;
int valueMoisture;

// Sleep mode
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);

/* Channels definition
 - channel 1: valve
 - channel 2: moisture
 - channel 3: water tank level
*/

ZUNO_SETUP_CHANNELS(
ZUNO_SWITCH_BINARY(getterValve, setterValve),
ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_GENERAL_PURPOSE, getterLevel),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_MOISTURE, SENSOR_MULTILEVEL_SCALE_PERCENTAGE_VALUE, SENSOR_MULTILEVEL_SIZE_ONE_BYTE, SENSOR_MULTILEVEL_PRECISION_ZERO_DECIMALS, getterMoisture)
);



void setup() {

  pinMode(pinValve, OUTPUT);
  pinMode(pinMoisture, INPUT);
  pinMode(pinLevel, INPUT_PULLUP);
}

void loop() {
  
  // Water level reading
 byte currenLevelState = digitalRead(pinLevel);
  if (currenLevelState != lastLevelState) {
    lastLevelState = currenLevelState;
    zunoSendReport(3);
  }


  // Moisture reading
  valueMoisture = analogRead(pinMoisture);
  valueMoisture = constrain(valueMoisture,400,1023);
  valueMoisture = map(valueMoisture,400,1023,100,0);  //Mapping: 400 means 100%, 1023 means 0%
  zunoSendReport(2);

  
   //Valve is opened if moisture <20% and tank is not empty
  if (valueMoisture < 20 && currentLevelState == LOW) {
    digitalWrite(pinValve,HIGH);
  }
  else {
    digitalWrite(pinValve,LOW);
  }


void setterValve(byte newvalue){
  digitalWrite(pinValve, (newvalue > 0) ? HIGH : LOW);
  valveValue = newvalue;
}

byte getterValve() {
  return valveValue;
}


byte getterLevel() {
  if (lastLevelState == 0) { // if low level, send 255, instead send 0
    return 255;
  } else {
    return 0;
  }
}

word getterMoisture(void) {
return (valueMoisture);
}
It aims to automatically open the valve if the moisture of the ground is below 20%.
What I would now like from my Jeedom board is to be able to
- monitor when the valve was opened (history). If I add a "zunoSendReport(1);" like this, will it work ? I'm not very comfortable with this command ...

Code: Select all

   //Valve is opened if moisture <20% and tank is not empty
  if (valueMoisture < 20 && currentLevelState == LOW) {
    digitalWrite(pinValve,HIGH);
  }
  else {
    digitalWrite(pinValve,LOW);
  }
zunoSendReport(1);
- surpass this condition by forcing the valve to be on, even if moisture is more than 20%. I tried this but it didn't work:

Code: Select all

   //Valve is opened if moisture <20% and tank is not empty, or forced from Jeedom
  if ((valueMoisture < 20 && currentLevelState == LOW) || valveValue == HIGH)  {
    digitalWrite(pinValve,HIGH);
  }
  else {
    digitalWrite(pinValve,LOW);
  }
  
Can someone help me in finalizing this code ? I think I'm pretty close to the solution, but ...
Thanks !
fredfit
Posts: 22
Joined: 17 Jun 2020 12:50

Re: Surpassing a condition from a Jeedom board

Post by fredfit »

I found myself a solution for point 2 by replacing "valveValue == HIGH" by "valveValue > 0" here:

Code: Select all

   //Valve is opened if moisture <20% and tank is not empty, or forced from Jeedom
  if ((valueMoisture < 20 && currentLevelState == LOW) || valveValue > 0)  {
    digitalWrite(pinValve,HIGH);
  }
  else {
    digitalWrite(pinValve,LOW);
  }
 
Stupid mistake !
But I'm still looking for having the history of the automatic activation of the valve (when moisture goes below 20%) to be visible in my Jeedom domotics. With the above code, I can only see the history of the manual valve activation. The purpose is to remotely check that the automatic irrigation system is working well.
Post Reply