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.
jemenake
Posts: 15
Joined: 01 Mar 2020 20:50

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

Post by jemenake »

I'm just starting out with Zuno, and I'm trying to make a device which can control 4 relays. Although I'm sure I could configure the Zuno as a dimmer (and just use the dim-level as a bitmap for which relays should be on/off) or a color bulb (and I still might end up doing it this way, for reasons I'll explain below), I wanted to see if it was possible to do it the "right" way by setting up four channels, all of them ZUNO_SWITCH_BINARY.

In one of the code samples in the quick-start guide, they show how to setup multiple channels:

Code: Select all

ZUNO_SETUP_CHANNELS(
ZUNO_SWITCH_BINARY(getterLED, setterLED),
ZUNO_SWITCH_MULTILEVEL(getterDimmer, setterDimmer),
ZUNO_SENSOR_BINARY_GENERAL_PURPOSE(getterButton)
);
but I noticed that all of the channels are different. It is not clear to me if the multiple channels can be identical (and then the Z-Wave protocol has some way for the controller to address a certain channel by number) or if the protocol only has a way to address certain "capabilities" (i.e. a device either has a single "binary switch" capability or it doesn't, and if it does, a controller asks to talk to that device's "binary switch").

Is it possible to do something like:

Code: Select all

ZUNO_SETUP_CHANNELS(
ZUNO_SWITCH_BINARY(getter1, setter1),
ZUNO_SWITCH_BINARY(getter2, setter2),
ZUNO_SWITCH_BINARY(getter3, setter3)
);
If so...
  • how would you select which switch you wanted to control from a Smartthings device-handler? I can't find any mention of a "channel number" in their methods for constructing a Z-wave message.
  • Is there a way for the getter/setter to discover the channel number they were activated with? If so, you can have multiple channels share a single getter/setter pair (because they can figure out, from the channel number, which switch is being set/queried). Something like:

    Code: Select all

    void setter(byte value) {
      int switch_num = get_channel();
      digitalWrite(switch_num, (value==0)?LOW:HIGH);
    }
    
    If there isn't a way to do this, then it's probably best to have the Zuno pretend to be a dimmer, so that the desired value of all of the relays can be encoded as a bitmap in the dimmer value and you can use a single getter/setter.
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

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

Post by PoltoS »

You can specify same type of channels many times. You will have multiple switches binded to corresponding getters and setters.

You can also use dynamic channel concept to have all in one handler function. See documentation. But this requires more programming skills.

But please not that new smarthings approach requires you to write device handler to handle channels and map them to controls
C.Scavardo
Posts: 5
Joined: 25 May 2020 20:32

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

Post by C.Scavardo »

Hi,
Sure, it works for ZUNO_SWITCH_BINARY, I did it, to get/set 2 LEDs linked to the Z-Uno.

Code: Select all

 ZUNO_SETUP_CHANNELS(
  ZUNO_SWITCH_BINARY(getterLed1, setterLed1),
  ZUNO_SWITCH_BINARY(getterLed2, setterLed2)
);
From my Z-Wave controller, the eedomus, I can turn on or turn them off. The status is correctly updated in the eedomus box.

But, my next step was to connect 2 buttons, INPUT_PULLUP mode, to the Z-UNO, using:

Code: Select all

  ZUNO_SETUP_CHANNELS(
                    ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_DOOR_WINDOW,getterButton1),
                    ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_DOOR_WINDOW,getterButton2));
That seems working, when I print to the serial monitor of the IDE, but, it does not work from the Z-Wave controller eedomus point of view.

It works only with 1 channel "ZUNO_SENSOR_BINARY", the status is correctly updated in the Z-Wave controller.
But, when I add a second channel, for a second press button, the Z-Wave controller looks not notified when the button state changed.
When the Z-Wave controller does the polling, the status is correct.
I don't know why the press button state is not automatically updated in the eedomus...
Why does it work with 1 press button, and not with 2...
Gbajolet
Posts: 12
Joined: 29 Apr 2020 13:14

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

Post by Gbajolet »

Hello, I also find some similar problem with eedomus, I didn’t succeed to add some BINARY SENSOR , nothing appears...
I shall follow your exchanges...
Gilles
ianakapilotlight
Posts: 7
Joined: 18 Nov 2017 13:06

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

Post by ianakapilotlight »

C.Scavardo wrote:
25 May 2020 21:05
Hi,
Sure, it works for ZUNO_SWITCH_BINARY, I did it, to get/set 2 LEDs linked to the Z-Uno.

Code: Select all

 ZUNO_SETUP_CHANNELS(
  ZUNO_SWITCH_BINARY(getterLed1, setterLed1),
  ZUNO_SWITCH_BINARY(getterLed2, setterLed2)
);
From my Z-Wave controller, the eedomus, I can turn on or turn them off. The status is correctly updated in the eedomus box.

But, my next step was to connect 2 buttons, INPUT_PULLUP mode, to the Z-UNO, using:

Code: Select all

  ZUNO_SETUP_CHANNELS(
                    ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_DOOR_WINDOW,getterButton1),
                    ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_DOOR_WINDOW,getterButton2));
That seems working, when I print to the serial monitor of the IDE, but, it does not work from the Z-Wave controller eedomus point of view.

It works only with 1 channel "ZUNO_SENSOR_BINARY", the status is correctly updated in the Z-Wave controller.
But, when I add a second channel, for a second press button, the Z-Wave controller looks not notified when the button state changed.
When the Z-Wave controller does the polling, the status is correct.
I don't know why the press button state is not automatically updated in the eedomus...
Why does it work with 1 press button, and not with 2...
Hello, I am having the same problem. Did you find a fix for this?
jemenake
Posts: 15
Joined: 01 Mar 2020 20:50

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

Post by jemenake »

ianakapilotlight wrote:
12 Jun 2021 18:16
Hello, I am having the same problem. Did you find a fix for this?
I did, actually (and I meant to create a YouTube video showing how, but I moved on to the next shiny object)

First, look at Eric Maycock's post about the Qubino stuff https://community.smartthings.com/t/rel ... mmer/79618, giving special attention to the qubino-flush-2-relays parthttps://github.com/erocm123/SmartThings ... ays.groovy.

Near the bottom, he has a function called "createChildDevices" which gets called whenever the DTH gets installed or updated. It turns out that your DTH can create/delete child devices. They appear as completely separate devices (so you can name them different things, set up different rules for each one, etc), but their communication with the hub go through your DTH.

The idea is that wave events that the hub receives will all get passed to your main DTH, and it's that DTH's responsibility to detect that it's a multi-channel command, figure out the channel, and notify the child device. It does that by creating a zwave event with the child's network ID. The network ID's for the child devices are chosen at the time you create them with addChildDevice(...). What Eric did (and I copied) was to just put a suffix on the main device's DNI (since we know that's already unique, so different suffixes should also be unique). You see this in his code with "${device.deviceNetworkId}-ep${i}". I guess the "-ep" part is for "end-point".

So, you end up with device ID's like: "2C", "2C-ep2", "2C-ep3", etc. Note: I handled the first switch in my main DTH and the others in child switches (which is why the first switch's DNI doesn't have a suffix; it just has the DNI of the main DTH). I think Eric creates a child DNI for all of his switches.

So, that's how you get events to your child devices (so that they properly update their on/off status). How do you get events from your child DTH to the hub? I guess you could have them create zwave events by themselves, but it creates duplication of code. If you look at Eric's child-device code https://github.com/erocm123/SmartThings ... ice.groovy, you'll see that he just has his on() and off() methods just call a method in the parent DTH with something like "parent.childOn(device.deviceNetworkId)". It's important that the DNI be passed along, since that's the only way the parent DTH will know which of the child devices needs to be turned on/off.

Although Eric wrote his own child-switch DTH, I think there's one that does the same thing built into the Smartthings IDE called "Child Switch" which does the same thing. That's the one I use. If you needed child devices of more-exotic stuff (like child RGBW bulbs, say), you might have to write your own child DTH like Eric did.

From there, your parent DTH gets these requests using the DNI you made (with suffixes) when you created the child devices. You need to turn these into a zwave channel, and you can see Eric do this in his "channelNumber(String $dni)" method. Once you have converted the child's DNI into the zwave channel, you can send the basicSet() zwave messages you see in his childOn() and childOff() methods.

If it helps you at all, here's the one I'm currently using: https://gist.github.com/jemenake/a25eb1 ... 3f9c6bd538. It's a little more basic (it's a switch-only, uses the built-in "Child Switch" DTH, etc.) but it's probably easier to wrap your head around for a start.

Let me know if that helps, or if you need more explanation.
ianakapilotlight
Posts: 7
Joined: 18 Nov 2017 13:06

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

Post by ianakapilotlight »

jemenake wrote:
12 Jun 2021 21:41
Let me know if that helps, or if you need more explanation.
I think you misunderstood the problem. I too can only receive reports from one binary sensor. Sensor one works as expected, but Sensor two fails to work. My Zwave controller is a Fibaro HC2 with the most up-to-date firmware, my Z-Uno has version 2.1.7 firmware too. I have so far lost a week trying to find out why it wont work.

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
 */
 
// LED pin number
#define ZONE1_LED     13
#define ZONE5_LED     14
#define DATA_LED      15

// 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;
byte lastZone1State = 0;
byte lastZone5State = 0;

byte zone1State = 0;
byte zone5State = 0;

ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);

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

// 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(LED_BUILTIN, OUTPUT);
  
  pinMode(ZONE1_LOOP, INPUT);
  pinMode(ZONE5_LOOP, INPUT);
}

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

  if (currentZone1State != lastZone1State) { // if state changes
    Serial.print("Zone 1 Changed ");
    lastZone1State = currentZone1State; // save new state
    showDataLED = true;
    if (currentZone1State == LOW) { // if button is pressed
      digitalWrite(ZONE1_LED, HIGH);  // shine the LED
      Serial.println("HIGH");
      zone1State = 0;
    } else {                        // if button is released
      digitalWrite(ZONE1_LED, LOW);   // turn the LED off
      Serial.println("LOW");
      zone1State = 255;
    }
    zunoSendReport(1); // send report over the Z-Wave to the controller
  }

  
  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, HIGH);  // shine the LED
      Serial.println("HIGH");
      zone5State = 0;
    } else {                        // if button is released
      digitalWrite(ZONE5_LED, LOW);   // turn the LED off
      Serial.println("LOW");
      zone5State = 255;
    }
    zunoSendReport(2); // send report over the Z-Wave to the controller
  }

  if (showDataLED) {
    showDataLED = false;
    digitalWrite(DATA_LED, HIGH);
    digitalWrite(LED_BUILTIN, HIGH);  
  } 

  delay(1000);
  digitalWrite(DATA_LED, LOW);
  digitalWrite(LED_BUILTIN, LOW);
}
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

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

Post by petergebruers »

Try to change the associations, the "M" and "S" columns on HC2 are important, but unfortunately at the moment I can not re-check what I wrote earlier about this, because my HC2 is disconnected

See https://forum.z-wave.me/viewtopic.php?f=3427&t=32910
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:
12 Jun 2021 22:26
Try to change the associations, the "M" and "S" columns on HC2 are important
I had a look at the post you identified. S, M, makes no sense. Even uploading the sketch for the 8 binary sensors, excluding, including, setting M only. Still doesn't work most annoying. Are these simply not Fibaro HC2 compatible?
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

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

Post by petergebruers »

The Z-Wave specification is not a single standard, frozen in time. It evolves. The specification, in total, is more than 1000 pages... There is room for interpretation. Z-Uno is unique because it allows you to make "arbitrary devices" that do not resemble anything else. Blame Fibaro, blame Z-Wave.me, if something does not work, it won't help.

I own several Z-Uno and have used them in different combinations - most combinations work for me, but you can definitely find stuff that does not work on HC or any other controller for that matter. To complicate the situation, try to add S0 (or S2 security, but HC2 HC3 do not support this at the moment), this changes compatibility, again!

To an end user, "S, M, makes no sense" indeed, it is a disadvantage of having a specification that tries to be compatible with > 10 year old devices... For a tech guy, M and S make a lot of sense.

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.
Post Reply