Post by selcouth on Jun 9, 2015 4:13:34 GMT
I wanted a reliable way to receive sensor alerts based on rules from openHAB. Prowl push notifications (iOS) and Notify My Android notifications work, but I wanted something built into the hardware. So I added a piezo speaker to the end node in my bedroom and added some devIDs to play different tones.
The idea is if I send ON to dev17 (toneContact) I get a single tone I associate with a contact sensor opening/closing. dev18 (toneMotion) is a tone I associate with motion. dev19 (toneAlarm) repeats an annoying alarm tone until I press a button to stop it.
I'm sure there's a cleaner way to do this, but this was what first came to my mind and so far it's been working for me.
The idea is if I send ON to dev17 (toneContact) I get a single tone I associate with a contact sensor opening/closing. dev18 (toneMotion) is a tone I associate with motion. dev19 (toneAlarm) repeats an annoying alarm tone until I press a button to stop it.
I'm sure there's a cleaner way to do this, but this was what first came to my mind and so far it's been working for me.
...
#define SPKPIN 9 // speaker out pin
#define BI2PIN 7 // binary input pin for button
...
bool toneContact = false; // tone for contact sensor
bool toneMotion = false; // tone for PIR motion sensor
bool toneAlarm = false; // tone for alarm
...
//inside void setup()
pinMode(BI2PIN, INPUT);
...
//inside void loop()
// begin tone checks
if (toneContact == true && toneAlarm == false){
// play tone then set toneContact to false
tone(SPKPIN, 440, 100);
delay(70);
tone(SPKPIN, 493, 100);
delay(70);
tone(SPKPIN, 523, 100);
toneContact = false; // reset toneContact status
}
if (toneMotion == true && toneAlarm == false){
// play tone then set toneMotion to false
tone(SPKPIN, 523, 100);
delay(70);
tone(SPKPIN, 493, 100);
delay(70);
tone(SPKPIN, 440, 100);
toneMotion = false; // reset toneMotion status
}
if (toneAlarm == true){
// play alarm tone until button interrupt then set toneAlarm to false
tone(SPKPIN, 440, 100);
delay(100);
tone(SPKPIN, 440, 100);
delay(300);
if (digitalRead(BI2PIN) == LOW) { // if the button was pressed
toneAlarm = false; // turn off the alarm
}
}
// end tone checks
...
//inside void parseCmd()
case (17) :
if (mes.cmd == 0) {
if (mes.intVal == 0 || mes.intVal == 1) {
toneContact = true;
if (setAck) send17 = true;
}
}
else send17 = true;
break;
case (18) :
if (mes.cmd == 0) {
if (mes.intVal == 0 || mes.intVal == 1) {
toneMotion = true;
if (setAck) send18 = true;
}
}
else send18 = true;
break;
case (19) :
if (mes.cmd == 0) {
if (mes.intVal == 0 || mes.intVal == 1) {
toneAlarm = true;
if (setAck) send19 = true;
}
}
else send19 = true;
break;
...
...