Switch combined with physical switch

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
duese
Posts: 6
Joined: 31 Oct 2016 19:28

Switch combined with physical switch

Post by duese » 08 Nov 2017 15:09

Hi everyone,

i´m looking for a working example of a simple switch sketch with a physical button/switch.

I managed it to get it working, but the state of the physical button ist not reported to the controller (Fibaro HC2)

Anyone else tried this and have solution?

petergebruers
Posts: 162
Joined: 26 Jul 2015 17:29

Re: Switch combined with physical switch

Post by petergebruers » 08 Nov 2017 15:13

There are different solutions. I have used a switch connected to int1. You are probably using a different setup Can you please post the sketch? Either here or as a private message? That will reduce the amount of guesswork from both sides...

duese
Posts: 6
Joined: 31 Oct 2016 19:28

Re: Switch combined with physical switch

Post by duese » 08 Nov 2017 18:21

This is the demo sketch is used.
I can trigger the LED with the button and from the HC2
But if i use the button, the HC2 didn´t recognize it.

Code: Select all

/*
 * That is a Simple Sensor Multilevel example
 * It measures the value on the potentiometer
 * And sends report to the controller if changed
 */
 
// LED pin number
#define LED_PIN 13
#define switchPin 0
#define Speaker 1


// Last saved LED value
byte currentLEDValue;
int state;
int lastState;

// next macro sets up the Z-Uno channels
// in this example we set up 1 switch binary channel
// you can read more on http://z-uno.z-wave.me/Reference/ZUNO_SWITCH_BINARY/
ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_BINARY(getter, setter));

void setup() {
  pinMode(LED_PIN, OUTPUT); // setup pin as output
  pinMode(Speaker, OUTPUT); // setup pin as output
}

void loop() {
  state = digitalRead(switchPin);
 
  if (state != lastState) 
  {
    if (state == HIGH) 
    {
      if (currentLEDValue == HIGH) 
      {
        currentLEDValue = LOW;
        Serial.println("LED AUS");
      }
      else 
      {
        currentLEDValue = HIGH;
        Serial.println("LED EIN");
      }
    }
    lastState = state;
  }
 
  digitalWrite(LED_PIN, currentLEDValue);
  digitalWrite (Speaker, currentLEDValue);
  delay(20);
}


// function, which sets new relay state
// this function runs only once the controller sends new value
 void setter (byte value) {
  // value is a variable, holding a "new value"
  // which came from the controller or other Z-Wave device
  if (value > 0) {    // if greater then zero
    digitalWrite (LED_PIN, HIGH); //turn LED on
    //digitalWrite (Speaker, HIGH); //turn LED on
  } else {            // if equals zero
    digitalWrite(LED_PIN, LOW);   //turn LED off
    //digitalWrite(Speaker, LOW); //turn LED on
  } 
  // let's save our value for the situation, when the controller will ask us about it
  currentLEDValue = value;
}

// function, which returns the previously saved relay value
// this function runs only once the controller asks
byte getter (){
  return currentLEDValue;
}

petergebruers
Posts: 162
Joined: 26 Jul 2015 17:29

Re: Switch combined with physical switch

Post by petergebruers » 08 Nov 2017 21:11

Thanks! Just add zunoSendReport like this and it will work:
lastState = state;
zunoSendReport(1);
}
http://z-uno.z-wave.me/Reference/zunoSendReport/

duese
Posts: 6
Joined: 31 Oct 2016 19:28

Re: Switch combined with physical switch

Post by duese » 08 Nov 2017 22:24

This works great!
Thanks for the quick help :-)


Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests