Door/Window magnetic sensors

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
04greg1980
Posts: 20
Joined: 26 Aug 2016 11:43

Door/Window magnetic sensors

Post by 04greg1980 » 14 Oct 2016 08:30

Hello,
I try to use 10 door/window magnetic sensors with z-uno.
I have write this code:

Code: Select all

/* 
 * This scretch was certified by the Z-Wave Alliance as one of the two reference Z-Uno sketches.
 * 
 * 10 door sensor
 * 
 */

// Pins definitions
#define DoorPin1 1
#define DoorPin2 2
#define DoorPin3 3
#define DoorPin4 4
#define DoorPin5 5
#define DoorPin6 6
#define DoorPin7 7
#define DoorPin8 8
#define DoorPin9 9
#define DoorPin10 10

// Global variables to store data reported via getters

byte lastDoorValue1 = 0;
byte lastDoorValue2 = 0;
byte lastDoorValue3 = 0;
byte lastDoorValue4 = 0;
byte lastDoorValue5 = 0;
byte lastDoorValue6 = 0;
byte lastDoorValue7 = 0;
byte lastDoorValue8 = 0;
byte lastDoorValue9 = 0;
byte lastDoorValue10 = 0;

ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);

ZUNO_SETUP_ASSOCIATIONS(ZUNO_ASSOCIATION_GROUP_SET_VALUE); // Send Basic Set to association group

// Set up 10 channels
ZUNO_SETUP_CHANNELS(
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor1)
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor2)
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor3)
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor4)
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor5)
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor6)
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor7)
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor8)
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor9)
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor10)
);

void setup() {
  // set up I/O pins. Analog and PWM will be automatically set up on analogRead/analogWrite functions call
  pinMode(DoorPin1, INPUT_PULLUP);
  pinMode(DoorPin2, INPUT_PULLUP);
  pinMode(DoorPin3, INPUT_PULLUP);
  pinMode(DoorPin4, INPUT_PULLUP);
  pinMode(DoorPin5, INPUT_PULLUP);
  pinMode(DoorPin6, INPUT_PULLUP);
  pinMode(DoorPin7, INPUT_PULLUP);
  pinMode(DoorPin8, INPUT_PULLUP);
  pinMode(DoorPin9, INPUT_PULLUP);
  pinMode(DoorPin10, INPUT_PULLUP);
}

void loop() {
  byte currentDoorValue1;
  byte currentDoorValue2;
  byte currentDoorValue3;
  byte currentDoorValue4;
  byte currentDoorValue5;
  byte currentDoorValue6;
  byte currentDoorValue7;
  byte currentDoorValue8;
  byte currentDoorValue9;
  byte currentDoorValue10;

  // Door/Window sensor
  currentDoorValue1 = digitalRead(DoorPin1); 
  if (currentDoorValue1 != lastDoorValue1) { 
    lastDoorValue1 = currentDoorValue1;
    zunoSendReport(10);
    }
  // Door/Window sensor
  currentDoorValue2 = digitalRead(DoorPin2); 
  if (currentDoorValue2 != lastDoorValue2) { 
    lastDoorValue2 = currentDoorValue2;
    zunoSendReport(2);
    }
    // Door/Window sensor
  currentDoorValue3 = digitalRead(DoorPin3); 
  if (currentDoorValue3 != lastDoorValue3) { 
    lastDoorValue3 = currentDoorValue3;
    zunoSendReport(3);
    }
   // Door/Window sensor
  currentDoorValue4 = digitalRead(DoorPin4); 
  if (currentDoorValue4 != lastDoorValue4) { 
    lastDoorValue4 = currentDoorValue4;
    zunoSendReport(4);
    }
   // Door/Window sensor
  currentDoorValue5 = digitalRead(DoorPin5); 
  if (currentDoorValue5 != lastDoorValue5) { 
    lastDoorValue5 = currentDoorValue5;
    zunoSendReport(5);
    }
 // Door/Window sensor
  currentDoorValue6 = digitalRead(DoorPin6); 
  if (currentDoorValue6 != lastDoorValue6) { 
    lastDoorValue6 = currentDoorValue6;
    zunoSendReport(6);
    }
  // Door/Window sensor
  currentDoorValue7 = digitalRead(DoorPin7); 
  if (currentDoorValue7 != lastDoorValue7) { 
    lastDoorValue7 = currentDoorValue7;
    zunoSendReport(7);
    }
    // Door/Window sensor
  currentDoorValue8 = digitalRead(DoorPin8); 
  if (currentDoorValue8 != lastDoorValue8) { 
    lastDoorValue8 = currentDoorValue8;
    zunoSendReport(8);
    }
   // Door/Window sensor
  currentDoorValue9 = digitalRead(DoorPin9); 
  if (currentDoorValue9 != lastDoorValue9) { 
    lastDoorValue9 = currentDoorValue9;
    zunoSendReport(9);
    }
   // Door/Window sensor
  currentDoorValue10 = digitalRead(DoorPin10); 
  if (currentDoorValue10 != lastDoorValue10) { 
    lastDoorValue10 = currentDoorValue10;
    zunoSendReport(10);
 }} 
// Getters and setters
byte getterDoor(void) {
  return lastDoorValue1 ? 0xff : 0;
}
I'm sorry because I'm a dummy and I have this error during compilation:
Arduino: 1.6.5 (Mac OS X), Board: "Z-Wave>ME Z-Uno, Europe, Enabled, Enabled"

Build options changed, rebuilding all

/Users/Michel/Library/Arduino15/packages/Z-Uno/tools/zuno_toolchain/00.08.10/zuno_toolchain/compiler build /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/doorsensorzuno.cpp -r /Users/Michel/Library/Arduino15/packages/Z-Uno/hardware/zw8051/2.0.6

************* Building Arduino Sketch *************
/var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/doorsensorzuno.cpp
***************************************************

Preprocessing file: /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/Print.cpp with SDCPP...
Compiling /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/Print_sdcpp_.cpp ...
Preprocessing file: /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/Stream.cpp with SDCPP...
Compiling /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/Stream_sdcpp_.cpp ...
Preprocessing file: /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/HardwareSerial.cpp with SDCPP...
Compiling /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/HardwareSerial_sdcpp_.cpp ...
Preprocessing file: /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/HLCore.cpp with SDCPP...
Compiling /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/HLCore_sdcpp_.cpp ...
Preprocessing file: /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/_doorsensorzuno.cpp with SDCPP...
Compiling /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/_doorsensorzuno_sdcpp_.cpp ...
Preprocessing file: /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/Print.cpp with SDCPP...
Compiling /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/Print_sdcpp_.cpp ...
Preprocessing file: /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/Stream.cpp with SDCPP...
Compiling /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/Stream_sdcpp_.cpp ...
Preprocessing file: /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/HardwareSerial.cpp with SDCPP...
Compiling /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/HardwareSerial_sdcpp_.cpp ...
Preprocessing file: /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/HLCore.cpp with SDCPP...
Compiling /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/HLCore_sdcpp_.cpp ...
Preprocessing file: /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/_doorsensorzuno.cpp with SDCPP...
Compiling /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/_doorsensorzuno_sdcpp_.cpp ...Compiling file "/var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/LLCore_arduino.c" by means of SDCC...
at 1: warning 119: don't know what to do with file ''. file extension unsupported
sdcc: Calling preprocessor...
sdcc: sdcpp -nostdinc -Wall -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_MODEL_LARGE -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=3_5_0 -DSDCC=350 -D__SDCC_REVISION=9253 -D__SDCC_mcs51 -D__STDC_NO_COMPLEX__ -D__STDC_NO_THREADS__ -D__STDC_NO_ATOMICS__ -D__STDC_NO_VLA__ -isystem /Users/Michel/Library/Arduino15/packages/Z-Uno/tools/zuno_toolchain/00.08.10/zuno_toolchain/sdcc//bin/../share/sdcc/include/mcs51 -isystem /usr/local/share/sdcc/include/mcs51 -isystem /Users/Michel/Library/Arduino15/packages/Z-Uno/tools/zuno_toolchain/00.08.10/zuno_toolchain/sdcc//bin/../share/sdcc/include -isystem /usr/local/share/sdcc/include /var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/LLCore_arduino.c
sdcc: Generating code...
/var/folders/h8/rk4jqb61489clkyncw9s2ppm0000gn/T/build3283161571940803437.tmp/Custom.h:16: syntax error: token -> '{' ; column 198
Error. SDCC returned: 1

Error compiling.
Do you have any ideas to solve this error?
Thanks a lot
Greg

A.Harrenberg
Posts: 200
Joined: 05 Sep 2016 22:27

Re: Door/Window magnetic sensors

Post by A.Harrenberg » 14 Oct 2016 21:57

Hi,

I changed your code and it compiles now:

First change, the different parameters to ZUNO_SETUP_CHANNELS() need to be seperated by ",",
Second change, all the declared getter functions (in the SETUP_CHANNELS definition) need to be in the code
Third, fixed a typo in loop(), in the first part you are evaluation a change to currentDoorValue1 but send the report for channel 10...

For the first change, I propose you to reformat the line with ZUNO_SETUP_CHANNELS() so that it is one long line. It is a littel bit ugly, but if you use it like this, the line number reported in case of an error are not correct. This will be fixed in a future release, but for now it will create some sort of an offset for the reported line numbers.

Kind regards,
Andreas.

Code: Select all

[code]
/*
 * This scretch was certified by the Z-Wave Alliance as one of the two reference Z-Uno sketches.
 *
 * 10 door sensor
 *
 */

// Pins definitions
#define DoorPin1 1
#define DoorPin2 2
#define DoorPin3 3
#define DoorPin4 4
#define DoorPin5 5
#define DoorPin6 6
#define DoorPin7 7
#define DoorPin8 8
#define DoorPin9 9
#define DoorPin10 10

// Global variables to store data reported via getters

byte lastDoorValue1 = 0;
byte lastDoorValue2 = 0;
byte lastDoorValue3 = 0;
byte lastDoorValue4 = 0;
byte lastDoorValue5 = 0;
byte lastDoorValue6 = 0;
byte lastDoorValue7 = 0;
byte lastDoorValue8 = 0;
byte lastDoorValue9 = 0;
byte lastDoorValue10 = 0;

ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);

ZUNO_SETUP_ASSOCIATIONS(ZUNO_ASSOCIATION_GROUP_SET_VALUE); // Send Basic Set to association group

// Set up 10 channels
ZUNO_SETUP_CHANNELS(
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor1),
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor2),
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor3),
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor4),
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor5),
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor6),
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor7),
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor8),
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor9),
  ZUNO_SENSOR_BINARY_DOOR_WINDOW(getterDoor10)
);

void setup() {
  // set up I/O pins. Analog and PWM will be automatically set up on analogRead/analogWrite functions call
  pinMode(DoorPin1, INPUT_PULLUP);
  pinMode(DoorPin2, INPUT_PULLUP);
  pinMode(DoorPin3, INPUT_PULLUP);
  pinMode(DoorPin4, INPUT_PULLUP);
  pinMode(DoorPin5, INPUT_PULLUP);
  pinMode(DoorPin6, INPUT_PULLUP);
  pinMode(DoorPin7, INPUT_PULLUP);
  pinMode(DoorPin8, INPUT_PULLUP);
  pinMode(DoorPin9, INPUT_PULLUP);
  pinMode(DoorPin10, INPUT_PULLUP);
}

void loop() {
  byte currentDoorValue1;
  byte currentDoorValue2;
  byte currentDoorValue3;
  byte currentDoorValue4;
  byte currentDoorValue5;
  byte currentDoorValue6;
  byte currentDoorValue7;
  byte currentDoorValue8;
  byte currentDoorValue9;
  byte currentDoorValue10;

  // Door/Window sensor
  currentDoorValue1 = digitalRead(DoorPin1);
  if (currentDoorValue1 != lastDoorValue1) {
    lastDoorValue1 = currentDoorValue1;
    zunoSendReport(1);
  }
  // Door/Window sensor
  currentDoorValue2 = digitalRead(DoorPin2);
  if (currentDoorValue2 != lastDoorValue2) {
    lastDoorValue2 = currentDoorValue2;
    zunoSendReport(2);
  }
  // Door/Window sensor
  currentDoorValue3 = digitalRead(DoorPin3);
  if (currentDoorValue3 != lastDoorValue3) {
    lastDoorValue3 = currentDoorValue3;
    zunoSendReport(3);
  }
  // Door/Window sensor
  currentDoorValue4 = digitalRead(DoorPin4);
  if (currentDoorValue4 != lastDoorValue4) {
    lastDoorValue4 = currentDoorValue4;
    zunoSendReport(4);
  }
  // Door/Window sensor
  currentDoorValue5 = digitalRead(DoorPin5);
  if (currentDoorValue5 != lastDoorValue5) {
    lastDoorValue5 = currentDoorValue5;
    zunoSendReport(5);
  }
  // Door/Window sensor
  currentDoorValue6 = digitalRead(DoorPin6);
  if (currentDoorValue6 != lastDoorValue6) {
    lastDoorValue6 = currentDoorValue6;
    zunoSendReport(6);
  }
  // Door/Window sensor
  currentDoorValue7 = digitalRead(DoorPin7);
  if (currentDoorValue7 != lastDoorValue7) {
    lastDoorValue7 = currentDoorValue7;
    zunoSendReport(7);
  }
  // Door/Window sensor
  currentDoorValue8 = digitalRead(DoorPin8);
  if (currentDoorValue8 != lastDoorValue8) {
    lastDoorValue8 = currentDoorValue8;
    zunoSendReport(8);
  }
  // Door/Window sensor
  currentDoorValue9 = digitalRead(DoorPin9);
  if (currentDoorValue9 != lastDoorValue9) {
    lastDoorValue9 = currentDoorValue9;
    zunoSendReport(9);
  }
  // Door/Window sensor
  currentDoorValue10 = digitalRead(DoorPin10);
  if (currentDoorValue10 != lastDoorValue10) {
    lastDoorValue10 = currentDoorValue10;
    zunoSendReport(10);
  }
}

// Getters and setters

byte getterDoor1(void) {
  return lastDoorValue1 ? 0xff : 0;
}
byte getterDoor2(void) {
  return lastDoorValue2 ? 0xff : 0;
}
byte getterDoor3(void) {
  return lastDoorValue3 ? 0xff : 0;
}
byte getterDoor4(void) {
  return lastDoorValue4 ? 0xff : 0;
}
byte getterDoor5(void) {
  return lastDoorValue5 ? 0xff : 0;
}
byte getterDoor6(void) {
  return lastDoorValue6 ? 0xff : 0;
}
byte getterDoor7(void) {
  return lastDoorValue7 ? 0xff : 0;
}
byte getterDoor8(void) {
  return lastDoorValue8 ? 0xff : 0;
}
byte getterDoor9(void) {
  return lastDoorValue9 ? 0xff : 0;
}
byte getterDoor10(void) {
  return lastDoorValue10 ? 0xff : 0;
}

[/code]
fhem.de - ZWave development support

ocram84
Posts: 2
Joined: 14 Oct 2016 23:53

Re: Door/Window magnetic sensors

Post by ocram84 » 15 Oct 2016 00:06

Hi, I would like to do the same and connect it to Fibaro Hc2 to read the state of 8 windows magnetic sensors.
Could you tell me where to connect the 16 wires to the z uno board? I think 9 connections to the board, 8 sensors and 1 common..correct?
Thanks

04greg1980
Posts: 20
Joined: 26 Aug 2016 11:43

Re: Door/Window magnetic sensors

Post by 04greg1980 » 15 Oct 2016 01:24

Hello,
Thanks a lot A.Harrenberg. I'm a new user and I'm not yet a good programmer, I'm so sorry.
I have try to had z-uno in a Fibaro HC2 controller, but I have only the first door magnetic sensor running. The 9 others are not seen by fibaro HC2. Have you a solution?
Capture d’écran 2016-10-15 à 00.25.04.png
Capture d’écran 2016-10-15 à 00.25.04.png (78.51 KiB) Viewed 1262 times
Thanks for your help.
See you soon
Greg

A.Harrenberg
Posts: 200
Joined: 05 Sep 2016 22:27

Re: Door/Window magnetic sensors

Post by A.Harrenberg » 15 Oct 2016 10:51

Hi Greg,
04greg1980 wrote:Hello,
I have try to had z-uno in a Fibaro HC2 controller, but I have only the first door magnetic sensor running. The 9 others are not seen by fibaro HC2. Have you a solution?
I am sorry, but I am not using a Fibaro system and can't help you here. I can't even test the sketch here on my system as I have setup all my connected sensors im system and I would loose most of that configuration if I exclude the Z-Uno from my system now.

But from just looking at the sketch, it should run and there should be 10 Sub-device, but I don't know how the Fibaro system is presenting that to the user.

Can you try the 10channel example from the website and see whether more channels are showing up in Fibaro with this expample?

I will order another Z-Uno, so that I will again have something to play with... :-)

@ocram84: Maybe you can also test the sketch and see how many channels you see in your system?

Regards,
Andreas.
fhem.de - ZWave development support

A.Harrenberg
Posts: 200
Joined: 05 Sep 2016 22:27

Re: Door/Window magnetic sensors

Post by A.Harrenberg » 15 Oct 2016 11:04

Hi ocram84,
ocram84 wrote: Could you tell me where to connect the 16 wires to the z uno board? I think 9 connections to the board, 8 sensors and 1 common..correct?
Thanks
the sketch from Greg is setup to use:

Code: Select all

// Pins definitions
#define DoorPin1 1
#define DoorPin2 2
#define DoorPin3 3
...
the defintion of the pin numbers was included in the Z-Uno (just a small piece of paper) or can be viewed online here.

Code: Select all

  pinMode(DoorPin1, INPUT_PULLUP);
  pinMode(DoorPin2, INPUT_PULLUP);
  pinMode(DoorPin3, INPUT_PULLUP);
  ...
The "mode" of the pins are set to "INPUT_PULLUP", which means that the pin is internally "powered" and that the connected switch need be "open" to generate a 1 (High-level) and need to connect the pin to ground to generate a 0 (Low-level).

As Greg currently has problems that only one channel is shown in Fibaro HC2 and you are also using this system, can you maybe try the sketch I have posted and see whether you get the same result?

Regards,
Andreas.
fhem.de - ZWave development support

User avatar
PoltoS
Posts: 3734
Joined: 26 Jan 2011 19:36

Re: Door/Window magnetic sensors

Post by PoltoS » 15 Oct 2016 11:33

@Greg, make sure to exclude Z-Uno and include back to let it apply the sketch.

What is the version of your HC?

04greg1980
Posts: 20
Joined: 26 Aug 2016 11:43

Re: Door/Window magnetic sensors

Post by 04greg1980 » 15 Oct 2016 15:17

Hello
Thanks for your answer.
I have correctly remove the z-uno of the HC2. I have applied sketch and associate as a new module into HC2.
I have the last version of HC2: 4.100.
Have you an idea to correct my problem?
Thanks a lot
Greg

User avatar
PoltoS
Posts: 3734
Joined: 26 Jan 2011 19:36

Re: Door/Window magnetic sensors

Post by PoltoS » 15 Oct 2016 15:43

No idea yet. We have not tested yet this latest HC2 fw.

ocram84
Posts: 2
Joined: 14 Oct 2016 23:53

Re: Door/Window magnetic sensors

Post by ocram84 » 15 Oct 2016 22:48

I haven't got a board yet to make test.
Thanks

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests