Page 1 of 1

Help with a (probably very easy) button sketch!

Posted: 22 May 2017 17:10
by n0ir
Hi!

I want to build a battery powered wall switch. I want to use the status of the wall switch as a trigger in my controller (Vera) to start scenes. If possible, I would like to use a momentary button instead of a toggle button.

The "Battery powered wall switch" sketch (https://z-uno.z-wave.me/examples/batter ... ll-switch/) is too complicated, I do not want to use associations.

Could someone please help me find or write a sketch that send the status of a wall switch button to a controller?

The wall switch will be battery powered (2xAA) so some kind of sleep mode function would be appreciated.

Re: Help with a (probably very easy) button sketch!

Posted: 22 May 2017 18:36
by n0ir
Nexa have a 433MHz device caled WBT-912 (Two Channel Transmitter) that can be connected to a wall switch to make a battery powered remote. It's the same thing I want but it uses 433MHz instead of Z-Wave.

Is it possible to build something similar using Z-Uno?

https://translate.google.se/translate?h ... %2Fwbt-912

Re: Help with a (probably very easy) button sketch!

Posted: 24 May 2017 02:39
by Black Cat

Re: Help with a (probably very easy) button sketch!

Posted: 31 May 2017 12:00
by n0ir
This sketch seems to control the LED on the Z-Uno using a switch in Vera. I want to control a switch in Vera using a button connected to the Z-Uno.

Re: Help with a (probably very easy) button sketch!

Posted: 31 May 2017 12:07
by PoltoS
Use Associations for that.

Re: Help with a (probably very easy) button sketch!

Posted: 31 May 2017 19:03
by Geirbakke
Her are an example, !not tested!

Code: Select all


#define Button_PIN_1  14 //Button 1
#define Button_PIN_2   15 //Button 2

#define SWITCH_ON 0xff
#define SWITCH_OFF 0


//ZUNO_SETUP_DEBUG_MODE(DEBUG_ON);


// Global variables to store data reported via getters
byte LastButton_state1 = 0; //Button Last State
byte LastButton_state2 = 0; //Button Last State

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 2 channels
ZUNO_SETUP_CHANNELS(
  ZUNO_SENSOR_BINARY_GENERAL_PURPOSE(getterBTN1),
  ZUNO_SENSOR_BINARY_GENERAL_PURPOSE(getterBTN2)
);

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin();
    
  Serial.println("Setup");
  pinMode(Door_PIN_2, INPUT_PULLUP); // Set button pin as input
  pinMode(Door_PIN_3, INPUT_PULLUP); // Set button pin as input
  
}
// the loop routine runs over and over again forever:
void loop() {
  byte currentBTN1_State;
  byte currentBTN2_State;


  currentBTN1 = digitalRead(Button_PIN_1); 
  if (currentBTN1 != LastButton_state1) { 
    LastButton_state1 = currentBTN1;
    zunoSendReport(1);
 }
 
  currentBTN2 = digitalRead(Button_PIN_2); 
  if (currentBTN2 != LastButton_state2) { 
    LastButton_state1 = currentBTN1;
    zunoSendReport(2);
 } 
 }

byte getterBTN1(void) {
 if (LastButton_state1 == 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 getterBTN1(void) {
 if (LastButton_state2 == 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
  }
}
  


Re: Help with a (probably very easy) button sketch!

Posted: 12 Jun 2017 08:49
by Black Cat
Yes, I can see what you mean, there is no example of using a button or mechanical switch.
I've just spent the best part of the day trying to cobble something together, but my knowledge is nearly nil. The above example code returns an error, so like yourself I'm back to the drawing board trying to find a simple example to build from.

Re: Help with a (probably very easy) button sketch!

Posted: 13 Jun 2017 21:47
by vkapadia
@Geirbakke

Just a quick addition, I assume the functions in your code should be getterBTN1 and getterBTN2.

Re: Help with a (probably very easy) button sketch!

Posted: 20 Jun 2017 08:20
by Black Cat
I returned to this example and have managed to compile it with some changes. I added some definitions and slowly worked through it until it compiled. I'm not sure if the code will work as I'm yet to upload it to Z-UNO.

Here it is if anyone else wants to test it.

Code: Select all


#define Button_PIN_1  14 //Button 1
#define Button_PIN_2   15 //Button 2

#define SWITCH_ON 0xff
#define SWITCH_OFF 0

#define currentBTN1
#define currentBTN2


//ZUNO_SETUP_DEBUG_MODE(DEBUG_ON);


// Global variables to store data reported via getters
byte LastButton_state1 = 0; //Button Last State
byte LastButton_state2 = 0; //Button Last State

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 2 channels
ZUNO_SETUP_CHANNELS(
  ZUNO_SENSOR_BINARY_GENERAL_PURPOSE(getterBTN1),
  ZUNO_SENSOR_BINARY_GENERAL_PURPOSE(getterBTN2)
);

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin();
    
  Serial.println("Setup");
  pinMode(Button_PIN_1, INPUT_PULLUP); // Set button pin as input
  pinMode(Button_PIN_2, INPUT_PULLUP); // Set button pin as input
  
}
// the loop routine runs over and over again forever:
void loop() {
  byte currentBTN1_State1;
  byte currentBTN2_State2;


  currentBTN1_State1 = digitalRead(Button_PIN_1); 
  if (currentBTN1_State1 != LastButton_state1) { 
    LastButton_state1 = currentBTN1_State1;
    zunoSendReport(1);
 }
 
  currentBTN2_State2 = digitalRead(Button_PIN_2); 
  if (currentBTN2_State2 != LastButton_state2) { 
    LastButton_state2 = currentBTN2_State2;
    zunoSendReport(2);
 } 
 }

byte getterBTN1(void) {
 if (LastButton_state1 == 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 getterBTN2(void) {
 if (LastButton_state2 == 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
  }
}
  

edit:
Included this into HomeSeer, It is not working in it's current form, I'm also not sure why the extra 2 sensor are populating the device?
Clipboard01.jpg
Clipboard01.jpg (45.79 KiB) Viewed 10157 times

edit 2:
See

https://github.com/BlackCatControlSystems/Z-UNO

if anyone wants to collaborate on this.