Help with a (probably very easy) button sketch!

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
n0ir
Posts: 21
Joined: 17 Nov 2016 16:17

Help with a (probably very easy) button sketch!

Post by n0ir » 22 May 2017 17:10

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.

n0ir
Posts: 21
Joined: 17 Nov 2016 16:17

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

Post by n0ir » 22 May 2017 18:36

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


n0ir
Posts: 21
Joined: 17 Nov 2016 16:17

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

Post by n0ir » 31 May 2017 12:00

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.

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

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

Post by PoltoS » 31 May 2017 12:07

Use Associations for that.

Geirbakke
Posts: 3
Joined: 22 May 2017 16:09

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

Post by Geirbakke » 31 May 2017 19:03

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
  }
}
  


Black Cat
Posts: 48
Joined: 02 Mar 2016 00:52

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

Post by Black Cat » 12 Jun 2017 08:49

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.

vkapadia
Posts: 13
Joined: 09 Jun 2017 00:38

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

Post by vkapadia » 13 Jun 2017 21:47

@Geirbakke

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

Black Cat
Posts: 48
Joined: 02 Mar 2016 00:52

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

Post by Black Cat » 20 Jun 2017 08:20

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 332 times

edit 2:
See

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

if anyone wants to collaborate on this.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests