The problem with channels.

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
sega66
Posts: 38
Joined: 30 Jul 2017 19:31

The problem with channels.

Post by sega66 »

I need to do to Z-Uno 4 temperature sensor DS 18B20 , connect 4 relay and do 2 switches. I wrote this code, but the 2-switch work with a delay of 2 minutes. What did I do wrong? If I leave only the switches 1 and 2 channel, they work fast. I have a Zipato controller.
// 4-ре реле и 4-ре датчика температуры и 2 сенсор
#include <ZUNO_DS18B20.h>
// DS18B20 pin connections
#define PIN_OW 9 // this is s_pin number and it have to be in range[9;16]
OneWire ow(PIN_OW);
DS18B20Sensor sen18b20(&ow);
// use scanAloneSensor() it returns 8-byte unique address of sensor connected to the BUS and fill sensor_addresses. This addresses is unique for any 1-wire device.
#define NUMBER_OF_SENSORS 4
#define ADDR_SIZE 8
// button pin number
#define BTN_1_PIN 22
#define BTN_2_PIN 23
// variable to store current button state
byte lastButtonState1;
byte lastButtonState2;
//==================================================
#define RelePin1 10
#define RelePin2 11
#define RelePin3 12
#define RelePin4 14

#define SWITCH_ON 0xff
#define SWITCH_OFF 0

byte switchValue1 = 0;
byte switchValue2 = 0;
byte switchValue3 = 0;
byte switchValue4 = 0;
//==================================================
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);

byte sensor_addresses[NUMBER_OF_SENSORS * ADDR_SIZE] =
{
0x28, 0x34, 0x32, 0x3B, 0x05, 0x00, 0x00, 0xC1,
0x28, 0x13, 0xB7, 0x3B, 0x05, 0x00, 0x00, 0xEB,
0x28, 0x1E, 0xFF, 0x42, 0x05, 0x00, 0x00, 0x4D,
0x28, 0x43, 0x9C, 0x3B, 0x05, 0x00, 0x00, 0x4D
};

int temp[NUMBER_OF_SENSORS];

ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp0),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp1),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp2),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE, SENSOR_MULTILEVEL_SCALE_CELSIUS, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS, getterTemp3),

ZUNO_SWITCH_BINARY(getterSwitch1, setterSwitch1),
ZUNO_SWITCH_BINARY(getterSwitch2, setterSwitch2),
ZUNO_SWITCH_BINARY(getterSwitch3, setterSwitch3),
ZUNO_SWITCH_BINARY(getterSwitch3, setterSwitch4),

ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_GENERAL_PURPOSE, getter1),
ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_GENERAL_PURPOSE, getter2)
);
unsigned long previousMillis = 0;
const long interval = 60000;

void setup() {
pinMode(BTN_1_PIN, INPUT_PULLUP); // set button pin as input
pinMode(BTN_2_PIN, INPUT_PULLUP); // set button pin as input
//==================================================================
pinMode(RelePin1, OUTPUT);
pinMode(RelePin2, OUTPUT);
pinMode(RelePin3, OUTPUT);
pinMode(RelePin4, OUTPUT);
//=================================================================
}

void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;

byte address[ADDR_SIZE];
// use byte instead of int to reduce code size
for (byte i = 0; i < NUMBER_OF_SENSORS; i++)
{
// Use fixed point math
// get temperature of sensor i from sensor_addresses

for (byte j = 0; j < ADDR_SIZE; j++)
{
address[j] = sensor_addresses[i * ADDR_SIZE + j];
}
temp = sen18b20.getTempC100(address);
zunoSendReport(1 + i);
}
}
byte currenButtonState1 = digitalRead(BTN_1_PIN);
if (currenButtonState1 != lastButtonState1) { // if state changes
lastButtonState1 = currenButtonState1; // save new state
zunoSendReport(1); // send report over the Z-Wave to the controller
}
byte currenButtonState2 = digitalRead(BTN_2_PIN);
if (currenButtonState2 != lastButtonState2) { // if state changes
lastButtonState2 = currenButtonState2; // save new state
zunoSendReport(2); // send report over the Z-Wave to the controller
}
}
word getterTemp0()
{
return temp[0];
}
word getterTemp1()
{
return temp[1];
}
word getterTemp2()
{
return temp[2];
}
word getterTemp3()
{
return temp[3];
}
void setterSwitch1(byte value) {
digitalWrite(RelePin1, (value > 0) ? HIGH : LOW);
switchValue1 = value;
}

byte getterSwitch1() {
return switchValue1;
}
void setterSwitch2(byte value) {
digitalWrite(RelePin2, (value > 0) ? HIGH : LOW);
switchValue2 = value;
}
byte getterSwitch2() {
return switchValue2;
}
void setterSwitch3(byte value) {
digitalWrite(RelePin3, (value > 0) ? HIGH : LOW);
switchValue3 = value;
}
byte getterSwitch3() {
return switchValue3;
}
void setterSwitch4(byte value) {
digitalWrite(RelePin4, (value > 0) ? HIGH : LOW);
switchValue4 = value;
}
byte getterSwitch4() {
return switchValue4;
}
byte getter1() {
if (lastButtonState1 == 0) { // if button is pressed
return 0xff; // return "Triggered" state to the controller
} else { // if button is released
return 0; // return "Idle" state to the controller
}
}
byte getter2() {
if (lastButtonState2 == 0) { // if button is pressed
return 0xff; // return "Triggered" state to the controller
} else { // if button is released
return 0; // return "Idle" state to the controller
}
}
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Re: The problem with channels.

Post by Black Cat »

If I read this right, you want to control 4 relays with 4 sensors and have an additional 2 switches? = 10 channels.

But you only have setup 4 Binary Switches, where I would think you need 6.
The 2 switches have been assigned as ZUNO_Sensor_Binary.


ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_GENERAL_PURPOSE, getter1),
ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_GENERAL_PURPOSE, getter2)
);

rather than ZUNO_SWITCH_BINARY(getterSwitch5, setterSwitch5)
ZUNO_SWITCH_BINARY(getterSwitch6, setterSwitch6)

I have limited knowledge in Z-Uno so this most probably will not the right, but it could be a start.
sega66
Posts: 38
Joined: 30 Jul 2017 19:31

Re: The problem with channels.

Post by sega66 »

I want to control 4 relays, receive data from 4 temperature sensors and have 2 sensors. Only 10 channels. This works, but 2 sensors(ZUNO_SENSOR_BINARY) work with 2-3 minutes delay. If I leave only 2 sensors, then they work out instantly. If I add 4 relays, the sensors work with a delay. How to fix it?
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Re: The problem with channels.

Post by Black Cat »

Set Group Associations maybe?

#define CONTROL_GROUP 1

2-3 minute delay seems to indicate it is waiting on a POLL from your HA Controller (which is?)

I've found Z-Uno to react differently with different HA Controllers, shouldn't be that way but is, otherwise a wiser person needs to step in on this.
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: The problem with channels.

Post by PoltoS »

> ZUNO_SWITCH_BINARY(getterSwitch3, setterSwitch4)
Getter is wrong here

> zunoSendReport(1)
1 and 2 are wrong here - you should use 9 and 10 as those are your sensors channels. This is the reason why you don't get updates, but you have a polling by Zipato gateway as Black Cat suggested
sega66
Posts: 38
Joined: 30 Jul 2017 19:31

Re: The problem with channels.

Post by sega66 »

Thanks, now everything works!
One more question: can I use two or more Z-uno with one zipato controller? Can the channels not interfere with each other?
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: The problem with channels.

Post by PoltoS »

Sure! Each device have its own channels. It is like to use few double switches in one controller - this works perfectly. Zipato have a very good support of multichannel devices.
Post Reply