The idea started when i bought a flic smart button.
Today i use it to raise, lower and play/pause my chromecast audio.
I want more buttons, actually a want more buttons doing the same thing.
I have my flic in my kitchen. But when i am at my table? or in my couch?
Of course, i could buy more flics. But..... Mysensors....
To start with i will put these button under my tables for easy volume control.
This is a sleeping node presenting it self as a scene controller.
If someone want to try a sleeping mysensors smart button. Version 2.X compatible.
Three functions from one button. Single click, double click and hold.
You will need to install an external library called Onebutton. This is available in the library manager.
This have been done before by @dakipro but that thread isn't that easy to find it you search and isn't 2.X compatible.
By finding that very thread i solved the sleep.
/*
Mysensors Smart Button
*/
#define MY_DEBUG
#define MY_RADIO_NRF24
#include "OneButton.h"
#include <SPI.h>
#include <MySensors.h>
#define SN "MySmartButton"
#define SV "1.0"
#define CHILD_ID 1
#define SLEEP_PIN 2
// Setup a new OneButton on pin D2. true will set pin high (internal pull up), false will set pin low.
OneButton button(2, true);
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
const long interval = 5000;
MyMessage on(CHILD_ID, V_SCENE_ON);
// setup code here, to run once:
void setup() {
// link the doubleclick function to be called on a doubleclick event.
button.attachClick(click);
button.attachDoubleClick(doubleclick);
button.attachPress(press);
} // setup
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo(SN, SV);
present(CHILD_ID, S_SCENE_CONTROLLER);
}
int messageA = 1;
int messageB = 2;
int messageC = 3;
void loop() {
currentMillis = millis();
// keep watching the push button:
button.tick();
if (currentMillis - previousMillis >= interval) {
Serial.println("Sleep");
previousMillis = currentMillis;
sleep(SLEEP_PIN - 2, CHANGE, 0);
}
} // loop
// this function will be called when the button was pressed one time
void click() {
send(on.set(messageA));
}
// this function will be called when the button was pressed 2 times in a short timeframe.
void doubleclick() {
send(on.set(messageB));
} // doubleclick
// this function will be called when the button was pressed for about one second
void press() {
send(on.set(messageC));
}
It isn't reporting battery state yet.
I will add that to the sketch later when i build my button node.
Maybe i update this thread later when that is done if someone is interested.
EDIT 2017-06-26
Some pics.