Can anybody help how to get a Binary button in a sleep mode and cannot be used for 15 min. After 15min the button works again.
Posts made by Dick
-
Binary button must lock after using
-
RE: IR remote controle
@nca78 I start experiment this weekend and will give it a try. Thanks for the ideas to make a working solution, in this case the use of an existing IR controle.
-
RE: IR remote controle
Thanks for the reply but this is probably to big for me. I wanted to make an IR remote to operate the most common use Mysensors in my house without starting the Domoticz app,The results I wanted to connect using an Event in domoticz
-
IR remote controle
I found a nice project using an IR remote controle, it is designed for Arduino but I have no idea how to convert the code to MySensors. Who can help? ```
/*Code belongs to this video https://www.youtube.com/watch?v=wqZwQnh6ZtQ
writen by Moz for YouTube changel logmaker360.
13-04-2016code works on a car mp3 remote controller
*/#include <IRremote.h>
int RECV_PIN = 6;
int BLUE_LED = 13;
int RED_LED = 12;IRrecv irrecv(RECV_PIN);
decode_results results;void setup() {
// initialize the digital pin as an output.
pinMode(RECV_PIN, INPUT);
pinMode(BLUE_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
Serial.begin(9600);
}
void loop() {
int i=0;
if (irrecv.decode(&results)) {translateIR();
unknownRemoter();irrecv.resume(); // Receive the next value
}
}void translateIR() // takes action based on IR code received describing Car MP3 IR codes
{switch(results.value){
case 0xFFA25D:
Serial.println(" CH- ");
break;
case 0xFF629D:
Serial.println(" CH ");
break;
case 0xFFE21D:
Serial.println(" CH+ ");
break;
case 0xFF22DD:
Serial.println(" blue LED off ");
digitalWrite(13,LOW);
break;
case 0xFF02FD:
Serial.println(" blue LED on ");
digitalWrite(13, HIGH);
break;
case 0xFFC23D:
Serial.println(" PLAY/PAUSE ");
break;
case 0xFFE01F:
Serial.println(" VOL- ");
break;
case 0xFFA857:
Serial.println(" VOL+ ");
break;
case 0xFF906F:
Serial.println(" EQ ");
break;
case 0xFF6897:
Serial.println(" 0 ");
break;
case 0xFF9867:
Serial.println(" 100+ ");
break;
case 0xFFB04F:
Serial.println(" 200+ ");
break;
case 0xFF30CF:
Serial.println(" 1 ");
break;case 0xFF18E7:
Serial.println(" 2 ");
break;case 0xFF7A85:
Serial.println(" 3 ");
break;case 0xFF10EF:
Serial.println(" 4 ");
break;case 0xFF38C7:
Serial.println(" 5 ");
break;case 0xFF5AA5:
Serial.println(" 6 ");
break;case 0xFF42BD:
Serial.println(" 7 ");
break;case 0xFF4AB5:
Serial.println(" 8 ");
break;case 0xFF52AD:
Serial.println(" 9 ");
break;default:
Serial.print(" unknown button ");
Serial.println(results.value, HEX);}
delay(500);
}
void unknownRemoter(){ //this function is from an old remoter see video.
long RED_LED_OFF = 0xFF40BF;
long RED_LED_ON = 0xFF906F;
long LAST_BUTTON = 0xFFD02F;if (results.value == RED_LED_OFF){
Serial.println ("Red led off");
digitalWrite(12,LOW);
}
else if (results.value == RED_LED_ON )
{
Serial.println ("Red led on");
digitalWrite(12,HIGH);
}
else if (results.value == LAST_BUTTON )
{
Serial.println ("CAMERA IMAGE button");
}else{
Serial.print(" still an unknown button ");
Serial.println(results.value, HEX);
}
} -
RE: Not all Relais visible in Domoticz
@mfalkvidd thanks for your support and no errors anymore. Unfortunately it did not work forme. probably I split my sensors in to, one with the relais switches and 1 with the binary buttons. I think that is the only way to continue right now.
-
RE: Not all Relais visible in Domoticz
@mfalkvidd I tested the solution and the LOOP code looks like this
but having an error during compiling ("IF" was not declared in this scope). how can I fix that?void loop() { debouncerIRBIN.update(); // Get the update value int valueIRBIN = debouncerIRBIN.read(); if (valueIRBIN != oldValue_IRBIN) { // Send in the new value send(msgIRBIN.set(valueIRBIN == HIGH ? 1 : 0)); oldValue_IRBIN = valueIRBIN; } debouncerIRBUI.update(); // Get the update value int valueIRBUI = debouncerIRBUI.read(); if (valueIRBUI != oldValue_IRBUI) { // Send in the new value send(msgIRBUI.set(valueIRBUI == HIGH ? 1 : 0)); oldValue_IRBUI = valueIRBUI; } static bool startup = true; If (startup) { Send initial value for each switch/relay startup=false; } }```
-
RE: Not all Relais visible in Domoticz
@nagelc
Thanks for the reply but I am not that experience. I must add your script to the "LOOP" but doing that I get a message "startup" was not declared in the scope. Can you show me was to declair? -
RE: Multi relay with two Binary switches
@dick said in Multi relay with two Binary switches:
I created 2 project where I need 5 relays and 2 buttons. If I put the number of relays on 5, I only see 3 in my Domoticz. The switches are visible in Domoticz without problems. How can I fix the relay issue?
// Enable debug prints to serial monitor
#define MY_DEBUG// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>#define RELAY_1 A0 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 5 // Total number of attached relays
#define RELAY_ON 0 // GPIO value to write to turn on attached relay
#define RELAY_OFF 1 // GPIO value to write to turn off attached relay#define CHILD_ID_IRBIN 3
#define CHILD_ID_IRBUI 4
#define IRBIN_PIN 3 // Arduino Digital I/O pin for button/reed switch
#define IRBUI_PIN 4Bounce debouncerIRBIN = Bounce();
Bounce debouncerIRBUI = Bounce();int oldValue_IRBIN = -1;
int oldValue_IRBUI = -1;MyMessage msgIRBIN(CHILD_ID_IRBIN, V_TRIPPED);
MyMessage msgIRBUI(CHILD_ID_IRBUI, V_TRIPPED);void before()
{
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
}
}void setup()
{
// Setup the button1
pinMode(IRBIN_PIN, INPUT);
debouncerIRBIN.attach(IRBIN_PIN);
debouncerIRBIN.interval(5);
digitalWrite(IRBIN_PIN, HIGH);
// Setup the button2
pinMode(IRBUI_PIN, INPUT);
debouncerIRBUI.attach(IRBUI_PIN);
debouncerIRBUI.interval(5);
digitalWrite(IRBUI_PIN, HIGH);}
void presentation()
{
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
present(CHILD_ID_IRBIN, S_DOOR);
present(CHILD_ID_IRBUI, S_DOOR);for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
present(sensor, S_BINARY);
}
}void loop()
{
debouncerIRBIN.update();
// Get the update value
int valueIRBIN = debouncerIRBIN.read();if (valueIRBIN != oldValue_IRBIN) {
// Send in the new value
send(msgIRBIN.set(valueIRBIN == HIGH ? 1 : 0));
oldValue_IRBIN = valueIRBIN;
}debouncerIRBUI.update();
// Get the update value
int valueIRBUI = debouncerIRBUI.read();if (valueIRBUI != oldValue_IRBUI) {
// Send in the new value
send(msgIRBUI.set(valueIRBUI == HIGH ? 1 : 0));
oldValue_IRBUI = valueIRBUI;
}
}void receive(const MyMessage &message)
{
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_STATUS) {
// Change relay state
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
// Store state in eeprom
saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}Sorry, add my questions two times
-
Not all Relais visible in Domoticz
I started a project with 5 relays and 2 binary buttons. In Domotics 3 of the 5 relays pops up including the 2 binary buttons. Why not 5 relays?
// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Enable repeater functionality for this node #define MY_REPEATER_FEATURE #include <SPI.h> #include <MySensors.h> #include <Bounce2.h> #define RELAY_1 A0 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 5 // Total number of attached relays #define RELAY_ON 0 // GPIO value to write to turn on attached relay #define RELAY_OFF 1 // GPIO value to write to turn off attached relay #define CHILD_ID_IRBIN 3 #define CHILD_ID_IRBUI 4 #define IRBIN_PIN 3 // Arduino Digital I/O pin for button/reed switch #define IRBUI_PIN 4 Bounce debouncerIRBIN = Bounce(); Bounce debouncerIRBUI = Bounce(); int oldValue_IRBIN = -1; int oldValue_IRBUI = -1; MyMessage msgIRBIN(CHILD_ID_IRBIN, V_TRIPPED); MyMessage msgIRBUI(CHILD_ID_IRBUI, V_TRIPPED); void before() { for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } } void setup() { // Setup the button1 pinMode(IRBIN_PIN, INPUT); debouncerIRBIN.attach(IRBIN_PIN); debouncerIRBIN.interval(5); digitalWrite(IRBIN_PIN, HIGH); // Setup the button2 pinMode(IRBUI_PIN, INPUT); debouncerIRBUI.attach(IRBUI_PIN); debouncerIRBUI.interval(5); digitalWrite(IRBUI_PIN, HIGH); } void presentation() { // Register binary input sensor to gw (they will be created as child devices) // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above. present(CHILD_ID_IRBIN, S_DOOR); present(CHILD_ID_IRBUI, S_DOOR); for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); } } void loop() { debouncerIRBIN.update(); // Get the update value int valueIRBIN = debouncerIRBIN.read(); if (valueIRBIN != oldValue_IRBIN) { // Send in the new value send(msgIRBIN.set(valueIRBIN == HIGH ? 1 : 0)); oldValue_IRBIN = valueIRBIN; } debouncerIRBUI.update(); // Get the update value int valueIRBUI = debouncerIRBUI.read(); if (valueIRBUI != oldValue_IRBUI) { // Send in the new value send(msgIRBUI.set(valueIRBUI == HIGH ? 1 : 0)); oldValue_IRBUI = valueIRBUI; } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_STATUS) { // Change relay state digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
-
Multi relay with two Binary switches
I created 2 project where I need 5 relays and 2 buttons. If I put the number of relays on 5, I only see 3 in my Domoticz. The switches are visible in Domoticz without problems. How can I fix the relay issue?
// Enable debug prints to serial monitor
#define MY_DEBUG// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>#define RELAY_1 A0 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 5 // Total number of attached relays
#define RELAY_ON 0 // GPIO value to write to turn on attached relay
#define RELAY_OFF 1 // GPIO value to write to turn off attached relay#define CHILD_ID_IRBIN 3
#define CHILD_ID_IRBUI 4
#define IRBIN_PIN 3 // Arduino Digital I/O pin for button/reed switch
#define IRBUI_PIN 4Bounce debouncerIRBIN = Bounce();
Bounce debouncerIRBUI = Bounce();int oldValue_IRBIN = -1;
int oldValue_IRBUI = -1;MyMessage msgIRBIN(CHILD_ID_IRBIN, V_TRIPPED);
MyMessage msgIRBUI(CHILD_ID_IRBUI, V_TRIPPED);void before()
{
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
}
}void setup()
{
// Setup the button1
pinMode(IRBIN_PIN, INPUT);
debouncerIRBIN.attach(IRBIN_PIN);
debouncerIRBIN.interval(5);
digitalWrite(IRBIN_PIN, HIGH);
// Setup the button2
pinMode(IRBUI_PIN, INPUT);
debouncerIRBUI.attach(IRBUI_PIN);
debouncerIRBUI.interval(5);
digitalWrite(IRBUI_PIN, HIGH);}
void presentation()
{
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
present(CHILD_ID_IRBIN, S_DOOR);
present(CHILD_ID_IRBUI, S_DOOR);for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); }
}
void loop()
{
debouncerIRBIN.update();
// Get the update value
int valueIRBIN = debouncerIRBIN.read();if (valueIRBIN != oldValue_IRBIN) {
// Send in the new value
send(msgIRBIN.set(valueIRBIN == HIGH ? 1 : 0));
oldValue_IRBIN = valueIRBIN;
}debouncerIRBUI.update();
// Get the update value
int valueIRBUI = debouncerIRBUI.read();if (valueIRBUI != oldValue_IRBUI) {
// Send in the new value
send(msgIRBUI.set(valueIRBUI == HIGH ? 1 : 0));
oldValue_IRBUI = valueIRBUI;
}
}void receive(const MyMessage &message)
{
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_STATUS) {
// Change relay state
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
// Store state in eeprom
saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
} -
RE: No matching function for call 'DHT::DHT()'
@mfalkvidd You are right. This was the problem. I forgot to check that. thanks for the Direction!
-
RE: No matching function for call 'DHT::DHT()'
@dbemowsk Thanks for the reply. After a fresh install of the Arduino IDE and adding the MySensors lib and the DHT lib you send me in the link, the compiling finished without errors but Now I have another strange behaviour where I work already on the whole day but I cannot find it. Looking on the serial monitor I see, (and I include a log from another already working switch)
0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
3 MCO:BGN:BFR
5 TSM:INIT
6 TSF:WUR:MS=0
13 TSM:INIT:TSP OK
15 TSF:SID:OK,ID=6
16 TSM:FPAR
58 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
181 TSF:MSG:READ,0-0-6,s=255,c=3,t=8,pt=1,l=1,sg=0:0
186 TSF:MSG:FPAR OK,ID=0,D=1
329 TSF:MSG:READ,3-3-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
334 TSF:MSG:BC
2065 TSM:FPAR:OK
2066 TSM:ID
2067 TSM:ID:OK
2069 TSM:UPL
2073 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2084 TSF:MSG:READ,0-0-6,s=255,c=3,t=25,pt=1,l=1,sg=0:1
2089 TSF:MSG:PONG RECV,HP=1
2093 TSM:UPL:OK
2094 TSM:READY:ID=6,PAR=0,DIS=1
2102 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2111 TSF:MSG:READ,0-0-6,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2119 TSF:MSG:SEND,6-6-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
2128 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
2144 TSF:MSG:READ,0-0-6,s=255,c=3,t=6,pt=0,l=1,sg=0:M
2152 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=11,pt=0,l=5,sg=0,ft=0,st=OK:Relay
2161 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
2169 TSF:MSG:SEND,6-6-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
2179 TSF:MSG:SEND,6-6-0-0,s=2,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
2184 MCO:REG:REQ
2189 TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
2197 TSF:MSG:READ,0-0-6,s=255,c=3,t=27,pt=1,l=1,sg=0:1
2202 MCO:PIM:NODE REG=1
2204 MCO:BGN:STP
2206 MCO:BGN:INIT OK,TSP=1After loading the same script on the same device, the result is:
0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
3 MCO:BGN:BFR
5 TSM:INIT
6 TSF:WUR:MS=0
12 TSM:INIT:TSP OK
14 TSF:SID:OK,ID=6
16 TSM:FPAR
52 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
2059 !TSM:FPAR:NO REPLY
2061 TSM:FPAR
2097 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
4105 !TSM:FPAR:NO REPLY
4107 TSM:FPAR
4143 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
6151 !TSM:FPAR:NO REPLY
6153 TSM:FPAR
6189 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
8197 !TSM:FPAR:FAIL
8198 TSM:FAIL:CNT=1
8200 TSM:FAIL:PDT
18203 TSM:FAIL:RE-INIT
18205 TSM:INIT
18212 TSM:INIT:TSP OK
18214 TSF:SID:OK,ID=6
18216 TSM:FPAR
18252 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
20260 !TSM:FPAR:NO REPLY
20262 TSM:FPAR
20299 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
22306 !TSM:FPAR:NO REPLY
22308 TSM:FPAR
22345 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
24352 !TSM:FPAR:NO REPLY
24354 TSM:FPAR
24391 TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
26398 !TSM:FPAR:FAIL
26399 TSM:FAIL:CNT=2
26401 TSM:FAIL:PDTThis "!TSM:FPAR:FAIL" I get also in my DHT project. It is strange that a working divice (4 days ago), load the same script again and I get an error. Any ideas in wat direction I have to look? Could it be something in the config file?? I do not know.
-
No matching function for call 'DHT::DHT()'
First of all 'Happy new year!'. I am working on the example script of the DHT22 https://www.mysensors.org/build/humidity. I read already some other builders about the library (I use version 2.1.1) I already downloaded the the DHT lib from gidhub but still the error as mentioned in the title. Who can help me. I use an Arduino nano.
-
RE: 💬 Temperature Sensor
@mfalkvidd I ony can tell "thanksfo the support ad you time" . Have a nice wekend!!!
-
RE: 💬 Temperature Sensor
@mfalkvidd I tried it in Presentation() and in Loop() inboth no results in the log (copied it as you advised me how to do. so no result bisible). it is getting complex I think!
6 TSM:INIT
7 TSF:WUR:MS=0
14 TSM:INIT:TSP OK
16 TSF:SID:OK,ID=12
17 TSM:FPAR
59 TSF:MSG:SEND,12-12-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
452 TSF:MSG:READ,0-0-12,s=255,c=3,t=8,pt=1,l=1,sg=0:0
457 TSF:MSG:FPAR OK,ID=0,D=1
561 TSF:MSG:READ,20-20-12,s=255,c=3,t=8,pt=1,l=1,sg=0:1
2066 TSM:FPAR:OK
2067 TSM:ID
2068 TSM:ID:OK
2070 TSM:UPL
2074 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2086 TSF:MSG:READ,0-0-12,s=255,c=3,t=25,pt=1,l=1,sg=0:1
2092 TSF:MSG:PONG RECV,HP=1
2094 TSM:UPL:OK
2096 TSM:READY:ID=12,PAR=0,DIS=1
2101 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2110 TSF:MSG:READ,0-0-12,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2118 TSF:MSG:SEND,12-12-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
2127 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
2142 TSF:MSG:READ,0-0-12,s=255,c=3,t=6,pt=0,l=1,sg=0:M
2151 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Temperature Sensor
2161 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
2168 MCO:REG:REQ
2172 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
2181 TSF:MSG:READ,0-0-12,s=255,c=3,t=27,pt=1,l=1,sg=0:1
2186 MCO:PIM:NODE REG=1
2189 MCO:BGN:STP
setup done.
2190 MCO:BGN:INIT OK,TSP=1
fetch sensors.
wait conversationtime.
fetch sensors.
wait conversationtime.
fetch sensors.
wait conversationtime. -
RE: 💬 Temperature Sensor
@mfalkvidd how can I manage that? sorr for the perhaps stupid qestion?
-
RE: 💬 Temperature Sensor
I put some deug lines i it and after uploadig the sketch it stops here (wait conversationtime.)
setup done.
2191 MCO:BGN:INIT OK,TSP=1
fetch sensors.
wait conversationtime.
fetch sensors.
wait conversationtime.
fetch sensors.
wait conversationtime.
fetch sensors.
wait conversationtime.
fetch sensors.
wait conversationtime.
fetch sensors.
wait conversationtime.
fetch sensors.
wait conversationtime. -
RE: 💬 Temperature Sensor
@mfalkvidd Ths is what the log says
0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
3 MCO:BGN:BFR
6 TSM:INIT
7 TSF:WUR:MS=0
14 TSM:INIT:TSP OK
16 TSF:SID:OK,ID=12
18 TSM:FPAR
59 TSF:MSG:SEND,12-12-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
1016 TSF:MSG:READ,0-0-12,s=255,c=3,t=8,pt=1,l=1,sg=0:0
1021 TSF:MSG:FPAR OK,ID=0,D=1
1804 TSF:MSG:READ,20-20-12,s=255,c=3,t=8,pt=1,l=1,sg=0:1
1851 TSF:MSG:READ,4-4-12,s=255,c=3,t=8,pt=1,l=1,sg=0:1
2067 TSM:FPAR:OK
2068 TSM:ID
2069 TSM:ID:OK
2071 TSM:UPL
2075 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2087 TSF:MSG:READ,0-0-12,s=255,c=3,t=25,pt=1,l=1,sg=0:1
2093 TSF:MSG:PONG RECV,HP=1
2095 TSM:UPL:OK
2097 TSM:READY:ID=12,PAR=0,DIS=1
2102 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2111 TSF:MSG:READ,0-0-12,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2119 TSF:MSG:SEND,12-12-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
2128 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
2144 TSF:MSG:READ,0-0-12,s=255,c=3,t=6,pt=0,l=1,sg=0:M
2152 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Temperature Sensor
2163 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
2169 MCO:REG:REQ
2173 TSF:MSG:SEND,12-12-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
2183 TSF:MSG:READ,0-0-12,s=255,c=3,t=27,pt=1,l=1,sg=0:1
2188 MCO:PIM:NODE REG=1
2190 MCO:BGN:STP
2192 MCO:BGN:INIT OK,TSP=1 -
RE: 💬 Temperature Sensor
@mfalkvidd In the Arduino log he Sleep error is not i anymore so that is solved but still no new device in Domoticz
-
RE: 💬 Temperature Sensor
@rejoe2 Yes on both location I replaced the sleep into a wait
-
RE: 💬 Temperature Sensor
@mfalkvidd I chaned the Sleep into Wait but the same log in both Domoticz and on my Arduino. I thought it was an easy go but it appear not to be.
-
RE: 💬 Temperature Sensor
@mfalkvidd I changed the dalles lib with an older one, because in a disussion a wile ago it was advised to get it working. Now this modified Sketch is available I replaced the dalles lib again the latest one. For the rest nothing.
-
RE: 💬 Temperature Sensor
@rejoe2 What I see in the Log of Domoticz is that all the nodes are registered and are visible in Black the only blue one is only the Dalles node
2017-08-19 12:44:48.339 MySensors: Node: 3, Sketch Name: Relay
2017-08-19 12:44:48.340 MySensors: Node: 3, Sketch Version: 1.0
2017-08-19 12:47:28.520 MySensors: Node: 48, Sketch Name: Temperature Sensor
2017-08-19 12:47:28.530 MySensors: Node: 48, Sketch Version: 1.2
2017-08-19 12:48:00.005 (GW Mysensors) Light/Switch (Voor Gor Pir)
2017-08-19 12:48:39.405 MySensors: Node: 48, Sketch Name: Temperature Sensor
2017-08-19 12:48:39.405 MySensors: Node: 48, Sketch Version: 1.2
2017-08-19 12:49:36.059 MySensors: Node: 48, Sketch Name: Temperature Sensor
2017-08-19 12:49:36.060 MySensors: Node: 48, Sketch Version: 1.2
2017-08-19 12:51:47.939 MySensors: Node: 12, Sketch Name: Temperature Sensor
2017-08-19 12:51:47.939 MySensors: Node: 12, Sketch Version: 1.2
2017-08-19 12:51:54.329 MySensors: Node: 12, Sketch Name: Temperature Sensor
2017-08-19 12:51:54.330 MySensors: Node: 12, Sketch Version: 1.2
2017-08-19 12:54:56.992 (GW Mysensors) Light/Switch (Serre IRbui)
2017-08-19 12:55:44.429 MySensors: Node: 12, Sketch Name: Temperature Sensor
2017-08-19 12:55:44.440 MySensors: Node: 12, Sketch Version: 1.2 -
RE: 💬 Temperature Sensor
@mfalkvidd For your info, I started the sketch cleareeprom to clear my Nano, loaded the script mentioned already and the log I posted is the same so the log must fit the sketch for the DallasTemperatureSimple. The repeater is activated or is it better to turn it off?
-
RE: 💬 Temperature Sensor
@mfalkvidd I already tried a fixed node ID but that was not the solution so I checked the log of domoticz and this is the result:
2017-08-19 11:59:30.260 MySensors: Node: 48, Sketch Name: Temperature Sensor
2017-08-19 11:59:30.261 MySensors: Node: 48, Sketch Version: 1.2
2017-08-19 11:59:38.480 MySensors: Node: 48, Sketch Name: Temperature Sensor
2017-08-19 11:59:38.481 MySensors: Node: 48, Sketch Version: 1.2So it see the node but it does not pop up as a new device.
The Arduino log shows this:0 MCO:BGN:INIT REPEATER,CP=RNNRA--,VER=2.1.1
3 MCO:BGN:BFR
6 TSM:INIT
7 TSF:WUR:MS=0
14 TSM:INIT:TSP OK
16 TSF:SID:OK,ID=48
17 TSM:FPAR
59 TSF:MSG:SEND,48-48-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
360 TSF:MSG:READ,0-0-48,s=255,c=3,t=8,pt=1,l=1,sg=0:0
365 TSF:MSG:FPAR OK,ID=0,D=1
408 TSF:MSG:READ,20-20-48,s=255,c=3,t=8,pt=1,l=1,sg=0:1
2066 TSM:FPAR:OK
2067 TSM:ID
2068 TSM:ID:OK
2070 TSM:UPL
2074 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
2086 TSF:MSG:READ,0-0-48,s=255,c=3,t=25,pt=1,l=1,sg=0:1
2092 TSF:MSG:PONG RECV,HP=1
2094 TSM:UPL:OK
2096 TSM:READY:ID=48,PAR=0,DIS=1
2101 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
2110 TSF:MSG:READ,0-0-48,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
2118 TSF:MSG:SEND,48-48-0-0,s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
2127 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
2143 TSF:MSG:READ,0-0-48,s=255,c=3,t=6,pt=0,l=1,sg=0:M
2152 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Temperature Sensor
2162 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
2169 MCO:REG:REQ
2173 TSF:MSG:SEND,48-48-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
2183 TSF:MSG:READ,0-0-48,s=255,c=3,t=27,pt=1,l=1,sg=0:1
2188 MCO:PIM:NODE REG=1
2190 MCO:BGN:STP
2191 MCO:BGN:INIT OK,TSP=1
2196 MCO:SLP:MS=750,SMS=0,I1=255,M1=255,I2=255,M2=255
2201 !MCO:SLP:REP
2952 MCO:SLP:MS=30000,SMS=0,I1=255,M1=255,I2=255,M2=255
2957 !MCO:SLP:REP
32960 MCO:SLP:MS=750,SMS=0,I1=255,M1=255,I2=255,M2=255 -
RE: 💬 Temperature Sensor
@rejoe2 Any idea why the DallasTemperatureSimple from your GitHub not presenting in Domoticz?
/** The MySensors Arduino library handles the wireless radio link and protocol between your home built sensors/actuators and HA controller of choice. The sensors forms a self healing radio network with optional repeaters. Each repeater and gateway builds a routing tables in EEPROM which keeps track of the network topology allowing messages to be routed to nodes. Created by Henrik Ekblad <henrik.ekblad@mysensors.org> Copyright (C) 2013-2015 Sensnology AB Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors Documentation: http://www.mysensors.org Support Forum: http://forum.mysensors.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. ******************************* DESCRIPTION Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller http://www.mysensors.org/build/temp Enhanced Version also sending the Dallas-ROM-ID, MySensors Version >=2.1.0 */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <SPI.h> #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 uint8_t DS_First_Child_ID = 7; //First Child-ID to be used by Dallas Bus; set this to be higher than other Child-ID's who need EEPROM storage to avoid conflicts unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors = 0; bool receivedConfig = false; bool metric = true; DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address int resolution = 12; // precision: 12 bits = 0.0625°C, 11 bits = 0.125°C, 10 bits = 0.25°C, 9 bits = 0.5°C int conversionTime = 0; // Initialize temperature message MyMessage msgTemp(0, V_TEMP); MyMessage msgId(0, V_ID); char* charAddr = "Check for faults"; #define SEND_ID void before() { // 12 bits = 750 ms, 11 bits = 375ms, 10 bits = 187.5ms, 9 bits = 93.75ms conversionTime = 750 / (1 << (12 - resolution)); // Startup up the OneWire library sensors.begin(); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Temperature Sensor", "1.2"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Present all sensors to controller for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { sensors.getAddress(tempDeviceAddress, i); charAddr = addrToChar(tempDeviceAddress); present(i + DS_First_Child_ID, S_TEMP, charAddr); #ifdef MY_DEBUG Serial.println(charAddr); #endif } } void setup() { // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { sensors.getAddress(tempDeviceAddress, i); #ifdef SEND_ID // 8 will assure a length of 16 of the sent ROM-ID send(msgId.setSensor(i + DS_First_Child_ID).set(tempDeviceAddress, 8)); #endif sensors.setResolution(tempDeviceAddress, resolution); metric = getControllerConfig().isMetric; } } void loop() { // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) sleep(conversionTime); // Read temperatures and send them to controller for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((metric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature send(msgTemp.setSensor(i + DS_First_Child_ID).set(temperature, 1)); wait(20); // Save new temperatures for next compare lastTemperature[i] = temperature; } } // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) sleep(SLEEP_TIME); } char* addrToChar(uint8_t* data) { String strAddr = String(data[0], HEX); //Chip Version; should be higher than 16 byte first ; int j = 0; for (uint8_t i = 1; i < 8; i++) { if (data[i] < 16) strAddr = strAddr + 0; strAddr = strAddr + String(data[i], HEX); strAddr.toUpperCase(); } for (int j = 0; j < 16; j++) { charAddr[j] = strAddr[j]; } return charAddr; }
-
RE: Maximum of relais and Binary buttons on Nano?
@Dick Still try to get it working. What I have untill now, 5 working relais, where 2 can be activated with a button. Only the Binary Button will not work and is not visible in Domoticz, For this Binary Button I used the default script (https://www.mysensors.org/build/binary). If I can get this button work (better is 2 Binary Buttons, my project is finished. Who can help me!
-
RE: Maximum of relais and Binary buttons on Nano?
@rejoe2 I take a good look at my code and put comments in it. I play around. again thanks for the advise
-
RE: Maximum of relais and Binary buttons on Nano?
@Dick said in Maximum of relais and Binary buttons on Nano?:
@rejoe2 Thanks for the links and I changed my code. The 5 relais are visible, the 2 binary switches as well but the relais are not switching??? any idea
here my code for now:
#define MOTION_SENSOR 3 #define CHILD_ID_MOTION 10 #define RELAY1_PIN 2 // Arduino Digital I/O pin number for relay alarm serre (groen) #define BUTTON1_PIN 14 // Arduino Digital I/O pin number for button with relay #define CHILD_ID_1 1 // Id of the sensor child #define RELAY2_PIN 4 // Arduino Digital I/O pin number for relay garden light serre (grijs) #define BUTTON2_PIN 15 // Arduino Digital I/O pin number for button with relay #define CHILD_ID_2 2 // Id of the sensor child #define RELAY3_PIN 5 // Arduino Digital I/O pin number for relay gordijn serre open (grijs) #define BUTTON3_PIN 16 // Arduino Digital I/O pin number for button with relay #define CHILD_ID_3 3 // Id of the sensor child #define RELAY6_PIN 6 // Arduino Digital I/O pin number for relay gordijn serre dicht (groen) #define BUTTON6_PIN 17 // Arduino Digital I/O pin number for button with relay #define CHILD_ID_6 12 // Id of the sensor child #define RELAY7_PIN 18 // Arduino Digital I/O pin number for relay gordijn serre stop (geel) #define BUTTON7_PIN 8 // Arduino Digital I/O pin number for button with relay #define CHILD_ID_7 11 // Id of the sensor child #define BUTTON4_PIN 19 // Arduino Digital I/O pin number for button without relay #define CHILD_ID_4 4 // Id of the sensor child #define BUTTON5_PIN 8 // Arduino Digital I/O pin number for button without relay #define CHILD_ID_5 5 // Id of the sensor child #define RELAY_ON 0 #define RELAY_OFF 1 #include <MySensors.h> #define MY_RADIO_NRF24 #define MY_DEBUG #include <SPI.h> #include <Bounce2.h> Bounce debouncer1 = Bounce(); int oldValue1 = 0; bool state1; Bounce debouncer2 = Bounce(); int oldValue2 = 0; bool state2; Bounce debouncer3 = Bounce(); int oldValue3 = 0; bool state3; Bounce debouncer4 = Bounce(); int oldValue4 = 0; bool state4; Bounce debouncer5 = Bounce(); int oldValue5 = 0; bool state5; Bounce debouncer6 = Bounce(); int oldValue6 = 0; bool state6; Bounce debouncer7 = Bounce(); int oldValue7 = 0; bool state7; Bounce debouncerMotion = Bounce(); MyMessage msg1(CHILD_ID_1, V_LIGHT); MyMessage msg2(CHILD_ID_2, V_LIGHT); MyMessage msg3(CHILD_ID_3, V_LIGHT); MyMessage msg4(CHILD_ID_4, V_LIGHT); MyMessage msg5(CHILD_ID_5, V_LIGHT); MyMessage msg6(CHILD_ID_6, V_LIGHT); MyMessage msg7(CHILD_ID_7, V_LIGHT); unsigned long SLEEP_TIME = 6000; unsigned long blockMotionTimer = 0; MyMessage msgRelay1(CHILD_ID_1, V_LIGHT), msgRelay2(CHILD_ID_2, V_LIGHT), msgRelay3(CHILD_ID_3, V_LIGHT), msgButton4(CHILD_ID_4, V_TRIPPED), msgButton5(CHILD_ID_5, V_TRIPPED), msgMotion(CHILD_ID_MOTION, V_TRIPPED), msgRelay6(CHILD_ID_6, V_LIGHT), msgRelay7(CHILD_ID_7, V_LIGHT); void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Relay & Button & Motion", "1.0"); // Setup the button pinMode(BUTTON1_PIN, INPUT); // Activate internal pull-up digitalWrite(BUTTON1_PIN, HIGH); pinMode(BUTTON2_PIN, INPUT); digitalWrite(BUTTON2_PIN, HIGH); pinMode(BUTTON3_PIN, INPUT); digitalWrite(BUTTON3_PIN, HIGH); pinMode(BUTTON4_PIN, INPUT); digitalWrite(BUTTON4_PIN, HIGH); pinMode(BUTTON5_PIN, INPUT); digitalWrite(BUTTON5_PIN, HIGH); pinMode(MOTION_SENSOR, INPUT_PULLUP); pinMode(BUTTON6_PIN, INPUT); digitalWrite(BUTTON6_PIN, HIGH); pinMode(BUTTON7_PIN, INPUT); digitalWrite(BUTTON7_PIN, HIGH); // After setting up the button, setup debouncer debouncer1.attach(BUTTON1_PIN); debouncer1.interval(5); debouncer2.attach(BUTTON2_PIN); debouncer2.interval(5); debouncer3.attach(BUTTON3_PIN); debouncer3.interval(5); debouncer4.attach(BUTTON4_PIN); debouncer4.interval(5); debouncer5.attach(BUTTON5_PIN); debouncer5.interval(5); debouncer6.attach(BUTTON6_PIN); debouncer6.interval(5); debouncer7.attach(BUTTON7_PIN); debouncer7.interval(5); debouncerMotion.attach(MOTION_SENSOR); debouncerMotion.interval(400); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_1, S_LIGHT); digitalWrite(RELAY1_PIN, RELAY_OFF); pinMode(RELAY1_PIN, OUTPUT); present(CHILD_ID_2, S_LIGHT); digitalWrite(RELAY2_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY2_PIN, OUTPUT); present(CHILD_ID_3, S_LIGHT); digitalWrite(RELAY3_PIN, RELAY_OFF); pinMode(RELAY3_PIN, OUTPUT); present(CHILD_ID_6, S_LIGHT); digitalWrite(RELAY6_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY6_PIN, OUTPUT); present(CHILD_ID_7, S_LIGHT); digitalWrite(RELAY7_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY7_PIN, OUTPUT); present(CHILD_ID_4, S_DOOR); present(CHILD_ID_5, S_DOOR); present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true); // Set relay to last known state (using eeprom storage) state1 = loadState(CHILD_ID_1); digitalWrite(RELAY1_PIN, state1 ? RELAY_ON : RELAY_OFF); state2 = loadState(CHILD_ID_2); digitalWrite(RELAY2_PIN, state2 ? RELAY_ON : RELAY_OFF); state3 = loadState(CHILD_ID_3); digitalWrite(RELAY3_PIN, state1 ? RELAY_ON : RELAY_OFF); state6 = loadState(CHILD_ID_6); digitalWrite(RELAY6_PIN, state6 ? RELAY_ON : RELAY_OFF); state7 = loadState(CHILD_ID_7); digitalWrite(RELAY7_PIN, state7 ? RELAY_ON : RELAY_OFF); } void loop() { debouncer1.update(); // Get the update value int value1 = debouncer1.read(); if (value1 != oldValue1 && value1 == 0) { send(msgRelay1.set(state1 ? false : true), true); // Send new state and request ack back } oldValue1 = value1; debouncer2.update(); // Get the update value int value2 = debouncer2.read(); if (value2 != oldValue2 && value2 == 0) { send(msgRelay2.set(state2 ? false : true), true); // Send new state and request ack back } oldValue2 = value2; debouncer3.update(); // Get the update value int value3 = debouncer3.read(); if (value3 != oldValue3 && value3 == 0) { send(msgRelay3.set(state3 ? false : true), true); // Send new state and request ack back } oldValue3 = value3; debouncer4.update(); // Get the update value int value4 = debouncer4.read(); if (value4 != oldValue4) { //Send in the new value send(msgButton4.set(value4 == HIGH ? 1 : 0)); oldValue4 = value4; } debouncer6.update(); // Get the update value int value6 = debouncer6.read(); if (value6 != oldValue6 && value6 == 0) { send(msgRelay6.set(state6 ? false : true), true); // Send new state and request ack back } oldValue6 = value6; debouncer7.update(); // Get the update value int value7 = debouncer7.read(); if (value7 != oldValue7 && value7 == 0) { send(msgRelay7.set(state7 ? false : true), true); // Send new state and request ack back } oldValue7 = value7; debouncer5.update(); // Get the update value int value5 = debouncer5.read(); if (value5 != oldValue5) { send(msgButton5.set(value5 == HIGH ? 1 : 0)); oldValue5 = value5; } if (blockMotionTimer == 0) { if (debouncerMotion.update()) { int valueMotion = debouncerMotion.read(); Serial.println( "PIR " + (String)valueMotion ); send( msgMotion.set( valueMotion ), true ); // Also it might need inverted value blockMotionTimer = (millis() + SLEEP_TIME); } } else { debouncerMotion.update(); // dummy update to prevent false trigger after timer expires if (blockMotionTimer < millis()) { blockMotionTimer = 0; } } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_LIGHT) { switch (message.sensor) { case CHILD_ID_1: // Change relay state state1 = message.getBool(); digitalWrite(RELAY1_PIN, state1 ? RELAY_ON : RELAY_OFF); // Store state in eeprom saveState(CHILD_ID_1, state1); break; case CHILD_ID_2: state2 = message.getBool(); digitalWrite(RELAY2_PIN, state2 ? RELAY_ON : RELAY_OFF); saveState(CHILD_ID_2, state2); break; case CHILD_ID_3: state3 = message.getBool(); digitalWrite(RELAY3_PIN, state3 ? RELAY_ON : RELAY_OFF); saveState(CHILD_ID_3, state3); break; case CHILD_ID_6: state6 = message.getBool(); digitalWrite(RELAY6_PIN, state6 ? RELAY_ON : RELAY_OFF); saveState(CHILD_ID_6, state6); break; case CHILD_ID_7: state7 = message.getBool(); digitalWrite(RELAY7_PIN, state7 ? RELAY_ON : RELAY_OFF); saveState(CHILD_ID_7, state7); break; default: Serial.print("Incoming sensor unknown"); } } }```
-
RE: Maximum of relais and Binary buttons on Nano?
@rejoe2 Thanks for the links and I cange my code. The 5 relais are visibl, the 2 binary switches as wel ut the relais are not switching??? any idea
-
Maximum of relais and Binary buttons on Nano?
I try to get 5 relais and 2 binary buttons activated on my nano and have them controlled by Domoticz.
What I found was that everything is working 2 bin buttons and 3 relais but adding another relais (4) I loose one bin button and had 4 relais. adding another relay I lost my last bin button. How can I get it in place 5 relais and 2 binary button?
here you see my script:#define MY_RADIO_NRF24 #define MY_DEBUG #define MY_REPEATER_FEATURE #include <MySensors.h> #include <SPI.h> #include <Bounce2.h> #define CHILD_ID1 3 #define BUTTON_PIN1 4 // Arduino Digital I/O pin for button/reed switch #define CHILD_ID2 4 #define BUTTON_PIN2 5 // Arduino Digital I/O pin for button/reed switch #define RELAY_1 A0 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 5 // Total number of attached relays #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay Bounce debouncer1 = Bounce(); Bounce debouncer2 = Bounce(); // debouncer for the second switch int oldValue1 = -1; int oldValue2 = -1; // second switch needs to have it's own old state MyMessage msg1(CHILD_ID1, V_TRIPPED), msg2(CHILD_ID2, V_TRIPPED); void before() { for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor) ? RELAY_ON : RELAY_OFF); } } void presentation() { sendSketchInfo("Serre", "1.0"); for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); } pinMode(BUTTON_PIN1, INPUT_PULLUP ); // You can assign pinmode and use pullup in one statement. pinMode(BUTTON_PIN2, INPUT_PULLUP); debouncer1.attach(BUTTON_PIN1); debouncer1.interval(5); debouncer2.attach(BUTTON_PIN2); debouncer2.interval(5); present(CHILD_ID1, S_DOOR); present(CHILD_ID2, S_DOOR); } void loop() { // Check if the first switch state has changed debouncer1.update(); // Get the update value int value = debouncer1.read(); if (value != oldValue1) { // Send in the new value send(msg1.set(value == HIGH ? 1 : 0)); oldValue1 = value; } debouncer2.update(); // Get the update value value = debouncer2.read(); // no need to redeclare it (I removed int) if (value != oldValue2) { // Send in the new value send(msg2.set(value == HIGH ? 1 : 0)); // this is where you turn the second switch in your controller oldValue2 = value; } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type == V_STATUS) { // Change relay state digitalWrite(message.sensor - 1 + RELAY_1, message.getBool() ? RELAY_ON : RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
-
RE: Upgraded to 2.11 and Domoticz 3.513. On/Off will not switch
@Dick Still trying to find the problem. What I did in the past hours, fresh install of the Pi and the Mysensors gateway, Connect a Node and activate them in Domoticz.It works good (4 relays wih button). Adding anothe nod, instaling no problem and actiate in Domotic. Tst all the active sensors and nothing works. Deleted all the active sensors and dit the same as befor only i gave the nodes a radio ID. Sme resut, frst node worked goodand addig a second, nothing woks. Beore adding the node I tested them on a test module. Does have anybody an Idea??
-
RE: Upgraded to 2.11 and Domoticz 3.513. On/Off will not switch
@Dick said in Upgraded to 2.11 and Domoticz 3.513. On/Off will not switch:
@Dick It is not fixed, I thought it was fixed but that is not the case.
I just finished cionfiguring my PI, so it is a fresh installation and empty.
I have a ode that worked fine in the formar version of Mysensors 153 and the oldr domoticZ. I adjusted the srit o the Node so i can use it in 2.1.1, Now I connect the node using the nrf24 radio. The switches are visible in Domoticz. If I use theswitches in domoticz they do not switch. If I cange the switches by putting ground to a button pinm he reay activates/deacivate. that is visible in the serial monitor and in domoticz log. Both looks correct switchn but using the button in domoticz, both logging also orrect bt no activity from the relay. Any idea what t is?What I also notised that the sitch is an ON/OFF type butputting GND to the botton pin the relay is a momentory button????
-
RE: Upgraded to 2.11 and Domoticz 3.513. On/Off will not switch
@Dick It is not fixed, I thought it was fixed but that is not the case.
I just finished cionfiguring my PI, so it is a fresh installation and empty.
I have a ode that worked fine in the formar version of Mysensors 153 and the oldr domoticZ. I adjusted the srit o the Node so i can use it in 2.1.1, Now I connect the node using the nrf24 radio. The switches are visible in Domoticz. If I use theswitches in domoticz they do not switch. If I cange the switches by putting ground to a button pinm he reay activates/deacivate. that is visible in the serial monitor and in domoticz log. Both looks correct switchn but using the button in domoticz, both logging also orrect bt no activity from the relay. Any idea what t is? -
RE: Upgraded to 2.11 and Domoticz 3.513. On/Off will not switch
@sundberg84 Yes that is right but I just finished testing. I use 4 relays in a script but physicaly there are only 2 relays attached and from the other two I only us the " 0" to open or clos my curtains and thiose channels are not working. Clicking on the nano itself (on the button pin) than then curtains open/close.
Finaly I dir " clear Eeprom" and that did the job. It is working (for now). -
RE: Upgraded to 2.11 and Domoticz 3.513. On/Off will not switch
@sundberg84 Thanks for the reply. That is what I am doing right now. New extra PI with the latest domoticz and replce the scripts on he nano and add thm a new device in Domoticz. At the momentI made a test environment if I can get it working wihout the attachment of cables frm evice like my curtains. Hope it wil work !
-
RE: Upgraded to 2.11 and Domoticz 3.513. On/Off will not switch
@LastSamurai What I ment, I take a cable with a (-) and conect it to the pin deined as a button fort the relay and that changes the state of th relay.The serial monitor also a statuschange. The ide monitor shows this:
158953 TSF:MSG:SEND,6-6-0-0,s=0,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:0
166039 TSF:MSG:SEND,6-6-0-0,s=0,c=1,t=2,pt=1,l=1,sg=0,ft=0,st=OK:1 -
RE: Upgraded to 2.11 and Domoticz 3.513. On/Off will not switch
@LastSamurai I also try to click on the arduino itself, the switch changed and another log in Domoticz is visble,
Light/Switch (open).Very strange?
-
RE: Upgraded to 2.11 and Domoticz 3.513. On/Off will not switch
In an earlier version it worked and the log in Domoticz says:
Light/Switch (open) and using the other button for closing it says Light/Switch (dicht).
it looks like Domoticz does its job but reality in something else. -
Upgraded to 2.11 and Domoticz 3.513. On/Off will not switch
I try to get all my defices running on the new version of MySensors and Domoticz. For MySensors it was no proble. I am now working on my 3rd Node and I see the devices in DomoticZ. As soon as I try to change the status from on to Off, it looks that it works and the icon change but nothing happens with the connected relay. If I do the same directly on my Nano, the relay activates. The node is a relay buth button as a test.
I already replaced the Nano with another one. -
RE: Conversion from 1.5.4 to 2.1.1.
@korttoma That is easy,Thanks for the solution.
-
RE: Conversion from 1.5.4 to 2.1.1.
@Dick I hope it is the last time to keep you involved, still nothing in the serial Monitor. For a test I loaded an Example and that showed up in the monitor. Any idea?
In// 2x binary switch + dallas temp example // Connect button or door/window reed switch between // digitial I/O pin 4,5 (BUTTON_PIN_4/BUTTON_PIN_5 below) and GND. // Connect dallas temp sensor to digital pin 3 #define MY_RADIO_NRF24 #define DIGITAL_MOTION_SENSOR 2 #define CHILD_ID_MOTION 6 #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 #define noRelays 1 #define RELAY_ON 1 // switch around for realy HIGH/LOW state #define RELAY_OFF 0 #include <MySensors.h> #include <SPI.h> #include <Bounce2.h> #include <DallasTemperature.h> #include <OneWire.h> Bounce motionsDebouncer = Bounce(); int lastMOTION; unsigned long SLEEP_TIME = 420000; //unsigned long SLEEP_TIME = 3000; unsigned long blockMotionTimer = 0; OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); //#define noRelays 3 //const int relayPin[] = {A1, A4, A5}; // switch around pins to your desire //const int buttonPin[] = {6, 7, 8}; // switch around pins to your desire const int relayPin[] = {A1}; // switch around pins to your desire const int buttonPin[] = {6}; // switch around pins to your desire class Relay // relay class, store all relevant data (equivalent to struct) { public: int buttonPin; // physical pin number of button int relayPin; // physical pin number of relay byte oldValue; // last Values for key (debounce) boolean relayState; // relay status (also stored in EEPROM) }; Relay Relays[noRelays]; Bounce debouncerRELAY[noRelays]; MyMessage msgRELAY[noRelays]; float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors = 0; boolean receivedConfig = false; boolean metric = true; MyMessage msg(0, V_TEMP); MyMessage msgMOTION(CHILD_ID_MOTION, V_TRIPPED); void presentation() { //sensors.begin(); //begin receive, AUTO, true; sendSketchInfo("Motion/Temp/relay", "1.0"); numSensors = sensors.getDeviceCount(); for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); } pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP); // sets the motion sensor digital pin as input motionsDebouncer.attach(DIGITAL_MOTION_SENSOR); motionsDebouncer.interval(400); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true); for (int i = 0; i < noRelays; i++) { Relays[i].buttonPin = buttonPin[i]; // assign physical pins Relays[i].relayPin = relayPin[i]; msgRELAY[i].sensor = i; // initialize messages msgRELAY[i].type = V_LIGHT; debouncerRELAY[i] = Bounce(); // initialize debouncer debouncerRELAY[i].attach(buttonPin[i]); debouncerRELAY[i].interval(5); pinMode(Relays[i].buttonPin, INPUT_PULLUP); pinMode(Relays[i].relayPin, OUTPUT); Relays[i].relayState = loadState(i); // retrieve last values from EEPROM digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly send(msgRELAY[i].set(Relays[i].relayState ? true : false)); // make controller aware of last status present(i, S_LIGHT); // present sensor to gateway delay(250); } } void loop() { for (byte i = 0; i < noRelays; i++) { debouncerRELAY[i].update(); byte value = debouncerRELAY[i].read(); if (value != Relays[i].oldValue && value == 0) { Relays[i].relayState = !Relays[i].relayState; digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); send(msgRELAY[i].set(Relays[i].relayState ? true : false)); saveState( i, Relays[i].relayState ); } // save sensor state in EEPROM (location == sensor number) Relays[i].oldValue = value; } if (blockMotionTimer == 0) { if (motionsDebouncer.update()) { int value = motionsDebouncer.read(); Serial.println( "PIR " + (String)value ); send( msgMOTION.set( value ), true ); // Also it might need inverted value blockMotionTimer = (millis() + SLEEP_TIME); } } else { motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires if (blockMotionTimer < millis()) { blockMotionTimer = 0; } } updateTemperature(30);// update time in seconds } void updateTemperature(int frequency) { static unsigned long lastUpdateTime; if (millis() - lastUpdateTime >= frequency * 1000UL) { sensors.requestTemperatures(); for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.; if (lastTemperature[i] != temperature && temperature != -127.00) { send(msg.setSensor(i).set(temperature, 1)); lastTemperature[i] = temperature; } } lastUpdateTime += frequency * 1000UL; } } //void incomingMessage(const MyMessage &message) void receive(const MyMessage &message) { if (message.type == V_LIGHT) { if (message.sensor < noRelays) // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]] { Relays[message.sensor].relayState = message.getBool(); digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number) } } //gw.wait(50); } `
-
RE: Conversion from 1.5.4 to 2.1.1.
@scalz I changed everything as mentioned before. I uploaded to my Nano but I see nothing in the serial monitor. I hope it is my last queation:
the code is until now:In// 2x binary switch + dallas temp example // Connect button or door/window reed switch between // digitial I/O pin 4,5 (BUTTON_PIN_4/BUTTON_PIN_5 below) and GND. // Connect dallas temp sensor to digital pin 3 #include <MySensors.h> #include <SPI.h> #include <Bounce2.h> #include <DallasTemperature.h> #include <OneWire.h> #define MY_RADIO_NRF24 #define DIGITAL_MOTION_SENSOR 2 #define CHILD_ID_MOTION 6 #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 #define RELAY_ON 1 // switch around for realy HIGH/LOW state #define RELAY_OFF 0 Bounce motionsDebouncer = Bounce(); int lastMOTION; unsigned long SLEEP_TIME = 420000; //unsigned long SLEEP_TIME = 3000; unsigned long blockMotionTimer = 0; OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); //#define noRelays 3 //const int relayPin[] = {A1, A4, A5}; // switch around pins to your desire //const int buttonPin[] = {6, 7, 8}; // switch around pins to your desire #define noRelays 1 const int relayPin[] = {A1}; // switch around pins to your desire const int buttonPin[] = {6}; // switch around pins to your desire class Relay // relay class, store all relevant data (equivalent to struct) { public: int buttonPin; // physical pin number of button int relayPin; // physical pin number of relay byte oldValue; // last Values for key (debounce) boolean relayState; // relay status (also stored in EEPROM) }; Relay Relays[noRelays]; Bounce debouncerRELAY[noRelays]; MyMessage msgRELAY[noRelays]; float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; boolean receivedConfig = false; boolean metric = true; MyMessage msg(0,V_TEMP); MyMessage msgMOTION(CHILD_ID_MOTION, V_TRIPPED); void presentation() { //sensors.begin(); //begin receive, AUTO, true; sendSketchInfo("Motion/Temp/relay", "1.0"); numSensors = sensors.getDeviceCount(); for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); } pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP); // sets the motion sensor digital pin as input motionsDebouncer.attach(DIGITAL_MOTION_SENSOR); motionsDebouncer.interval(400); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true); for (int i = 0; i < noRelays; i++) { Relays[i].buttonPin = buttonPin[i]; // assign physical pins Relays[i].relayPin = relayPin[i]; msgRELAY[i].sensor = i; // initialize messages msgRELAY[i].type = V_LIGHT; debouncerRELAY[i] = Bounce(); // initialize debouncer debouncerRELAY[i].attach(buttonPin[i]); debouncerRELAY[i].interval(5); pinMode(Relays[i].buttonPin, INPUT_PULLUP); pinMode(Relays[i].relayPin, OUTPUT); Relays[i].relayState = loadState(i); // retrieve last values from EEPROM digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly send(msgRELAY[i].set(Relays[i].relayState ? true : false)); // make controller aware of last status present(i, S_LIGHT); // present sensor to gateway delay(250); } } void loop() { for (byte i = 0; i < noRelays; i++) { debouncerRELAY[i].update(); byte value = debouncerRELAY[i].read(); if (value != Relays[i].oldValue && value == 0) { Relays[i].relayState = !Relays[i].relayState; digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); send(msgRELAY[i].set(Relays[i].relayState ? true : false)); saveState( i, Relays[i].relayState ); } // save sensor state in EEPROM (location == sensor number) Relays[i].oldValue = value; } if (blockMotionTimer == 0) { if (motionsDebouncer.update()) { int value = motionsDebouncer.read(); Serial.println( "PIR " + (String)value ); send( msgMOTION.set( value ), true ); // Also it might need inverted value blockMotionTimer = (millis() + SLEEP_TIME); } } else { motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires if (blockMotionTimer < millis()) { blockMotionTimer = 0; } } updateTemperature(30);// update time in seconds } void updateTemperature(int frequency) { static unsigned long lastUpdateTime; if (millis() - lastUpdateTime >= frequency * 1000UL) { sensors.requestTemperatures(); for (int i=0; i<numSensors && i< MAX_ATTACHED_DS18B20; i++) { float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; if (lastTemperature[i] != temperature && temperature != -127.00) { send(msg.setSensor(i).set(temperature,1)); lastTemperature[i]=temperature; } } lastUpdateTime += frequency * 1000UL; } } //void incomingMessage(const MyMessage &message) void receive(const MyMessage &message){ if (message.type == V_LIGHT) { if (message.sensor < noRelays) // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]] { Relays[message.sensor].relayState = message.getBool(); digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number) } } //gw.wait(50); } `
-
RE: Conversion from 1.5.4 to 2.1.1.
@scalz That is a good idea, totaly forgotten
-
RE: Conversion from 1.5.4 to 2.1.1.
@scalz thanks for the link, that was the one I used also. Perhaps you can do something with the whole script in the part void presentation (3rd row)
// 2x binary switch + dallas temp example // Connect button or door/window reed switch between // digitial I/O pin 4,5 (BUTTON_PIN_4/BUTTON_PIN_5 below) and GND. // Connect dallas temp sensor to digital pin 3 #include <MySensors.h> #include <SPI.h> #include <Bounce2.h> #include <DallasTemperature.h> #include <OneWire.h> #define DIGITAL_MOTION_SENSOR 2 #define CHILD_ID_MOTION 6 #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 #define RELAY_ON 1 // switch around for realy HIGH/LOW state #define RELAY_OFF 0 Bounce motionsDebouncer = Bounce(); int lastMOTION; unsigned long SLEEP_TIME = 420000; //unsigned long SLEEP_TIME = 3000; unsigned long blockMotionTimer = 0; OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); //#define noRelays 3 //const int relayPin[] = {A1, A4, A5}; // switch around pins to your desire //const int buttonPin[] = {6, 7, 8}; // switch around pins to your desire #define noRelays 1 const int relayPin[] = {A1}; // switch around pins to your desire const int buttonPin[] = {6}; // switch around pins to your desire class Relay // relay class, store all relevant data (equivalent to struct) { public: int buttonPin; // physical pin number of button int relayPin; // physical pin number of relay byte oldValue; // last Values for key (debounce) boolean relayState; // relay status (also stored in EEPROM) }; Relay Relays[noRelays]; Bounce debouncerRELAY[noRelays]; MyMessage msgRELAY[noRelays]; float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; boolean receivedConfig = false; boolean metric = true; MyMessage msg(0,V_TEMP); MyMessage msgMOTION(CHILD_ID_MOTION, V_TRIPPED); void presentation() { sensors.begin(); begin(receive, AUTO, true); sendSketchInfo("Motion/Temp/relay", "1.0"); numSensors = sensors.getDeviceCount(); for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i, S_TEMP); } pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP); // sets the motion sensor digital pin as input motionsDebouncer.attach(DIGITAL_MOTION_SENSOR); motionsDebouncer.interval(400); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true); for (int i = 0; i < noRelays; i++) { Relays[i].buttonPin = buttonPin[i]; // assign physical pins Relays[i].relayPin = relayPin[i]; msgRELAY[i].sensor = i; // initialize messages msgRELAY[i].type = V_LIGHT; debouncerRELAY[i] = Bounce(); // initialize debouncer debouncerRELAY[i].attach(buttonPin[i]); debouncerRELAY[i].interval(5); pinMode(Relays[i].buttonPin, INPUT_PULLUP); pinMode(Relays[i].relayPin, OUTPUT); Relays[i].relayState = gw.loadState(i); // retrieve last values from EEPROM digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly send(msgRELAY[i].set(Relays[i].relayState ? true : false)); // make controller aware of last status present(i, S_LIGHT); // present sensor to gateway delay(250); } } void loop() { //process(); for (byte i = 0; i < noRelays; i++) { debouncerRELAY[i].update(); byte value = debouncerRELAY[i].read(); if (value != Relays[i].oldValue && value == 0) { Relays[i].relayState = !Relays[i].relayState; digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); send(msgRELAY[i].set(Relays[i].relayState ? true : false)); saveState( i, Relays[i].relayState ); } // save sensor state in EEPROM (location == sensor number) Relays[i].oldValue = value; } if (blockMotionTimer == 0) { if (motionsDebouncer.update()) { int value = motionsDebouncer.read(); Serial.println( "PIR " + (String)value ); send( msgMOTION.set( value ), true ); // Also it might need inverted value blockMotionTimer = (millis() + SLEEP_TIME); } } else { motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires if (blockMotionTimer < millis()) { blockMotionTimer = 0; } } updateTemperature(30);// update time in seconds } void updateTemperature(int frequency) { static unsigned long lastUpdateTime; if (millis() - lastUpdateTime >= frequency * 1000UL) { sensors.requestTemperatures(); for (int i=0; i<numSensors && i< MAX_ATTACHED_DS18B20; i++) { float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; if (lastTemperature[i] != temperature && temperature != -127.00) { send(msg.setSensor(i).set(temperature,1)); lastTemperature[i]=temperature; } } lastUpdateTime += frequency * 1000UL; } } //void incomingMessage(const MyMessage &message) void receive(const MyMessage &message){ if (message.type == V_LIGHT) { if (message.sensor < noRelays) // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]] { Relays[message.sensor].relayState = message.getBool(); digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number) } } //gw.wait(50); }
-
Conversion from 1.5.4 to 2.1.1.
I am converting all my nodes to 2.1.1 because they are not visible in the Domoticz so I think I have re adjust them all. Is there a central place where the conversion is explained? I found already a lot of info on this forum. Now I have a questions what can I do with the row:
gw.begin(incomingMessage, AUTO, true);
I changed it already in
begin(recieve,AUTO, true);
But get an erro "begin was not declared in the scope.
What must I do? -
RE: double RelyWithButonActuator not working
Thanks for the solution, I tested it and works fine now. In Answer to your question why I use the old version of MySensors, at the moment I am re-configurating my ne RP with the latest version of Domoticz. After that I will connect the latest MYsensors Gateway to it. If all the nodes keep on working on the new environment, there is not an immediate need to adjust the code of all my nodes. Is my approach correct? if not please reply.
-
double RelyWithButonActuator not working
still strugling with multiple relais without using a class. in my code I duplicate the example of MySensors. testing the 2 relais both activate of the 2 defined buttons. so clicking one button, both relais activate, the same with the other button. How can I get it work and what is wrong in the code? If I test only one relay with one button that works fine.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Example sketch for a "light switch" where you can control light or something * else from both HA controller and a local physical button * (connected between digital pin 3 and GND). * This node also works as a repeader for other nodes * http://www.mysensors.org/build/relay */ #include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #define RELAY1_PIN 4 // Arduino Digital I/O pin number for relay #define BUTTON1_PIN 3 // Arduino Digital I/O pin number for button #define CHILD_ID_1 1 // Id of the sensor child #define RELAY2_PIN 6 // Arduino Digital I/O pin number for relay #define BUTTON2_PIN 5 // Arduino Digital I/O pin number for button #define CHILD_ID_2 2 // Id of the sensor child #define RELAY_ON 1 #define RELAY_OFF 0 Bounce debouncer1 = Bounce(); int oldValue1=0; bool state1; Bounce debouncer2 = Bounce(); int oldValue2=0; bool state2; MySensor gw; MyMessage msg1(CHILD_ID_1,V_LIGHT); MyMessage msg2(CHILD_ID_2,V_LIGHT); void setup() { gw.begin(incomingMessage, AUTO, true); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Relay & Button", "1.0"); // Setup the button pinMode(BUTTON1_PIN,INPUT); digitalWrite(BUTTON1_PIN,HIGH); pinMode(BUTTON2_PIN,INPUT); digitalWrite(BUTTON2_PIN,HIGH); // After setting up the button, setup debouncer debouncer1.attach(BUTTON1_PIN); debouncer1.interval(5); debouncer2.attach(BUTTON2_PIN); debouncer2.interval(5); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_1, S_LIGHT); digitalWrite(RELAY1_PIN, RELAY_OFF); pinMode(RELAY1_PIN, OUTPUT); gw.present(CHILD_ID_2, S_LIGHT); digitalWrite(RELAY2_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY2_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) state1 = gw.loadState(CHILD_ID_1); digitalWrite(RELAY1_PIN, state1?RELAY_ON:RELAY_OFF); state2 = gw.loadState(CHILD_ID_2); digitalWrite(RELAY2_PIN, state2?RELAY_ON:RELAY_OFF); } /* * Example on how to asynchronously check for new messages from gw */ void loop() { gw.process(); debouncer1.update(); // Get the update value int value1 = debouncer1.read(); if (value1 != oldValue1 && value1==0) { gw.send(msg1.set(state1?false:true), true); // Send new state and request ack back } oldValue1 = value1; debouncer2.update(); // Get the update value int value2 = debouncer2.read(); if (value2 != oldValue2 && value2==0) { gw.send(msg2.set(state2?false:true), true); // Send new state and request ack back } oldValue2 = value2; } void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_LIGHT) { // Change relay state state1 = message.getBool(); digitalWrite(RELAY1_PIN, state1?RELAY_ON:RELAY_OFF); // Store state in eeprom gw.saveState(CHILD_ID_1, state1); if (message.type == V_LIGHT) { state2 = message.getBool(); digitalWrite(RELAY2_PIN, state2?RELAY_ON:RELAY_OFF); gw.saveState(CHILD_ID_2, state2); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } }
-
RE: Binary button conflicting Relais with button
@mfalkvidd i thought is was ok because I defined 4 binary buttons 2, 8, A0 and A1 and they only work like a button. Beside these Buttons there is a class in use for the 3x relais with extra buttons to control the relais or do I make a mistake?
-
Binary button conflicting Relais with button
I use a sensor with 3 relais with button and 4 binary buttons. All 3 relais are working and 3 of the 4 buttons are working to but as soon as I hit the button on pin A1, the relay on pin A5 is switching. I have already tried to change the A1 pin in another but same result. Any idea how to solve this? included the code:```
// 2x binary switch + dallas temp example
// Connect button or door/window reed switch between
// digitial I/O pin 4,5 (BUTTON_PIN_4/BUTTON_PIN_5 below) and GND.
// Connect dallas temp sensor to digital pin 3#include <MySensor.h>
#include <SPI.h>
#include <Bounce2.h>
#define DIGITAL_MOTION_SENSOR 3
#define CHILD_ID_MOTION 6
#define BUTTON1_PIN 2
#define CHILD_ID_BUTTON1 4
#define BUTTON2_PIN A0
#define CHILD_ID_BUTTON2 3
#define BUTTON3_PIN 8
#define CHILD_ID_BUTTON3 5
#define BUTTON4_PIN A1
#define CHILD_ID_BUTTON4 1
#define RELAY_ON 0 // switch around for realy HIGH/LOW state
#define RELAY_OFF 1
#define RADIO_ID 43Bounce motionsDebouncer = Bounce();
Bounce button1debouncer = Bounce();
Bounce button2debouncer = Bounce();
Bounce button3debouncer = Bounce();
Bounce button4debouncer = Bounce();
int oldValueButt1=-1;
int oldValueButt2=-1;
int oldValueButt3=-1;
int oldValueButt4=-1;int lastMOTION;
unsigned long SLEEP_TIME = 10000;
unsigned long blockMotionTimer = 0;MySensor gw;
#define noRelays 3
const int relayPin[] = {A3, A7, A6}; // switch around pins to your desire
const int buttonPin[] = {4, A5, 7}; // switch around pins to your desireclass Relay // relay class, store all relevant data (equivalent to struct)
{
public:
int buttonPin; // physical pin number of button
int relayPin; // physical pin number of relay
byte oldValue; // last Values for key (debounce)
boolean relayState; // relay status (also stored in EEPROM)
};Relay Relays[noRelays];
Bounce debouncerRELAY[noRelays];
MyMessage msgRELAY[noRelays], msgMOTION(CHILD_ID_MOTION, V_TRIPPED), msgBUTTON1(CHILD_ID_BUTTON1,V_TRIPPED), msgBUTTON2(CHILD_ID_BUTTON2,V_TRIPPED), msgBUTTON3(CHILD_ID_BUTTON3,V_TRIPPED), msgBUTTON4(CHILD_ID_BUTTON4,V_TRIPPED);void setup()
{
//sensors.begin();
//gw.begin();
gw.begin(incomingMessage, AUTO, true);
gw.sendSketchInfo("Motion/Button/relay", "1.0");// Setup the button
pinMode(BUTTON1_PIN,INPUT);
pinMode(BUTTON2_PIN,INPUT);
pinMode(BUTTON3_PIN,INPUT);
pinMode(BUTTON4_PIN,INPUT);
// Activate internal pull-up
digitalWrite(BUTTON1_PIN,HIGH);// Activate internal pull-up
digitalWrite(BUTTON2_PIN,HIGH);
digitalWrite(BUTTON3_PIN,HIGH);
digitalWrite(BUTTON4_PIN,HIGH);gw.present(CHILD_ID_BUTTON1, S_DOOR);
gw.present(CHILD_ID_BUTTON2, S_DOOR);
gw.present(CHILD_ID_BUTTON3, S_DOOR);
gw.present(CHILD_ID_BUTTON4, S_DOOR);// After setting up the button, setup debouncer
button1debouncer.attach(BUTTON1_PIN);
button1debouncer.interval(5);
button2debouncer.attach(BUTTON2_PIN);
button2debouncer.interval (5);
button3debouncer.attach(BUTTON3_PIN);
button3debouncer.interval(5);
button4debouncer.attach(BUTTON4_PIN);
button4debouncer.interval (5);// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
gw.present(CHILD_ID_BUTTON1, S_DOOR);
gw.present(CHILD_ID_BUTTON2, S_DOOR);
gw.present(CHILD_ID_BUTTON3, S_DOOR);
gw.present(CHILD_ID_BUTTON4, S_DOOR);pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP); // sets the motion sensor digital pin as input
motionsDebouncer.attach(DIGITAL_MOTION_SENSOR);
motionsDebouncer.interval(400);
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true);for (int i = 0; i < noRelays; i++)
{
Relays[i].buttonPin = buttonPin[i]; // assign physical pins
Relays[i].relayPin = relayPin[i];
msgRELAY[i].sensor = i; // initialize messages
msgRELAY[i].type = V_LIGHT;
debouncerRELAY[i] = Bounce(); // initialize debouncer
debouncerRELAY[i].attach(buttonPin[i]);
debouncerRELAY[i].interval(5);
pinMode(Relays[i].buttonPin, INPUT_PULLUP);
pinMode(Relays[i].relayPin, OUTPUT);
Relays[i].relayState = gw.loadState(i); // retrieve last values from EEPROM
digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
gw.send(msgRELAY[i].set(Relays[i].relayState ? true : false)); // make controller aware of last status
gw.present(i, S_LIGHT); // present sensor to gateway
delay(250);}
}
void loop()
{
gw.process();button1debouncer.update();
// Get the update value
int value = button1debouncer.read();if (value != oldValueButt1) {
// Send in the new value
gw.send(msgBUTTON1.set(value==HIGH ? 1 : 0));
oldValueButt1 = value;
}
button2debouncer.update();
// Get the update value
value = button2debouncer.read();if (value != oldValueButt2) {
// Send in the new value
gw.send(msgBUTTON2.set(value==HIGH ? 1 : 0));
oldValueButt2 = value;
}
button3debouncer.update();
// Get the update value
value = button3debouncer.read();if (value != oldValueButt3) {
// Send in the new value
gw.send(msgBUTTON3.set(value==HIGH ? 1 : 0));
oldValueButt3 = value;
}
button4debouncer.update();
// Get the update value
value = button4debouncer.read();if (value != oldValueButt4) {
// Send in the new value
gw.send(msgBUTTON4.set(value==HIGH ? 1 : 0));
oldValueButt4 = value;
}for (byte i = 0; i < noRelays; i++)
{
debouncerRELAY[i].update();
byte value = debouncerRELAY[i].read();
if (value != Relays[i].oldValue && value == 0)
{
Relays[i].relayState = !Relays[i].relayState;
digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF);
gw.send(msgRELAY[i].set(Relays[i].relayState ? true : false));
gw.saveState( i, Relays[i].relayState );
} // save sensor state in EEPROM (location == sensor number)Relays[i].oldValue = value;
}
if (blockMotionTimer == 0) {
if (motionsDebouncer.update()) {
int value = motionsDebouncer.read();
Serial.println( "PIR " + (String)value );
gw.send( msgMOTION.set( value ), true ); // Also it might need inverted value
blockMotionTimer = (millis() + SLEEP_TIME);
}
} else {
motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires
if (blockMotionTimer < millis()) {
blockMotionTimer = 0;
}
}}
void incomingMessage(const MyMessage &message)
{if (message.type == V_LIGHT)
{
if (message.sensor < noRelays) // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]]
{
Relays[message.sensor].relayState = message.getBool();
digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly
gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
}
}
//gw.wait(50);}
-
RE: pir trigger must start delay
@BartE What an extended answere. Here I can do something with. Good learning stuff.
-
RE: pir trigger must start delay
@BartE It works fine. Now I try to understand how it works, have found already some documentation about this item. again thanks!
-
RE: pir trigger must start delay
@BartE Hi Bart thanks for the solution but hopefully you can help me with the last hurdle:
I added your solution, after starting the node I can activate the PIR once (it state change from 1 to 0) and stays in 0 and will not change anymore.
Here the code as it is now// 2x binary switch + dallas temp example // Connect button or door/window reed switch between // digitial I/O pin 4,5 (BUTTON_PIN_4/BUTTON_PIN_5 below) and GND. // Connect dallas temp sensor to digital pin 3 #include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #include <DallasTemperature.h> #include <OneWire.h> #define DIGITAL_MOTION_SENSOR 2 #define CHILD_ID_MOTION 6 #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 #define RELAY_ON 0 // switch around for realy HIGH/LOW state #define RELAY_OFF 1 Bounce motionsDebouncer = Bounce(); int lastMOTION; unsigned long SLEEP_TIME = 3600; unsigned long blockMotionTimer = 0; OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); MySensor gw; #define noRelays 3 const int relayPin[] = {A3, A4, A5}; // switch around pins to your desire const int buttonPin[] = {6, 7, 8}; // switch around pins to your desire class Relay // relay class, store all relevant data (equivalent to struct) { public: int buttonPin; // physical pin number of button int relayPin; // physical pin number of relay byte oldValue; // last Values for key (debounce) boolean relayState; // relay status (also stored in EEPROM) }; Relay Relays[noRelays]; Bounce debouncerRELAY[noRelays]; MyMessage msgRELAY[noRelays]; float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; boolean receivedConfig = false; boolean metric = true; MyMessage msg(0,V_TEMP); MyMessage msgMOTION(CHILD_ID_MOTION, V_TRIPPED); void setup() { sensors.begin(); //gw.begin(); gw.begin(incomingMessage, AUTO, true); gw.sendSketchInfo("Motion/Temp/relay", "1.0"); numSensors = sensors.getDeviceCount(); for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { gw.present(i, S_TEMP); } pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP); // sets the motion sensor digital pin as input motionsDebouncer.attach(DIGITAL_MOTION_SENSOR); motionsDebouncer.interval(400); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true); for (int i = 0; i < noRelays; i++) { Relays[i].buttonPin = buttonPin[i]; // assign physical pins Relays[i].relayPin = relayPin[i]; msgRELAY[i].sensor = i; // initialize messages msgRELAY[i].type = V_LIGHT; debouncerRELAY[i] = Bounce(); // initialize debouncer debouncerRELAY[i].attach(buttonPin[i]); debouncerRELAY[i].interval(5); pinMode(Relays[i].buttonPin, INPUT_PULLUP); pinMode(Relays[i].relayPin, OUTPUT); Relays[i].relayState = gw.loadState(i); // retrieve last values from EEPROM digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly gw.send(msgRELAY[i].set(Relays[i].relayState ? true : false)); // make controller aware of last status gw.present(i, S_LIGHT); // present sensor to gateway delay(250); } } void loop() { gw.process(); for (byte i = 0; i < noRelays; i++) { debouncerRELAY[i].update(); byte value = debouncerRELAY[i].read(); if (value != Relays[i].oldValue && value == 0) { Relays[i].relayState = !Relays[i].relayState; digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); gw.send(msgRELAY[i].set(Relays[i].relayState ? true : false)); gw.saveState( i, Relays[i].relayState ); } // save sensor state in EEPROM (location == sensor number) Relays[i].oldValue = value; } if (blockMotionTimer == 0) { { if (motionsDebouncer.update()) { int value = motionsDebouncer.read(); Serial.println( "PIR " + (String)value ); gw.send( msgMOTION.set( value ), true ); // Also it might need inverted value blockMotionTimer = (millis() + SLEEP_TIME); } else { motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires if (blockMotionTimer < millis()) { blockMotionTimer = 0; } } } } updateTemperature(30);// update time in seconds } void updateTemperature(int frequency) { static unsigned long lastUpdateTime; if (millis() - lastUpdateTime >= frequency * 1000UL) { sensors.requestTemperatures(); for (int i=0; i<numSensors && i< MAX_ATTACHED_DS18B20; i++) { float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; if (lastTemperature[i] != temperature && temperature != -127.00) { gw.send(msg.setSensor(i).set(temperature,1)); lastTemperature[i]=temperature; } } lastUpdateTime += frequency * 1000UL; } } void incomingMessage(const MyMessage &message) { if (message.type == V_LIGHT) { if (message.sensor < noRelays) // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]] { Relays[message.sensor].relayState = message.getBool(); digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number) } } //gw.wait(50); } `
-
RE: pir trigger must start delay
@m26872 No Problem. I continue reading. If someone else knows what to do please reply.
-
RE: pir trigger must start delay
@m26872 it is all new for me this solution. How can I make them global?? that means outside the function? is that the only thing I have to do?
-
RE: pir trigger must start delay
@m26872 I implemented the function but it does not work. I also read more about the NON BLOCKING code. is new for me. At the moment the pir pin give no reaction. nothing happend with the new function. The relays and temp sensors are working fine. Any idea to get it work so I can see a working example so I can use it in my other sensors.
-
RE: pir trigger must start delay
@m26872
thanks for the short lesson. I change the code it test it. -
RE: pir trigger must start delay
Here the code to make it more clear
@Dick said in pir trigger must start delay:
Is there anyone who can me help with the next step in getting this sensor to work. It is a combi of 3 relays, motion sensor and 2 temps. All works now but if the Motion is triggered it starts the SLEEP_TIME. but in this period I cannot use the buttons to activate the relays. How can I only stop the motion trigger (for a period of time) without affecting the test of the sensors.
// 2x binary switch + dallas temp example // Connect button or door/window reed switch between // digitial I/O pin 4,5 (BUTTON_PIN_4/BUTTON_PIN_5 below) and GND. // Connect dallas temp sensor to digital pin 3 #include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #include <DallasTemperature.h> #include <OneWire.h> #define DIGITAL_MOTION_SENSOR 2 #define CHILD_ID_MOTION 6 #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 #define RELAY_ON 0 // switch around for realy HIGH/LOW state #define RELAY_OFF 1 Bounce motionsDebouncer = Bounce(); int lastMOTION; unsigned long SLEEP_TIME = 60000; OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); MySensor gw; #define noRelays 3 const int relayPin[] = {A3, A4, A5}; // switch around pins to your desire const int buttonPin[] = {6, 7, 8}; // switch around pins to your desire class Relay // relay class, store all relevant data (equivalent to struct) { public: int buttonPin; // physical pin number of button int relayPin; // physical pin number of relay byte oldValue; // last Values for key (debounce) boolean relayState; // relay status (also stored in EEPROM) }; Relay Relays[noRelays]; Bounce debouncerRELAY[noRelays]; MyMessage msgRELAY[noRelays]; float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; boolean receivedConfig = false; boolean metric = true; MyMessage msg(0,V_TEMP); MyMessage msgMOTION(CHILD_ID_MOTION, V_TRIPPED); void setup() { sensors.begin(); //gw.begin(); gw.begin(incomingMessage, AUTO, true); gw.sendSketchInfo("Motion/Temp/relay", "1.0"); numSensors = sensors.getDeviceCount(); for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { gw.present(i, S_TEMP); } pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP); // sets the motion sensor digital pin as input motionsDebouncer.attach(DIGITAL_MOTION_SENSOR); motionsDebouncer.interval(10); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true); for (int i = 0; i < noRelays; i++) { Relays[i].buttonPin = buttonPin[i]; // assign physical pins Relays[i].relayPin = relayPin[i]; msgRELAY[i].sensor = i; // initialize messages msgRELAY[i].type = V_LIGHT; debouncerRELAY[i] = Bounce(); // initialize debouncer debouncerRELAY[i].attach(buttonPin[i]); debouncerRELAY[i].interval(5); pinMode(Relays[i].buttonPin, INPUT_PULLUP); pinMode(Relays[i].relayPin, OUTPUT); Relays[i].relayState = gw.loadState(i); // retrieve last values from EEPROM digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly gw.send(msgRELAY[i].set(Relays[i].relayState ? true : false)); // make controller aware of last status gw.present(i, S_LIGHT); // present sensor to gateway delay(250); } } void loop() { gw.process(); for (byte i = 0; i < noRelays; i++) { debouncerRELAY[i].update(); byte value = debouncerRELAY[i].read(); if (value != Relays[i].oldValue && value == 0) { Relays[i].relayState = !Relays[i].relayState; digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); gw.send(msgRELAY[i].set(Relays[i].relayState ? true : false)); gw.saveState( i, Relays[i].relayState ); } // save sensor state in EEPROM (location == sensor number) Relays[i].oldValue = value; } if ( motionsDebouncer.update()) { int value = motionsDebouncer.read(); Serial.println( "PIR " + (String)value ); gw.send( msgMOTION.set( value ), true ); // Also it might need inverted value // Sleep until interrupt comes in on motion sensor. Send update. gw.sleep(DIGITAL_MOTION_SENSOR, CHANGE, SLEEP_TIME); } updateTemperature(30);// update time in seconds } void updateTemperature(int frequency) { static unsigned long lastUpdateTime; if (millis() - lastUpdateTime >= frequency * 1000UL) { sensors.requestTemperatures(); for (int i=0; i<numSensors && i< MAX_ATTACHED_DS18B20; i++) { float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; if (lastTemperature[i] != temperature && temperature != -127.00) { gw.send(msg.setSensor(i).set(temperature,1)); lastTemperature[i]=temperature; } } lastUpdateTime += frequency * 1000UL; } } void incomingMessage(const MyMessage &message) { if (message.type == V_LIGHT) { if (message.sensor < noRelays) // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]] { Relays[message.sensor].relayState = message.getBool(); digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number) } } //gw.wait(50); }
-
pir trigger must start delay
Is there anyone who can me help with the next step in getting this sensor to work. It is a combi of 3 relays, motion sensor and 2 temps. All works now but if the Motion is triggered it starts the SLEEP_TIME. but in this period I cannot use the buttons to activate the relays. How can I only stop the motion trigger (for a period of time) without affecting the test of the sensors.
-
RE: relays do not work using button
@mfalkvidd
you are right, i try to make one relay working. -
RE: relays do not work using button
@mfalkvidd
Thanks for the info. I adjusted what you mentioned but still no reaction. this is what I have changed.InBounce debouncer = Bounce(); int oldValue=0; bool state; Bounce debouncer_1 = Bounce(); int oldValue_1=0; bool state_1; unsigned long previousMillis = 0; MySensor gw; MyMessage msg2(CHILD_ID,V_LIGHT);//relay_pin A1 MyMessage msg3(CHILD_ID_1,V_LIGHT);//relay_pin A2`
-
relays do not work using button
I have a working temperature compare node and I want to add2 relays with button. I am searching already for of few hours e why the relays are not working after using the buttons.
Can anyone give me a tip ?#include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #include <DallasTemperature.h> #include <OneWire.h> // Partie Température #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; boolean receivedConfig = false; boolean metric = true; // Initialize temperature message MyMessage msg(0,V_TEMP); // Partie Relay #define RELAY_PIN A1 // Arduino Digital I/O pinnumber for relay #define BUTTON_PIN A3 // Arduino Digital I/O pin number for button #define CHILD_ID 17 // Id of the sensor child #define RELAY_PIN_1 A2 // Arduino Digital I/O pinnumber for relay #define BUTTON_PIN_1 A4 // Arduino Digital I/O pin number for button #define CHILD_ID_1 18 // Id of the sensor child #define RELAY_ON 1 #define RELAY_OFF 0 Bounce debouncer = Bounce(); int oldValue=0; bool state; unsigned long previousMillis = 0; MySensor gw; MyMessage msg2(CHILD_ID,V_LIGHT);//relay_pin A1 MyMessage msg3(CHILD_ID,V_LIGHT);//relay_pin A2 void setup() { // Startup up the OneWire library sensors.begin(); // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); gw.begin(incomingMessage, AUTO, true); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Relay & Button", "1.0"); gw.sendSketchInfo("Temperature Sensor", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); Serial.print(numSensors); Serial.println(" temperature sensors detected"); // Setup the button pinMode(BUTTON_PIN,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN,HIGH); pinMode(BUTTON_PIN_1,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN_1,HIGH); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); debouncer.attach(BUTTON_PIN_1); debouncer.interval(5); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { gw.present(i, S_TEMP); } // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_LIGHT); gw.present(CHILD_ID_1, S_LIGHT); // Make sure relays are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN_1, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_PIN_1, OUTPUT); // Set relay to last known state (using eeprom storage) state = gw.loadState(CHILD_ID); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); state = gw.loadState(CHILD_ID); digitalWrite(RELAY_PIN_1, state?RELAY_ON:RELAY_OFF); } /* * Example on how to asynchronously check for new messages from gw */ void loop() { gw.process(); // Relay button debouncer.update(); // Get the update value int value = debouncer.read(); if (value != oldValue && value==0) { gw.send(msg2.set(state?false:true), true); // Send new state and request ack back gw.send(msg3.set(state?false:true), true); } oldValue = value; // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed //int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); unsigned long currentMillis = millis(); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) // gw.wait(conversionTime); // Read temperatures and send them to controller if (currentMillis - previousMillis >= SLEEP_TIME) { // save the last time you read temperature previousMillis = currentMillis; for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature gw.send(msg.setSensor(i).set(temperature,1)); // Save new temperatures for next compare lastTemperature[i]=temperature; } } } } void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); digitalWrite(RELAY_PIN_1, state?RELAY_ON:RELAY_OFF); // Store state in eeprom gw.saveState(CHILD_ID, state); gw.saveState(CHILD_ID_1, state); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } Insert Code Here
-
RE: Binary switch not working
@AWI I changed it and compiling worked good. But what I noticed that if i connect the A5 (Binary pin) to - I see no Send led on my nano. Perhaps another issue? al the other sensors are working still but only the binary switch Not.
Any idea?#include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #include <DallasTemperature.h> #include <OneWire.h> // Partie Température #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors = 0; boolean receivedConfig = false; boolean metric = true; // Initialize temperature message MyMessage msg(0, V_TEMP); // Partie Relay #define RELAY_PIN A1 // Arduino Digital I/O pinnumber for relay #define BUTTON_PIN A3 // Arduino Digital I/O pin number for button #define CHILD_ID 17 // Id of the sensor child #define RELAY_ON 1 #define RELAY_OFF 0 #define CHILD_ID1 5 //radar #define BUTTON_PIN1 A5 //radar Bounce debouncerA3 = Bounce(); int oldValueA3 = 0; bool state; unsigned long previousMillis = 0; MySensor gw; MyMessage msg2(CHILD_ID, V_LIGHT); Bounce debouncerA5 = Bounce(); //radar int oldValueA5 = -1; //radar MyMessage msgA5(CHILD_ID, V_TRIPPED); void setup() { // Startup up the OneWire library sensors.begin(); // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); pinMode(BUTTON_PIN1, INPUT); //radar digitalWrite(BUTTON_PIN1, HIGH); //radar debouncerA5.attach(BUTTON_PIN1); //radar debouncerA5.interval(5); //radar gw.present(CHILD_ID1, S_DOOR); //radar gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Relay & Button", "1.0"); gw.sendSketchInfo("Temperature Sensor", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); Serial.print(numSensors); Serial.println(" temperature sensors detected"); // Setup the button pinMode(BUTTON_PIN, INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN, HIGH); // After setting up the button, setup debouncer debouncerA3.attach(BUTTON_PIN); debouncerA3.interval(5); // Present all sensors to controller for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { gw.present(i, S_TEMP); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_LIGHT); // Make sure relays are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) state = gw.loadState(CHILD_ID); digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF); } } /* Example on how to asynchronously check for new messages from gw */ void loop() { gw.process(); debouncerA5.update(); //radar // Get the update value int value = debouncerA5.read(); //radar if (value != oldValueA5) //radar { // Send in the new value gw.send(msg.set(value == HIGH ? 1 : 0)); //radar oldValueA5 = value; //radar // Relay button debouncerA3.update(); // Get the update value int value = debouncerA3.read(); if (value != oldValueA3 && value == 0) { gw.send(msg2.set(state ? false : true), true); // Send new state and request ack back } oldValueA3 = value; // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed //int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); unsigned long currentMillis = millis(); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) // gw.wait(conversionTime); // Read temperatures and send them to controller if (currentMillis - previousMillis >= SLEEP_TIME) { // save the last time you read temperature previousMillis = currentMillis; for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature gw.send(msg.setSensor(i).set(temperature, 1)); // Save new temperatures for next compare lastTemperature[i] = temperature; } } } } } void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF); // Store state in eeprom gw.saveState(CHILD_ID, state); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
-
Binary switch not working
Can anybody help me out. I have a working combination node with 2 temp sens0rs, button and relais. it works fine but I needed a binary switch in it. I added the switch to the code but it will not work. I think the problem is in the "LOOP" part. I am always strugling with the {}. Perhaps somebode can take a look in the code and what I added to the working code has the comment "//radar". pls let me know.
#include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #include <DallasTemperature.h> #include <OneWire.h> // Partie Température #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 900000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors = 0; boolean receivedConfig = false; boolean metric = true; // Initialize temperature message MyMessage msg(0, V_TEMP); // Partie Relay #define RELAY_PIN A1 // Arduino Digital I/O pinnumber for relay #define BUTTON_PIN A3 // Arduino Digital I/O pin number for button #define CHILD_ID 17 // Id of the sensor child #define RELAY_ON 1 #define RELAY_OFF 0 #define CHILD_ID1 5 //radar #define BUTTON_PIN1 A5 //radar Bounce debouncerA3 = Bounce(); int oldValueA3 = 0; bool state; unsigned long previousMillis = 0; MySensor gw; MyMessage msg2(CHILD_ID, V_LIGHT); Bounce debouncerA5 = Bounce(); //radar int oldValueA5 = -1; //radar MyMessage msgA5(CHILD_ID, V_TRIPPED); void setup() { // Startup up the OneWire library sensors.begin(); // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); pinMode(BUTTON_PIN1, INPUT); //radar digitalWrite(BUTTON_PIN1, HIGH); //radar debouncerA5.attach(BUTTON_PIN1); //radar debouncerA5.interval(5); //radar gw.present(CHILD_ID1, S_DOOR); //radar gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Relay & Button", "1.0"); gw.sendSketchInfo("Temperature Sensor", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); Serial.print(numSensors); Serial.println(" temperature sensors detected"); // Setup the button pinMode(BUTTON_PIN, INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN, HIGH); // After setting up the button, setup debouncer debouncerA3.attach(BUTTON_PIN); debouncerA3.interval(5); // Present all sensors to controller for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { gw.present(i, S_TEMP); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_LIGHT); // Make sure relays are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) state = gw.loadState(CHILD_ID); digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF); } } void loop() { gw.process(); // Relay button debouncerA3.update(); // Get the update value int value = debouncerA3.read(); if (value != oldValueA3 && value == 0) { gw.send(msg2.set(state ? false : true), true); // Send new state and request ack back } oldValueA3 = value; // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed //int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); unsigned long currentMillis = millis(); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) // gw.wait(conversionTime); // Read temperatures and send them to controller if (currentMillis - previousMillis >= SLEEP_TIME) { // save the last time you read temperature previousMillis = currentMillis; for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature gw.send(msg.setSensor(i).set(temperature, 1)); // Save new temperatures for next compare lastTemperature[i] = temperature; } debouncerA5.update(); //radar // Get the update value int value = debouncerA5.read(); //radar if (value != oldValueA5) //radar { // Send in the new value gw.send(msg.set(value == HIGH ? 1 : 0)); //radar oldValueA5 = value; //radar } } } } void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF); // Store state in eeprom gw.saveState(CHILD_ID, state); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
-
RE: Send notification/email x-times
@gus thanks for the info, it looks good. I will try to start with it tomorrow. Hope it can help me.
-
RE: Send notification/email x-times
@sundberg84
Thanks for the reply. It is clear that I need to find a good starting point for LUA script because I do not have any knowledge of that. -
Send notification/email x-times
I want to send an notification/email of a Dummy switch X-times after changing the status of it. How can I get that in place the best way? the X-times is very important for my project.
-
RE: temp sensor keep on loging status switch
no good to mention, That is a new project for me to build an efficience battery powered node. In this case it is powered by an external power source.
-
RE: temp sensor keep on loging status switch
that was easy, I do it right away. Thanks for the support and this stopped me for changing other parts of the event of the code of the sensor.
Have a nice day! -
RE: temp sensor keep on loging status switch
this sensor only messure the temp on 2 different locations and as seen in the Event, if the temp inside (TEMP binnen temp) <- 20 and the temp in the glasshouse is >-26 the fan switch on and the second part of the Event only switch of the Fan if the temp inside is to high (>-26) or the temp in the glasshouse is <-27. that is all I want with this project. I only want the mesurement every 15 min for example
-
RE: temp sensor keep on loging status switch
Yes you are right there is an Event. Do I have to add a timer or delay function in it or something else?
-
temp sensor keep on loging status switch
I have a working sensor that checks the temp om 2 places. If needed it wil switch on/of a Fan. That is all working perfect only this sensor logs continue the status of the switch. i am using Domoticz.
the log looks like this:2017-01-05 19:24:18.747 EventSystem: Event triggered: ventilator aan/uit_2
2017-01-05 19:24:18.741 (MySensors GW1) Temp (Temp serre)
2017-01-05 19:24:18.960 (MySensors GW1) Lighting 2 (Temp Fan switch)
2017-01-05 19:24:48.736 EventSystem: Event triggered: ventilator aan/uit_2
2017-01-05 19:24:48.730 (MySensors GW1) Temp (Temp serre)
2017-01-05 19:24:49.068 (MySensors GW1) Lighting 2 (Temp Fan switch)
2017-01-05 19:26:49.032 EventSystem: Event triggered: ventilator aan/uit_2
2017-01-05 19:26:49.027 (MySensors GW1) Temp (Temp binnen)
2017-01-05 19:26:49.182 (MySensors GW1) Lighting 2 (Temp Fan switch)
2017-01-05 19:27:49.049 EventSystem: Event triggered: ventilator aan/uit_2
2017-01-05 19:27:49.044 (MySensors GW1) Temp (Temp serre)
2017-01-05 19:27:49.291 (MySensors GW1) Lighting 2 (Temp Fan switch)
2017-01-05 19:28:48.988 EventSystem: Event triggered: ventilator aan/uit_2
2017-01-05 19:28:48.985 (MySensors GW1) Temp (Temp binnen)
2017-01-05 19:28:49.401 (MySensors GW1) Lighting 2 (Temp Fan switch)
2017-01-05 19:29:18.972 EventSystem: Event triggered: ventilator aan/uit_2 italicised textThis is my code
#include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #include <DallasTemperature.h> #include <OneWire.h> // Partie Température #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; boolean receivedConfig = false; boolean metric = true; // Initialize temperature message MyMessage msg(0,V_TEMP); // Partie Relay #define RELAY_PIN A1 // Arduino Digital I/O pinnumber for relay #define BUTTON_PIN A3 // Arduino Digital I/O pin number for button #define CHILD_ID 17 // Id of the sensor child #define RELAY_ON 1 #define RELAY_OFF 0 Bounce debouncer = Bounce(); int oldValue=0; bool state; unsigned long previousMillis = 0; MySensor gw; MyMessage msg2(CHILD_ID,V_LIGHT); void setup() { // Startup up the OneWire library sensors.begin(); // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); gw.begin(incomingMessage, AUTO, true); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Relay & Button", "1.0"); gw.sendSketchInfo("Temperature Sensor", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); Serial.print(numSensors); Serial.println(" temperature sensors detected"); // Setup the button pinMode(BUTTON_PIN,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN,HIGH); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); // Present all sensors to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { gw.present(i, S_TEMP); } // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_LIGHT); // Make sure relays are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) state = gw.loadState(CHILD_ID); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); } /* * Example on how to asynchronously check for new messages from gw */ void loop() { gw.process(); // Relay button debouncer.update(); // Get the update value int value = debouncer.read(); if (value != oldValue && value==0) { gw.send(msg2.set(state?false:true), true); // Send new state and request ack back } oldValue = value; // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // query conversion time and sleep until conversion completed //int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution()); unsigned long currentMillis = millis(); // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater) // gw.wait(conversionTime); // Read temperatures and send them to controller if (currentMillis - previousMillis >= SLEEP_TIME) { // save the last time you read temperature previousMillis = currentMillis; for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { #else if (temperature != -127.00 && temperature != 85.00) { #endif // Send in the new temperature gw.send(msg.setSensor(i).set(temperature,1)); // Save new temperatures for next compare lastTemperature[i]=temperature; } } } } void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Store state in eeprom gw.saveState(CHILD_ID, state); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
Does anyone know why it produce that large amount of logs?
-
RE: bi stable 2 coil relais switch
after reading some documentation , I can use a double 'door, window and push' button. the status is not inportant because the state of the relais is stored in the relais itself.
-
bi stable 2 coil relais switch
I have no idea where to start, I have a bi stable relais with 2 coils 3v, I want to use it as a batt powered switch using one button. So push once A2 is High for 1 sec, push a second time A3 is high for 1 second. The latest status must be stored in case of a power failure. Does anyone have start code for this project? Most imporatant is how to store the last status of one of the coils.
-
RE: error auto restart pi
@mfalkvidd I did not noticed that, I changed it to disabled and will monitor it during the upcomming days. Thanks for the tip!
-
error auto restart pi
I am using a Pi3 for my Domoticz. Already from the beginning it is not stable and it stops working after a few days. Today I did a fresh install using the SD installation procedure including the memory extend, time zone and password change.
Only i sensor attached (double temp sensor).
Immediate I receive a error:ERROR: pi hardware (4) nothing received for more then 5 Minutes!....
Error: Restarting: pibolded textitalicised textDoes anybody know if this is normal behaviour? The sensors only send data if a change of 1 degr is detected.
-
RE: 2 Reed Switches 1 Arduino Nano
The compiler is unable to find out what "value" is, since it has not been used before.
Try thisgw.send(msg.set(HIGH));
-
RE: one button code lock
@TheoL Finish what is needed, ï„‘
mfalkvidd gave me already some advise so next week I can test the project. I hope you have a good holiday. Again about the other hobby, working with wood, it is also one of my hobbies. Most of the time only creating housings for my projects. next year I want to start an CNC project. -
RE: one button code lock
@mfalkvidd , I added the change you advised and no erroros in the compilation anymore.
I will post the result after my testing of the project. Thanks for the support. -
RE: one button code lock
Thanks for the reply. I modified the items you stated in your reply. I did not know the use of the "auto format" tools. that makes life easier. About the logic I want to use is the status of the relay "digitalWrite(RELAY_PIN, HIGH); " so I can use that info in Domoticz.
-
RE: one button code lock
@TheoL Nevermind, I am on holiday and I only prepare some projects and this was one of them. If you have time later this week or next week, take your time. Compliment for your website. strait forward and it giave me also some ideas about houtbewerking.
have a nice evening. -
RE: one button code lock
this is the code untill now with one compilation error. I installed the Arduino IDE and add the Mysensors master to it but it did not solve the proble.
#include <SPI.h> #include <MySensors.h> //#define SKETCH_NAME "One Button Code Lock" #define CHILD_ID_CODE 5 #define RELAY_PIN 3 //Arduino Digital I/O pin number for relay #define BUTTON_PIN 2 // Arduino Digital I/O pin for button/reed switch #define LED_PIN 4 #define RELAY_ON 1 #define RELAY_OFF 0 MySensor gw; //original code code_lock int count=0; unsigned long a[]={0,0,0,0,0}; unsigned long b[]={0,0,0,0,0}; unsigned long del[]={1000,1000,1000,5000}; float tolerance=.4; MyMessage msg(CHILD_ID,V_TRIPPED); void setup() { gw.begin(); pinMode(BUTTON_PIN, INPUT); pinMode(RELAY_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT); } void dataCapture() { a[count]=millis(); delay(500); // for button debounce, your value may differ count++; } void checkCombination() { int compare=0; count=0; // calcualate delays between keypresses b[0]=a[1]-a[0]; b[1]=a[2]-a[1]; b[2]=a[3]-a[2]; b[3]=a[4]-a[3]; // compare the button delay values if (b[0]<=(del[0]*(1+tolerance)) && b[0]>=(del[0]*(1-tolerance))) { compare++; } if (b[1]<=(del[1]*(1+tolerance)) && b[1]>=(del[1]*(1-tolerance))) { compare++; } if (b[2]<=(del[2]*(1+tolerance)) && b[2]>=(del[2]*(1-tolerance))) { compare++; } if (b[3]<=(del[3]*(1+tolerance)) && b[3]>=(del[3]*(1-tolerance))) { compare++; } if (compare==4) { digitalWrite(RELAY_PIN,HIGH); } delay(3000); digitalWrite(RELAY_PIN,LOW); if (compare!=4) { digitalWrite(LED_PIN,HIGH); } delay(3000); digitalWrite(LED_PIN,LOW); gw.present(CHILD_ID, S_DOOR); } void loop() { if (digitalRead(2)==HIGH) gw.send(msg.set(value==HIGH ? 1 : 0)); { dataCapture(); } if (count>4) { checkCombination(); } }
the error code during compilation is
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\arduino-1.6.11\hardware\arduino\avr\libraries\SPI
exit status 1
Error compiling for board Arduino Nano.
This is also during the selection of an UNO.
Any idea???
And is this code working using the 1.5.4. lib. -
one button code lock
Can anybody help me with this project I found on the internet. It is not a MYSENSORS project but who can help me to make it working in Mysensors? I use a serial gateway to Domoticz. I want to use a match of the code in Domoticz.
This is the code:
int count=0; unsigned long a[]={0,0,0,0,0}; unsigned long b[]={0,0,0,0,0}; unsigned long del[]={1000,1000,1000,5000}; float tolerance=.4; void setup() { pinMode(2, INPUT); pinMode(10, OUTPUT); pinMode(13, OUTPUT); } void dataCapture() { a[count]=millis(); delay(500); // for button debounce, your value may differ count++; } void checkCombination() { int compare=0; count=0; // calcualate delays between keypresses b[0]=a[1]-a[0]; b[1]=a[2]-a[1]; b[2]=a[3]-a[2]; b[3]=a[4]-a[3]; // compare the button delay values if (b[0]<=(del[0]*(1+tolerance)) && b[0]>=(del[0]*(1-tolerance))) { compare++; } if (b[1]<=(del[1]*(1+tolerance)) && b[1]>=(del[1]*(1-tolerance))) { compare++; } if (b[2]<=(del[2]*(1+tolerance)) && b[2]>=(del[2]*(1-tolerance))) { compare++; } if (b[3]<=(del[3]*(1+tolerance)) && b[3]>=(del[3]*(1-tolerance))) { compare++; } if (compare==4) { digitalWrite(10,HIGH); } delay(3000); digitalWrite(10,LOW); if (compare!=4) { digitalWrite(13,HIGH); } delay(3000); digitalWrite(13,LOW); } void loop() { if (digitalRead(2)==HIGH) { dataCapture(); } if (count>4) { checkCombination(); } }
-
RE: gw send, how to do in my combination of sensors
@TheoL My Domoticz works again, I have to give it a fix ip because the IP was change and for your info, Your solution worked very well. It is now visible in Domoticz. Thanks for the support now I have to wait for other parts, I wait for my last parts for this project, an IR receiver so I can use a remote controle. After that I can use this project as a universal project, a default design in basic.
Again thanks! -
RE: gw send, how to do in my combination of sensors
@TheoL
Hi Theo, the devil is playing with me, my PI stopped working and that is my Domoticz location. I read your commend, thank you for that, I am probably not able to test it this evening.
sorry for that> I inform you about the results. -
RE: gw send, how to do in my combination of sensors
@mfalkvidd
Yes I did bud than I do not understand what I have now,if ( motionsDebouncer.update()) { int value = motionsDebouncer.read(); Serial.println( "PIR " + (String)value );``` only a GW send row needed or is that not right? What I saw on the https://www.mysensors.org/build/motion was clear but after implementation I got several errors during the compilation so I thought, perhaps only something with GW.send Or am I wrong?
-
RE: gw send, how to do in my combination of sensors
not yet, stil working with the 1.54. in the IDE serial it works all fine but the motion sensor is not visible in DOMOTICZ and probably because I do not send to GW but I am new in this area so support is welcome.
-
gw send, how to do in my combination of sensors
In my project in development, I miss the GW send for my motion detector. I tried several options but nothing works. Anyone an idea, how to?
#include <MySensor.h> #include <SPI.h> #include "Bounce2.h" #define USE_MOTION_SENSOR #define MOTION_SENSOR_PIN 3 //physical number of PIR #define LIGHT_SENSOR_ANALOG_PIN A0 //physical number of LDR #define CHILD_ID_LIGHT 6 #define RELAY_ON 0 // switch around for realy HIGH/LOW state #define RELAY_OFF 1 Bounce motionsDebouncer = Bounce(); MySensor gw; #define RADIO_ID 11 // radio Id, whatever channel you assigned to #define noRelays 5 //number of relais in use const int relayPin[] = {A1, A2, A3, A4, A5}; // switch around pins to your desire number of relais const int buttonPin[] = {4, 5, 6, 7, 8 }; // switch around pins to your desire number of buttons class Relay // relay class, store all relevant data (equivalent to struct) { public: int buttonPin; // physical pin number of button int relayPin; // physical pin number of relay byte oldValue; // last Values for key (debounce) boolean relayState; // relay status (also stored in EEPROM) }; Relay Relays[noRelays]; Bounce debouncer[noRelays]; MyMessage msgRelay[noRelays]; MyMessage msgLDR(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; unsigned long SLEEP_TIME = 6000; // Sleep time between reads (in milliseconds) void setup() { gw.begin(incomingMessage, RADIO_ID, true); delay(250); gw.sendSketchInfo("Multy-Relay&button-PIR&LDR", "0.2"); delay(250); gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); pinMode( MOTION_SENSOR_PIN, INPUT_PULLUP ); motionsDebouncer.attach(MOTION_SENSOR_PIN); motionsDebouncer.interval(50); // Initialize Relays with corresponding buttons for (int i = 0; i < noRelays; i++) { Relays[i].buttonPin = buttonPin[i]; // assign physical pins Relays[i].relayPin = relayPin[i]; msgRelay[i].sensor = i; // initialize messages msgRelay[i].type = V_LIGHT; debouncer[i] = Bounce(); // initialize debouncer debouncer[i].attach(buttonPin[i]); debouncer[i].interval(5); pinMode(Relays[i].buttonPin, INPUT_PULLUP); pinMode(Relays[i].relayPin, OUTPUT); Relays[i].relayState = gw.loadState(i); // retrieve last values from EEPROM digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly gw.send(msgRelay[i].set(Relays[i].relayState ? true : false)); // make controller aware of last status gw.present(i, S_LIGHT); // present sensor to gateway delay(250); } } void loop() { if ( motionsDebouncer.update()) { int value = motionsDebouncer.read(); Serial.println( "PIR " + (String)value ); } { gw.process(); for (byte i = 0; i < noRelays; i++) { debouncer[i].update(); byte value = debouncer[i].read(); if (value != Relays[i].oldValue && value == 0) { Relays[i].relayState = !Relays[i].relayState; digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); gw.send(msgRelay[i].set(Relays[i].relayState ? true : false)); gw.saveState( i, Relays[i].relayState ); } // save sensor state in EEPROM (location == sensor number) Relays[i].oldValue = value; } int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; //Serial.println(LDR); if ((lightLevel > 1.05 * lastLightLevel)||(lightLevel < 0.95 * lastLightLevel)) //5% difference will send { gw.send(msgLDR.set(lightLevel)); lastLightLevel = lightLevel; Serial.print("LDR"); Serial.println(lightLevel); } } } // process incoming message void incomingMessage(const MyMessage &message) { if (message.type == V_LIGHT) { if (message.sensor < noRelays) // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]] { Relays[message.sensor].relayState = message.getBool(); digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number) } } // delay( 50 ); // give the input pins some rest. Incomming messages are still being processed. gw.wait(50); }
-
RE: dht22 with relay irregular measurement and operation
somebody any suggestions?
-
dht22 with relay irregular measurement and operation
Double dht22 with relay is working good but the 2 DHT's give logging irregular
H1= 50.20
H0= 75.70
H0= 75.80
T1= 23.90
H1= 50.30
T0= 21.40
H0= 75.70
T0= 21.50
H0= 75.90
T0= 21.40
H0= 75.80is it possible to measure in an sequence? Also the relay cannot be used by the button everytime I like, also immediate after the measurement it can be used. is there something wrong in the delay?
Here the code as it is now#include <SPI.h> #include <MySensor.h> #include <DHT.h> #include <Bounce2.h> #define CHILD_ID_HUM1 0 #define CHILD_ID_HUM2 1 #define CHILD_ID_TEMP1 3 #define CHILD_ID_TEMP2 4 // RelayWithActuator stuff #define RELAY_PIN 6 // Arduino Digital I/O pin number for relay #define BUTTON_PIN 7 // Arduino Digital I/O pin number for button #define CHILD_ID 5 // Id of the sensor child #define RELAY_ON 1 #define RELAY_OFF 0 Bounce debouncer = Bounce(); bool state; MySensor gw; MyMessage msg(CHILD_ID,V_LIGHT); #define HEARTBEAT 10 unsigned int timer = 0; // Sleep time between reads (in milliseconds) #define SLEEP_TIME 3000 DHT* dht[2]; byte sensorPin[2] = {3, 4}; float lastTemp[2] = {0.0, 0.0}; float lastHum[2] = {0.0, 0.0}; boolean metric = true; //MyMessage msgHum(CHILD_ID_HUM1, V_HUM); //MyMessage msgTemp(CHILD_ID_TEMP1, V_TEMP); void setup() { gw.begin(incomingMessage, AUTO, true); for (int i = 0; i < 2; i++) { dht[i] = new DHT; dht[i]->setup(sensorPin[i]); } gw.sendSketchInfo("HumidityAndRelay", "1.0"); gw.present(CHILD_ID_HUM1, S_HUM); gw.present(CHILD_ID_HUM2, S_HUM); gw.present(CHILD_ID_TEMP1, S_TEMP); gw.present(CHILD_ID_TEMP1, S_TEMP); // Setup the button and Activate internal pull-up pinMode(BUTTON_PIN,INPUT_PULLUP); // After setting up the button, setup debouncer debouncer.attach(BUTTON_PIN); debouncer.interval(5); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID, S_LIGHT); // Make sure relays are off when starting up digitalWrite(RELAY_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_PIN, OUTPUT); // Set relay to last known state (using eeprom storage) state = gw.loadState(CHILD_ID); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); timer = 0; metric = gw.getConfig().isMetric; } void loop() { gw.process(); timer++; if (timer > (SLEEP_TIME / HEARTBEAT)) { // Reset timer again and for the next timed loop timer = 0; for (int i = 0; i < 2; i++) { delay(dht[i]->getMinimumSamplingPeriod()); float temperature = dht[i]->getTemperature(); if (isnan(temperature)) { Serial.print(F("Failed reading temperature from DHT")); Serial.println(i); } else if (temperature != lastTemp[i]) { lastTemp[i] = temperature; if (!metric) { temperature = dht[i]->toFahrenheit(temperature); } //gw.send(msgTemp.set(temperature, i)); Serial.print(F("T")); Serial.print(i); Serial.print(F("= ")); Serial.println(temperature); } float humidity = dht[i]->getHumidity(); if (isnan(humidity)) { Serial.print("Failed reading humidity from DHT"); Serial.println(i); } else if (humidity != lastHum[i]) { lastHum[i] = humidity; //gw.send(msgHum.set(humidity, 1)); Serial.print(F("H")); Serial.print(i); Serial.print(F("= ")); Serial.println(humidity); } } } // Get the button update state (true if a change was detected) if (debouncer.update() && debouncer.read() == 0) { gw.send(msg.set(state?false:true), true); // Send new state and request ack back } gw.wait(HEARTBEAT); //sleep a bit } void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_LIGHT) { // Change relay state state = message.getBool(); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); // Store state in eeprom gw.saveState(CHILD_ID, state); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }
-
RE: delay for LDR sensor
good luck and i advice you to do it wll otherwise you have an issue
-
RE: delay for LDR sensor
YES yes yes, I did not see that one. Your solution is working perfect also with the difference in light (5%).
Thank you for the support and have a nice weekend
-
RE: delay for LDR sensor
no it is steady with the same amount of light, changing it it keeps steady on the new value but with a hi speed logging. , I checked it just now. The LDR is connected to the +5v and A0 with a resister of 10k to gnd.
-
RE: delay for LDR sensor
that is what I want but it continue with logging (> 1000 per minute).So the sensor is very busy with the LDR only. a delay should be the best or your solution of 5% difference.
-
RE: delay for LDR sensor
1 to 100 depends on the light intencity and it changes the value with more and less light.
-
RE: delay for LDR sensor
thanks for the advise. I changed the If into you sugested (what is much better that 5% difference) but the ldr is still logging (10 per second or so).
any Idea? -
delay for LDR sensor
I am a newbi and I have a working sensor build. A 4 button, 4 Relay and Pir. I added an LDR and that works only it keep on logging. How to stop this, perhaps a delay or something like that and where to place in the script?
The Serial.println(lightLevel);
delay(2500); //just here to slow down the output for easier reading does not work#include <MySensor.h> #include <SPI.h> #include "Bounce2.h" #define USE_MOTION_SENSOR #define MOTION_SENSOR_PIN 3 #define LIGHT_SENSOR_ANALOG_PIN A0 #define CHILD_ID_LIGHT 6 #define RELAY_ON 0 // switch around for realy HIGH/LOW state #define RELAY_OFF 1 Bounce motionsDebouncer = Bounce(); MySensor gw; #define RADIO_ID 11 // radio Id, whatever channel you assigned to #define noRelays 4 const int relayPin[] = {A1, A2, A3, A4}; // switch around pins to your desire const int buttonPin[] = {A5, 6, 7, 8}; // switch around pins to your desire class Relay // relay class, store all relevant data (equivalent to struct) { public: int buttonPin; // physical pin number of button int relayPin; // physical pin number of relay byte oldValue; // last Values for key (debounce) boolean relayState; // relay status (also stored in EEPROM) }; Relay Relays[noRelays]; Bounce debouncer[noRelays]; MyMessage msg[noRelays]; MyMessage msgLDR(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; unsigned long SLEEP_TIME = 6000; // Sleep time between reads (in milliseconds) void setup() { gw.begin(incomingMessage, RADIO_ID, true); delay(250); gw.sendSketchInfo("Multy-Relay&Pulsanti", "0.2"); delay(250); gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); pinMode( MOTION_SENSOR_PIN, INPUT_PULLUP ); motionsDebouncer.attach(MOTION_SENSOR_PIN); motionsDebouncer.interval(50); // Initialize Relays with corresponding buttons for (int i = 0; i < noRelays; i++) { Relays[i].buttonPin = buttonPin[i]; // assign physical pins Relays[i].relayPin = relayPin[i]; msg[i].sensor = i; // initialize messages msg[i].type = V_LIGHT; debouncer[i] = Bounce(); // initialize debouncer debouncer[i].attach(buttonPin[i]); debouncer[i].interval(5); pinMode(Relays[i].buttonPin, INPUT_PULLUP); pinMode(Relays[i].relayPin, OUTPUT); Relays[i].relayState = gw.loadState(i); // retrieve last values from EEPROM digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly gw.send(msg[i].set(Relays[i].relayState ? true : false)); // make controller aware of last status gw.present(i, S_LIGHT); // present sensor to gateway delay(250); } } void loop() { if ( motionsDebouncer.update()) { int value = motionsDebouncer.read(); Serial.println( "Motion sensor is " + (String)value ); } { gw.process(); for (byte i = 0; i < noRelays; i++) { debouncer[i].update(); byte value = debouncer[i].read(); if (value != Relays[i].oldValue && value == 0) { Relays[i].relayState = !Relays[i].relayState; digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); gw.send(msg[i].set(Relays[i].relayState ? true : false)); gw.saveState( i, Relays[i].relayState ); } // save sensor state in EEPROM (location == sensor number) Relays[i].oldValue = value; } int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.println(lightLevel); if (lightLevel != lastLightLevel) { gw.send(msgLDR.set(lightLevel)); lastLightLevel = lightLevel; Serial.print("Lightlevel ="); Serial.println(lightLevel); delay(2500); //just here to slow down the output for easier reading } } } // process incoming message void incomingMessage(const MyMessage &message) { if (message.type == V_LIGHT) { if (message.sensor < noRelays) // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]] { Relays[message.sensor].relayState = message.getBool(); digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number) } } // delay( 50 ); // give the input pins some rest. Incomming messages are still being processed. gw.wait(50); }
-
RE: dht22 2x and LDR and RelayWithButtonActuator
@mfalkvidd ok I understand but now I only have 1 relay, sorry for the perhaps silly questions.