Multiple channels of the same type (and referencing them in Smartthings)

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
ianakapilotlight
Posts: 7
Joined: 18 Nov 2017 13:06

Re: Multiple channels of the same type (and referencing them in Smartthings)

Post by ianakapilotlight »

petergebruers wrote:
13 Jun 2021 17:30
I cannot help you, my HC2 is switched off... I use a HC3 at the moment. You can upload your sketch, here, and hope that someone else reads your post and works it out for you.
Believe me, I do appreciate your response. I have built a few projects with the Z-Uno. I have an 8 channel relay board sat in my shed and using the Z-Uno I am able to switch those relays on/off to control lighting in the garden. Unlike that project which displayed on/off buttons in my HC2 without any problems whatsoever (no messing with S or M or associations at all), it simply worked and I was happy with that.

However with Binary Door window channels any more than ONE is a complete pain and does not simply appear, unlike the on/off switches.

I thank you for your responses.
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Multiple channels of the same type (and referencing them in Smartthings)

Post by petergebruers »

I totally understand, I have had similar issues, I usually tried some workaround, like, defining different channel types (eg a "multilevel switch" or "multilevel sensor" might do the trick, not sure what you want to do) and accept that the GUI might not be 100% correct, but at least get some kind of communication. It's hard to say without tools if it is the HC2 or the Z-Uno that is not following the (or some) rule, a Zniffer can tell you if the Z-Uno is sending the right data, but this does not help you at all, you have almost zero chance of getting a fix on a HC2. On HC3, that is a different matter, Fibaro is working on a new Z-Wave engine which should improve compatibility. But that's a different story.
ianakapilotlight
Posts: 7
Joined: 18 Nov 2017 13:06

Re: Multiple channels of the same type (and referencing them in Smartthings)

Post by ianakapilotlight »

petergebruers wrote:
13 Jun 2021 17:30
I cannot help you, my HC2 is switched off... I use a HC3 at the moment. You can upload your sketch, here, and hope that someone else reads your post and works it out for you.
Just a quick update I've got it working, see final code

Code: Select all

/*
 * Airing Cupboard Z-Wave controller
 * Monitors the Zone 1 & Zone 5 alarm system door sensors
 * When door opens/closes the circuit sends a Z-Wave announcement of the door state
 */
 
// Firmware : 2.1.6
// To Include :
// Once included in the ZWave network, set configuration parameter 12 to 1
// Go into associations and uncheck M & S on the controller -> Save
// Go into associations and check M only on controller -> Save

// Undesired are the extra devices auto created, these should be disabled and hidden
 
// LED pin number
#define ZONE1_LED     14
#define ZONE5_LED     15
#define DATA_LED      16

// button pin number
#define ZONE1_LOOP    17
#define ZONE5_LOOP    18

// channel number
#define ZUNO_ZONE1_CHANNEL_REPORT   1
#define ZUNO_ZONE5_CHANNEL_REPORT   2

// variable to store current button state
bool showDataLED = false;
bool showDataLEDPrevious = false;
byte lastZone1State = 0;
byte lastZone5State = 0;

long lastReadingTime = 0;
byte zone1State = 0;
byte zone5State = 0;

ZUNO_SETUP_CHANNELS(
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(zone1Getter),
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(zone5Getter)
);

ZUNO_DISABLE(WITH_CC_NOTIFICATION);

bool lastButtonState = false;

// function, which returns the previously saved button state
// this function runs only once the controller asks
byte zone1Getter(){
  Serial.print("Zone 1 Read : ");
  Serial.println(zone1State);
  return zone1State;
}

// function, which returns the previously saved button state
// this function runs only once the controller asks
byte zone5Getter(){
  Serial.print("Zone 5 Read : ");
  Serial.println(zone5State);
  return zone5State;
}

void setup() {
  Serial.begin(115200);
  Serial.println("starting");
  pinMode(ZONE1_LED, OUTPUT);
  pinMode(ZONE5_LED, OUTPUT);
  pinMode(DATA_LED, OUTPUT);
  
  pinMode(ZONE1_LOOP, INPUT);
  pinMode(ZONE5_LOOP, INPUT);
  
  delay(100);
}

void loop() {
  
  // sample current button state
  byte currentZone1State = digitalRead(ZONE1_LOOP);
  byte currentZone5State = digitalRead(ZONE5_LOOP); 

  if (currentZone1State != lastZone1State || currentZone5State != lastZone5State) { // if state changes
    Serial.print("currentZone1State: ");
    Serial.print(currentZone1State);
    Serial.print(", currentZone5State: ");
    Serial.println(currentZone5State);
    
    if(currentZone1State != lastZone1State) {
      Serial.print("Zone 1 Changed ");
      lastZone1State = currentZone1State; // save new state
      showDataLED = true;
      if (currentZone1State == LOW) { // if button is pressed
        digitalWrite(ZONE1_LED, LOW);  // shine the LED
        Serial.println("HIGH");
        zone1State = 0;
      } else {                        // if button is released
        digitalWrite(ZONE1_LED, HIGH);   // turn the LED off
        Serial.println("LOW");
        zone1State = 255;
      }

      Serial.println("Sending Zone 1 Report");
      zunoSendReport(ZUNO_ZONE1_CHANNEL_REPORT);
    }

    if (currentZone5State != lastZone5State) { // if state changes
      lastZone5State = currentZone5State; // save new state
      Serial.print("Zone 5 Changed ");
      showDataLED = true;
      if (currentZone5State == LOW) { // if button is pressed
        digitalWrite(ZONE5_LED, LOW);  // shine the LED
        Serial.println("HIGH");
        zone5State = 0;
      } else {                        // if button is released
        digitalWrite(ZONE5_LED, HIGH);   // turn the LED off
        Serial.println("LOW");
        zone5State = 255;
      }
      Serial.println("Sending Zone 5 Report");
      zunoSendReport(ZUNO_ZONE5_CHANNEL_REPORT);
    }
    
  }

  if (showDataLED) {
    
    if (!showDataLEDPrevious) {
      // Turn LED on if not already on - Set once
      Serial.println("Turn LED on");
      showDataLEDPrevious = true;
      
      digitalWrite(DATA_LED, HIGH);
    }
    
    long currentMillis = millis();
    if (currentMillis - lastReadingTime > 2000) {
      lastReadingTime = currentMillis;
      
      Serial.println("Turn LED off");
    
      digitalWrite(DATA_LED, LOW);

      showDataLED = false;
      showDataLEDPrevious = false;    
    }
    
  } 
  
}
Key pieces to get this working

Code: Select all

ZUNO_DISABLE(WITH_CC_NOTIFICATION);
Plus the inclusion steps I noted in my code comments
davidtheITGuy
Posts: 25
Joined: 24 Sep 2021 03:55

Re: Multiple channels of the same type (and referencing them in Smartthings)

Post by davidtheITGuy »

Great feedback on all this and I too have this problem. At first I thought it was the way I was instantiating device channels in the sketch like this:

Code: Select all

// set up channels
ZUNO_SETUP_CHANNELS(
  ZUNO_SWITCH_BINARY(getterMasterEnable, setterMasterEnable),                       // this is channel 1: the master enable switch
  ZUNO_SENSOR_MULTILEVEL_HUMIDITY(getterHumidity),                                  // this is channel 2: the device sensor for the ambient humidity
  ZUNO_SWITCH_MULTILEVEL(getterDehumid, setterDehumid),                             // this is channel 3: the slider to set the target dehumidity level
  ZUNO_SWITCH_BINARY(getterRelayEnable, setterRelayEnable)                          // this is channel 4: sensor to pass the value of the dehumidifer relay
);
Note the first and fourth definitions are for BINARY SWITCHES. It doesn't work and the issue is at the Z-Wave internals level. Here is a screenshot of what is created in the Z-Uno MCU (using ZWave JS API viewer to view, see https://github.com/zwave-js for more information):
ZWave_Node_create.png
ZWave_Node_create.png (89.85 KiB) Viewed 2197 times
You can see that only three device values have been created for the Z-Uno including only ONE instance of the Binary Switch.

Moreover, is appears that an attempt to create a multiple device class somehow screws up the api calls on the Z-Uno and at least on my viewer, node interview fails and doesn't return after initial boot (upper right corner is a stuck node interview request on the Z-Uno).

So it appears that the only way to properly use a device class in only once and then use the channels documented here to identify multiple instances. Too bad because it was just be easier to work with multiple device (class) channels.... Thanks all for point me in the right direction.
Post Reply