redemarrage domoticz

Un forum dédie à vos questions concernant l'intégration à Domoticz des capteurs et gateway mysensors.org
sphinxou
Messages : 227
Inscription : 03 déc. 2016, 13:37

redemarrage domoticz

Message par sphinxou »

bonjour ci joint le code que j'utilise pour gérer mes entrée est sortie my sensors
le soucis c'est au redémarrage de domoticz pour les entrées par exemple j'ouvre ma fenêtre de cuisine le contact ne s'ouvre spas il faut que je referme et rouvre pour qu'il s'ouvre après sa fonctionne normalement

??

Code : Tout sélectionner

// Enable debug prints to serial monitor
#define MY_DEBUG

// Enable serial gateway
#define MY_GATEWAY_SERIAL

#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>

#define RELAY_PIN 40  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 20 // 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

// Define Sensor ID's
#define KNOB_A_ID 22   // Id of the sensor child
#define KNOB_B_ID 23   // Id of the sensor child
#define KNOB_C_ID 24  // Id of the sensor child
#define KNOB_D_ID 25  // Id of the sensor child
#define KNOB_E_ID 26  // Id of the sensor child
#define KNOB_F_ID 27  // Id of the sensor child
#define KNOB_G_ID 28  // Id of the sensor child
#define KNOB_H_ID 29  // Id of the sensor child
#define KNOB_I_ID 30  // Id of the sensor child
#define KNOB_J_ID 31  // Id of the sensor child
#define KNOB_K_ID 32  // Id of the sensor child
#define KNOB_L_ID 33  // Id of the sensor child
#define KNOB_M_ID 34  // Id of the sensor child
#define KNOB_N_ID 35  // Id of the sensor child

// Define buttons
const int buttonPinA = 22;
const int buttonPinB = 23;
const int buttonPinC = 24;
const int buttonPinD = 25;
const int buttonPinE = 26;
const int buttonPinF = 27;
const int buttonPinG = 28;
const int buttonPinH = 29;
const int buttonPinI = 30;
const int buttonPinJ = 31;
const int buttonPinK = 32;
const int buttonPinL = 33;
const int buttonPinM = 34;
const int buttonPinN = 35;

// Define Variables
int oldValueA = 0;
int oldValueB = 0;
int oldValueC = 0;
int oldValueD = 0;
int oldValueE = 0;
int oldValueF = 0;
int oldValueG = 0;
int oldValueH = 0;
int oldValueI = 0;
int oldValueJ = 0;
int oldValueK = 0;
int oldValueL = 0;
int oldValueM = 0;
int oldValueN = 0;

bool stateA = false;
bool stateB = false;
bool stateC = false;
bool stateD = false;
bool stateE = false;
bool stateF = false;
bool stateG = false;
bool stateH = false;
bool stateI = false;
bool stateJ = false;
bool stateK = false;
bool stateL = false;
bool stateM = false;
bool stateN = false;
int trigger = 0;


Bounce debouncerA = Bounce();
Bounce debouncerB = Bounce();
Bounce debouncerC = Bounce();
Bounce debouncerD = Bounce();
Bounce debouncerE = Bounce();
Bounce debouncerF = Bounce();
Bounce debouncerG = Bounce();
Bounce debouncerH = Bounce();
Bounce debouncerI = Bounce();
Bounce debouncerJ = Bounce();
Bounce debouncerK = Bounce();
Bounce debouncerL = Bounce();
Bounce debouncerM = Bounce();
Bounce debouncerN = Bounce();

MyMessage msgA(KNOB_A_ID, V_STATUS);
MyMessage msgB(KNOB_B_ID, V_STATUS);
MyMessage msgC(KNOB_C_ID, V_STATUS);
MyMessage msgD(KNOB_D_ID, V_STATUS);
MyMessage msgE(KNOB_E_ID, V_STATUS);
MyMessage msgF(KNOB_F_ID, V_STATUS);
MyMessage msgG(KNOB_G_ID, V_STATUS);
MyMessage msgH(KNOB_H_ID, V_STATUS);
MyMessage msgI(KNOB_I_ID, V_STATUS);
MyMessage msgJ(KNOB_J_ID, V_STATUS);
MyMessage msgK(KNOB_K_ID, V_STATUS);
MyMessage msgL(KNOB_L_ID, V_STATUS);
MyMessage msgM(KNOB_M_ID, V_STATUS);
MyMessage msgN(KNOB_N_ID, V_STATUS);

void before()
{
    for (int sensor=1, pin=RELAY_PIN; 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()
{

  pinMode(buttonPinA, INPUT_PULLUP); // Setup the button Activate internal pull-up
  pinMode(buttonPinB, INPUT_PULLUP); // Setup the button Activate internal pull-up
  pinMode(buttonPinC, INPUT_PULLUP); // Setup the button Activate internal pull-up
  pinMode(buttonPinD, INPUT_PULLUP);
  pinMode(buttonPinE, INPUT_PULLUP);
  pinMode(buttonPinF, INPUT_PULLUP);
  pinMode(buttonPinG, INPUT_PULLUP);
  pinMode(buttonPinH, INPUT_PULLUP);
  pinMode(buttonPinI, INPUT_PULLUP);
  pinMode(buttonPinJ, INPUT_PULLUP);
  pinMode(buttonPinK, INPUT_PULLUP);
  pinMode(buttonPinL, INPUT_PULLUP);
  pinMode(buttonPinM, INPUT_PULLUP);
  pinMode(buttonPinN, INPUT_PULLUP);

  digitalWrite(buttonPinA,HIGH);
  digitalWrite(buttonPinB,HIGH);
  digitalWrite(buttonPinC,HIGH);
  digitalWrite(buttonPinD,HIGH);
  digitalWrite(buttonPinE,HIGH);
  digitalWrite(buttonPinF,HIGH);
  digitalWrite(buttonPinG,HIGH);
  digitalWrite(buttonPinH,HIGH);
  digitalWrite(buttonPinI,HIGH);
  digitalWrite(buttonPinJ,HIGH);
  digitalWrite(buttonPinK,HIGH);
  digitalWrite(buttonPinL,HIGH);
  digitalWrite(buttonPinM,HIGH);
  digitalWrite(buttonPinN,HIGH);

  // After setting up the buttons, setup debouncer
  debouncerA.attach(buttonPinA);
  debouncerA.interval(5);
  debouncerB.attach(buttonPinB);
  debouncerB.interval(5);
  debouncerC.attach(buttonPinC);
  debouncerC.interval(5);
  debouncerD.attach(buttonPinD);
  debouncerD.interval(5);
  debouncerE.attach(buttonPinE);
  debouncerE.interval(5);
debouncerF.attach(buttonPinF);
  debouncerF.interval(5);
debouncerG.attach(buttonPinG);
  debouncerG.interval(5);
debouncerH.attach(buttonPinH);
  debouncerH.interval(5);
debouncerI.attach(buttonPinI);
  debouncerI.interval(5);
debouncerJ.attach(buttonPinJ);
  debouncerJ.interval(5);
debouncerK.attach(buttonPinK);
  debouncerK.interval(5);
debouncerL.attach(buttonPinL);
  debouncerL.interval(5);
debouncerM.attach(buttonPinM);
  debouncerM.interval(5);
debouncerN.attach(buttonPinN);
  debouncerN.interval(5);

    /*--------------------- Added these lines for toggle switch-------------------------*/
  oldValueA = digitalRead(buttonPinA);  // set oldValueA to the current status of the toggle switch
  oldValueB = digitalRead(buttonPinB);  // set oldValueB to the current status of the toggle switch
  oldValueC = digitalRead(buttonPinC);
  oldValueD = digitalRead(buttonPinD);  // set oldValueC to the current status of the toggle switch  
  oldValueE = digitalRead(buttonPinE);
  oldValueF = digitalRead(buttonPinF);
  oldValueG = digitalRead(buttonPinG);
  oldValueH = digitalRead(buttonPinH);
  oldValueI = digitalRead(buttonPinI);
  oldValueJ = digitalRead(buttonPinJ);
  oldValueK = digitalRead(buttonPinK);
  oldValueL = digitalRead(buttonPinL);
  oldValueM = digitalRead(buttonPinM);
  oldValueN = digitalRead(buttonPinN);          
 
}

void presentation()  {
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("2x bistable button", "1.1");

  // Register all sensorsto gw (they will be created as child devices)
  present(KNOB_A_ID, S_DOOR);
  present(KNOB_B_ID, S_DOOR);
  present(KNOB_C_ID, S_DOOR);
  present(KNOB_D_ID, S_DOOR);
  present(KNOB_D_ID, S_DOOR);
  present(KNOB_E_ID, S_DOOR);
  present(KNOB_F_ID, S_DOOR);
  present(KNOB_G_ID, S_DOOR);
  present(KNOB_H_ID, S_DOOR);
  present(KNOB_I_ID, S_DOOR);
  present(KNOB_J_ID, S_DOOR); 
  present(KNOB_K_ID, S_DOOR);
  present(KNOB_L_ID, S_DOOR);
  present(KNOB_M_ID, S_DOOR);
  present(KNOB_N_ID, S_DOOR); 

 for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
    }

}



void loop()
{
  if (trigger == 0)
    {
      debouncerA.update(); // Get the startup valueA
      int valueA = debouncerA.read();
      send(msgA.set(valueA==HIGH ? 1 : 0));

      debouncerB.update(); // Get the startup valueB
      int valueB = debouncerB.read();
      send(msgB.set(valueB==HIGH ? 1 : 0));

      debouncerC.update(); // Get the startup valueC
      int valueC = debouncerC.read();
      send(msgC.set(valueC==HIGH ? 1 : 0));

      debouncerD.update(); // Get the startup valueC
      int valueD = debouncerD.read();
      send(msgD.set(valueD==HIGH ? 1 : 0));

      debouncerE.update(); // Get the startup valueC
      int valueE = debouncerE.read();
      send(msgE.set(valueE==HIGH ? 1 : 0));

      debouncerF.update(); // Get the startup valueC
      int valueF = debouncerF.read();
      send(msgF.set(valueF==HIGH ? 1 : 0));

      debouncerG.update(); // Get the startup valueC
      int valueG = debouncerG.read();
      send(msgG.set(valueG==HIGH ? 1 : 0));

      debouncerH.update(); // Get the startup valueC
      int valueH = debouncerH.read();
      send(msgH.set(valueH==HIGH ? 1 : 0));
     
      debouncerI.update(); // Get the startup valueC
      int valueI = debouncerI.read();
      send(msgI.set(valueI==HIGH ? 1 : 0));

      debouncerJ.update(); // Get the startup valueC
      int valueJ = debouncerI.read();
      send(msgJ.set(valueJ==HIGH ? 1 : 0));

      debouncerK.update(); // Get the startup valueC
      int valueK = debouncerK.read();
      send(msgK.set(valueK==HIGH ? 1 : 0));

      debouncerL.update(); // Get the startup valueC
      int valueL = debouncerL.read();
      send(msgL.set(valueL==HIGH ? 1 : 0));

      debouncerM.update(); // Get the startup valueC
      int valueM = debouncerM.read();
      send(msgM.set(valueM==HIGH ? 1 : 0));

      debouncerN.update(); // Get the startup valueC
      int valueN = debouncerN.read();
      send(msgN.set(valueN==HIGH ? 1 : 0));


      trigger = 1;
    }



  debouncerA.update();
  // Get the update valueA
  int valueA = debouncerA.read();
 
  if (valueA != oldValueA) {
     // Send in the new valueA
     send(msgA.set(valueA==HIGH ? 1 : 0));
     oldValueA = valueA;
  }

  debouncerB.update();
  // Get the update valueB
  int valueB = debouncerB.read();
 
  if (valueB != oldValueB) {
     // Send in the new valueB
     send(msgB.set(valueB==HIGH ? 1 : 0));
     oldValueB = valueB;
  }

  debouncerC.update();
  // Get the update valueC
  int valueC = debouncerC.read();
 
  if (valueC != oldValueC) {
     // Send in the new valueC
     send(msgC.set(valueC==HIGH ? 1 : 0));
     oldValueC = valueC;
  }  

  debouncerD.update();
  // Get the update valueC
  int valueD = debouncerD.read();
 
  if (valueD != oldValueD) {
     // Send in the new valueC
     send(msgD.set(valueD==HIGH ? 1 : 0));
     oldValueD = valueD;
  }

  debouncerE.update();
  // Get the update valueC
  int valueE = debouncerE.read();
 
  if (valueE != oldValueE) {
     // Send in the new valueC
     send(msgE.set(valueE==HIGH ? 1 : 0));
     oldValueE = valueE;
  }

  debouncerF.update();
  // Get the update valueF
  int valueF = debouncerF.read();
 
  if (valueF != oldValueF) {
     // Send in the new valueC
     send(msgF.set(valueF==HIGH ? 1 : 0));
     oldValueF = valueF;
  }

   debouncerG.update();
  // Get the update valueC
  int valueG = debouncerG.read();
 
  if (valueG != oldValueG) {
     // Send in the new valueC
     send(msgG.set(valueG==HIGH ? 1 : 0));
     oldValueG = valueG;
  }

  debouncerH.update();
  // Get the update valueC
  int valueH = debouncerH.read();
 
  if (valueH != oldValueH) {
     // Send in the new valueC
     send(msgH.set(valueH==HIGH ? 1 : 0));
     oldValueH = valueH;
  }

  debouncerI.update();
  // Get the update valueC
  int valueI = debouncerI.read();
 
  if (valueI != oldValueI) {
     // Send in the new valueC
     send(msgI.set(valueI==HIGH ? 1 : 0));
     oldValueI = valueI;
  }

  debouncerJ.update();
  // Get the update valueC
  int valueJ = debouncerJ.read();
 
  if (valueJ != oldValueJ) {
     // Send in the new valueC
     send(msgJ.set(valueJ==HIGH ? 1 : 0));
     oldValueJ = valueJ;
  }

debouncerK.update();
  // Get the update valueC
  int valueK = debouncerK.read();
 
  if (valueK != oldValueK) {
     // Send in the new valueC
     send(msgK.set(valueK==HIGH ? 1 : 0));
     oldValueK = valueK;
  }

  debouncerL.update();
  // Get the update valueC
  int valueL = debouncerL.read();
 
  if (valueL != oldValueL) {
     // Send in the new valueC
     send(msgL.set(valueL==HIGH ? 1 : 0));
     oldValueL = valueL;
  }

  debouncerM.update();
  // Get the update valueC
  int valueM = debouncerM.read();
 
  if (valueM != oldValueM) {
     // Send in the new valueC
     send(msgM.set(valueM==HIGH ? 1 : 0));
     oldValueM = valueM;
  }

  debouncerN.update();
  // Get the update valueC
  int valueN = debouncerN.read();
 
  if (valueN != oldValueN) {
     // Send in the new valueC
     send(msgN.set(valueN==HIGH ? 1 : 0));
     oldValueN = valueN;
  }


}

void receive(const MyMessage &message)
{
    // We only expect one type of message from controller. But we better check anyway.
    if (message.getType()==V_STATUS) {
        // Change relay state
        digitalWrite(message.getSensor()-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
        // Store state in eeprom
        saveState(message.getSensor(), message.getBool());
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.getSensor());
        Serial.print(", New status: ");
        Serial.println(message.getBool());
    }
}    
Domoticz 4.9700/ rfxcom /sonde diy/raspberry pi3+HDD/cirusms/contact de porte diy
Répondre