Dynamic channel configuration not working

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
perjar
Posts: 56
Joined: 08 Apr 2018 18:02

Dynamic channel configuration not working

Post by perjar »

Hello Forum friends,

I am having problems getting the dynamic channel configuration to work properly, I am hoping the forum might have some ideas and pointers to get it right.

What I want to achieve in the end, is a way to control the z-uno from a Python program in a Raspberry Pi.

To make the z-uno code as generic as possible, I decided to explore the concept of dynamically configuring the channels using the macros ZUNO_START_CONFIG(), ZUNO_ADD_CHANNEL(), ZUNO_COMMIT_CONFIG().

My first attempt was to use the sample code "Z-Uno as a modem (AT Commands)". https://z-uno.z-wave.me/examples/z-uno-as-a-modem/

It works to some extent, as long as I only add a maximum of two channels. With more channels, only the first and the last channels are actually configured in the controller, the ones in between are lost.

So, to make sure it was not the sample code that messed it up, I collected all the config commands and put them in a short sketch just to check how setting up the channels works in the controller.

In my example, I am defining two dimmers, one binary switch and two thermometers.

Code 1:

Code: Select all

ZUNO_ENABLE(WITH_CC_SWITCH_MULTILEVEL WITH_CC_METER WITH_CC_SENSOR_BINARY WITH_CC_SWITCH_COLOR WITH_CC_SENSOR_MULTILEVEL WITH_CC_DOORLOCK WITH_CC_SWITCH_BINARY WITH_CC_NOTIFICATION WITH_CC_THERMOSTAT);

ZUNO_DYNAMIC_CHANNELS(32);

void setup() {
  
  ZUNO_START_CONFIG();
  
  // Channel 1 - Switch multilevel
  ZUNO_ADD_CHANNEL(2,0,0);
  
  // Channel 2 - Switch multilevel
  ZUNO_ADD_CHANNEL(2,0,0);

  // Channel 3 - Switch binary
  ZUNO_ADD_CHANNEL(1,0,0);

  // Channel 4 - Thermometer 
  ZUNO_ADD_CHANNEL(4,1,66);

  // Channel 5 - Thermometer 
  ZUNO_ADD_CHANNEL(4,1,66);
  
  ZUNO_COMMIT_CONFIG();
}
Code 1 results in two devices being created in the controller
1 dimmer
1 thermometer.
The other ones are not visible.

So the next thing I tried was to use the ZUNO_SET_ZWCHANNEL() to try to assign each channel explicitly instead. This is what Code 2 is doing. I am using the same model as in the sample code in the z-uno reference: https://z-uno.z-wave.me/Reference/ZUNO_SET_ZWCHANNEL/.

Code 2:

Code: Select all

ZUNO_ENABLE(WITH_CC_SWITCH_MULTILEVEL WITH_CC_METER WITH_CC_SENSOR_BINARY WITH_CC_SWITCH_COLOR WITH_CC_SENSOR_MULTILEVEL WITH_CC_DOORLOCK WITH_CC_SWITCH_BINARY WITH_CC_NOTIFICATION WITH_CC_THERMOSTAT);

ZUNO_DYNAMIC_CHANNELS(32);

#define MAP_TO_ZEROCHANNEL 0x80

void setup() {
  ZUNO_START_CONFIG();
  
  // Channel 1 - Switch multilevel
  ZUNO_SET_ZWCHANNEL(1| MAP_TO_ZEROCHANNEL); 
  ZUNO_ADD_CHANNEL(2,0,0);
  
  // Channel 2 - Switch multilevel
  ZUNO_SET_ZWCHANNEL(MAP_TO_ZEROCHANNEL + 1);
  ZUNO_ADD_CHANNEL(2,0,0);

  // Channel 3 - Switch binary
  ZUNO_SET_ZWCHANNEL(MAP_TO_ZEROCHANNEL + 2);
  ZUNO_ADD_CHANNEL(1,0,0);

  // Channel 4 - Thermometer 
  ZUNO_SET_ZWCHANNEL(MAP_TO_ZEROCHANNEL + 3);
  ZUNO_ADD_CHANNEL(4,1,66);

  // Channel 5 - Thermometer 
  ZUNO_SET_ZWCHANNEL(MAP_TO_ZEROCHANNEL + 4);
  ZUNO_ADD_CHANNEL(4,1,66);
  
  ZUNO_COMMIT_CONFIG();
}
I have to admit I don't understand this thing with the zero channel.
(1 | 0x80) amounts to the same thing as (0x80 +1) so I am essentially assigning the channel twice as I understand it.

Code 2 results in no less than 8 devices being created in the controller:
2 dimmers (both are mapped to channel 1)
1 binary switch (channel 3)
3 thermometers (only one can be controlled). Channel 4 and 5 are mapped to the same device in the controller
2 generic multilevel sensors (unkown channel numbers).

Final attempt is in Code 3 which uses the same approach as code 2, but is based on another sample code which addresses the channels differently. https://z-uno.z-wave.me/examples/multip ... e-sensors/
Here, the first channel is still 0x81 but then it continues with 2,3,4 etc

Code 3:

Code: Select all

ZUNO_ENABLE(WITH_CC_SWITCH_MULTILEVEL WITH_CC_METER WITH_CC_SENSOR_BINARY WITH_CC_SWITCH_COLOR WITH_CC_SENSOR_MULTILEVEL WITH_CC_DOORLOCK WITH_CC_SWITCH_BINARY WITH_CC_NOTIFICATION WITH_CC_THERMOSTAT);

ZUNO_DYNAMIC_CHANNELS(32);

void setup() {
  ZUNO_START_CONFIG();
  
  // Channel 1 - Switch multilevel
  ZUNO_SET_ZWCHANNEL(0x81); 
  ZUNO_ADD_CHANNEL(2,0,0);
  
  // Channel 2 - Switch multilevel
  ZUNO_SET_ZWCHANNEL(2);
  ZUNO_ADD_CHANNEL(2,0,0);

  // Channel 3 - Switch binary
  ZUNO_SET_ZWCHANNEL(3);
  ZUNO_ADD_CHANNEL(1,0,0);

  // Channel 4 - Thermometer 
  ZUNO_SET_ZWCHANNEL(4);
  ZUNO_ADD_CHANNEL(4,1,66);

  // Channel 5 - Thermometer 
  ZUNO_SET_ZWCHANNEL(5);
  ZUNO_ADD_CHANNEL(4,1,66);
  
  ZUNO_COMMIT_CONFIG();
}
Code 3 generates no less than 9 devices in the controller, but they are all marked as "Not configured", so sending and receiving reports don't work.
1 parent device
3 dimmers
1 binary switch
2 thermometers
2 generic multilevel sensors

My controller is a Fibaro Home Center 2 on the latest SW (4.620).

Any ideas what I am doing wrong here?
p0lyg0n1
Posts: 205
Joined: 04 Aug 2016 07:14

Re: Dynamic channel configuration not working

Post by p0lyg0n1 »

Hi,
the first that I have to say that dynamic configuration is one of the most sophisticated topics of ZUno.
The API differs for the 1st and 2nd generation.
Seems you try to write code for the 1st generation of Z-Uno, don't you?

1. About mapping to zero channel. Let's keep it simple as we can. Just map ONLY 1 (ANY one) channel to zero channel. It's a modern way of multichannel device organization for Z-Wave. Fibaro supports only this approach. So your 3-rd example has the right channel mapping.
2. You have to exclude device every time you change its z-wave appearance. ZUNO_COMMIT_CONFIG() works only if NodeId is 0. After inclusion device just loads its previous configuration from EEPROM.
3. I am able to try your code with my Raspberry gateway. I'll fixed if it doesn't work the right way.
4. Maybe these examples will help you a little (they were made for 1st generation) https://github.com/Z-Wave-Me/Z-Uno-Test ... annel_2.15

Best regards,
Alex.
p0lyg0n1
Posts: 205
Joined: 04 Aug 2016 07:14

Re: Dynamic channel configuration not working

Post by p0lyg0n1 »

Hi,
have tried and your code works with my Razberry gateway the right way, I just add loop() and some code to see that the sketch works:

Code: Select all

ZUNO_ENABLE(WITH_CC_SWITCH_MULTILEVEL WITH_CC_METER WITH_CC_SENSOR_BINARY WITH_CC_SWITCH_COLOR WITH_CC_SENSOR_MULTILEVEL WITH_CC_DOORLOCK WITH_CC_SWITCH_BINARY WITH_CC_NOTIFICATION WITH_CC_THERMOSTAT);

ZUNO_DYNAMIC_CHANNELS(32);

void setup() {
  ZUNO_START_CONFIG();
  // Channel 1 - Switch multilevel
  ZUNO_SET_ZWCHANNEL(0x81); 
  ZUNO_ADD_CHANNEL(2,0,0);
  // Channel 2 - Switch multilevel
  ZUNO_SET_ZWCHANNEL(2);
  ZUNO_ADD_CHANNEL(2,0,0);
  // Channel 3 - Switch binary
  ZUNO_SET_ZWCHANNEL(3);
  ZUNO_ADD_CHANNEL(1,0,0);
  // Channel 4 - Thermometer 
  ZUNO_SET_ZWCHANNEL(4);
  ZUNO_ADD_CHANNEL(4,1,66);
  // Channel 5 - Thermometer 
  ZUNO_SET_ZWCHANNEL(5);
  ZUNO_ADD_CHANNEL(4,1,66);
  
  ZUNO_COMMIT_CONFIG();

  pinMode(13, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);

  // Start dimmers values
  g_channels_data[0].bParam = 10;
  g_channels_data[1].bParam = 30;
  // Start switch value
  g_channels_data[2].bParam = 0;
  // Test temperature values
  g_channels_data[3].wParam = 2450; // 24.5
  g_channels_data[4].wParam = 2210; // 22.1
  // Report them to controller
  zunoSendReport(4); // channels indexes are 1-based
  zunoSendReport(5);

}
void loop(){
    analogWrite(13, g_channels_data[0].bParam);
    analogWrite(14, g_channels_data[1].bParam);
    analogWrite(15, g_channels_data[2].bParam);
}
Please not this code is only for the 1st generation.
If you need the same example for the second generation of Z-Uno I can share it here too.
Attachments
Снимок экрана 2022-01-12 в 23.12.12.png
Снимок экрана 2022-01-12 в 23.12.12.png (213.83 KiB) Viewed 166 times
perjar
Posts: 56
Joined: 08 Apr 2018 18:02

Re: Dynamic channel configuration not working

Post by perjar »

p0lyg0n1 wrote:
12 Jan 2022 22:29
Hi,
the first that I have to say that dynamic configuration is one of the most sophisticated topics of ZUno.
The API differs for the 1st and 2nd generation.
Seems you try to write code for the 1st generation of Z-Uno, don't you?

1. About mapping to zero channel. Let's keep it simple as we can. Just map ONLY 1 (ANY one) channel to zero channel. It's a modern way of multichannel device organization for Z-Wave. Fibaro supports only this approach. So your 3-rd example has the right channel mapping.
2. You have to exclude device every time you change its z-wave appearance. ZUNO_COMMIT_CONFIG() works only if NodeId is 0. After inclusion device just loads its previous configuration from EEPROM.
3. I am able to try your code with my Raspberry gateway. I'll fixed if it doesn't work the right way.
4. Maybe these examples will help you a little (they were made for 1st generation) https://github.com/Z-Wave-Me/Z-Uno-Test ... annel_2.15

Best regards,
Alex.
Thank you so much for testing the code and for the advice. Much appreciated!

You are right, I am using a 1st z-uno. If you have code to share for 2nd get I would be happy to take it in. I presume that coming purchases will be for gen 2. I have searched the reference documention for any mention of differences between gen 1 and 2 but can't find a single word on the topic. I do hope that the makers of Z-uno will spend some time on updating the documentation to keep it coherent and accurate.

Thanks for sorting out the zero channel situation. I only wish that the reference documentation could mention this sort if thing. Normally, channels are referenced as 1,2,3,4 etc. And then suddenly, for ZUNO_SET_ZWCHANNEL, we should use 0x81 for channel 0 and 1. It is not consistent, and the documentation should address this. :|

I also found that the sequence of things in the exclude/include procedure is really key when working with dynamic channels. I had big problems getting my new dynamic configs to stick, and found that it is critical to exclude before I run a new config. Your tip #2 explains why this is the case. Thanks! Again, something which is not explained in the docs. It is quite the opposite actually. The documentation says that exclusion/inclusion is needed after changing the channels. The procedure is actually:
1. Exclude
2. Change the channels
3. Include

I am still having problems with the code (trying your new code as well). In setup(), g_channels_data variable is set and this is refelcted in the controller right away, no need to call zunoSendReport() apparently. If I do the same in loop(), nothing is sent to the controller, not even if I call zunoSendReport(). The end result is that it is possible to send updated from HC2 to z-uno, but not from z-uno to HC2.

So, it seems Hc2 is not working as smoothly as Razberry.

HC2 also marks the devices as "Not configured" in the user interface, there is apparently something amiss here.
Fibaro HC2.png
Fibaro HC2.png (66 KiB) Viewed 144 times
I am also getting these extra sensor devices that can't be set or read is seems. Not a big issue, they can be hidden, but I do wonder why the show up in the first place.

An observation regarding the g_channels_data variable:
The documentation mentions that we should use bParam, wParam and dwParam depending on the size of the value (1,2 or 4 bytes).
The sample code in zuno_moden.ino ignores this and simply uses dwParam for all channels, both when sending and receiving. And this seems to work just fine too. This is the code : https://github.com/Z-Wave-Me/Z-Uno-Test ... _modem.ino
Post Reply