How can initialize relays first time.



  • HI,

    I installed this firmware in HAAS and it works fine. It controls my 8 relays without problem and the status remains the same when I restart my nano, it takes the same status.
    I have problems only at the start to detect the relays in HASS. I have tried several things but I would like to know how to avoid it if the status has already been detected. In other words, the first initiation.

    #include <Arduino.h>
    /**
     *
     * REVISION HISTORY
     * Cette version est fonctionnel et est compatible avec Home Assistant (Sauf l'initialisation)
     * Utilise le composant 74HC595 pour réduire le nombre de fils.
     *
     * DESCRIPTION
     * Ce firmware utilise 8 sorties pour relais
     * V_STATUS sert seulement pour le statu de sortie
     * V_CUSTOM est pour activé les relais.
    */
    // Mettre le mode DEBUG ou l'enlever en commentaire
    #define MY_DEBUG
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_RFM69
    //#define MY_IS_RFM69HW
    //#define MY_RFM69_NEW_DRIVER				// Use new RFM69 Driver (include ATC)
    //#define MY_RFM69_FREQUENCY RFM69_868MHZ
    #define MY_REPEATER_FEATURE
    
    
    #include <SPI.h>
    #include <MySensors.h>
    
    #define SN "8_Relais"
    #define SV "1.2"
    
    
    #define NB_OUTPUTS 8
    #define OUTPUT_SER		7	// Serial data comes on this pin
    #define OUTPUT_RCLK		8	// This is the LATCH pin. Data is released when the pin goes HI
    #define OUTPUT_SRCLK	4	// Clock pin
    #define HEARTBEAT_DELAY 3600000
    #define pinEnable 6 // C'est dans la conception du board. La pin D6 doit être à 0 pour que le 74HC595 soit enable.
    
    
    
    byte outputStates;
    unsigned long lastHeartBeat=0;
    
    
    
    
    
    void changeOutputState(int i, boolean newState){
    	bitWrite(outputStates, i, newState);
    
    	// Lock latch
    	digitalWrite(OUTPUT_RCLK, LOW);
    	// Write bits
    	shiftOut(OUTPUT_SER, OUTPUT_SRCLK, MSBFIRST, outputStates);
    	// Unlock latch
    	digitalWrite(OUTPUT_RCLK, HIGH);
    }
    
    
    void setup() {
    
    	pinMode( OUTPUT_SER, OUTPUT);
    	pinMode( OUTPUT_RCLK, OUTPUT);
    	pinMode( OUTPUT_SRCLK, OUTPUT);
      pinMode( pinEnable, OUTPUT);
      digitalWrite(pinEnable, LOW);  // On met ici toujour la pin D6 à LOW
      
    
    }
    
    
    
    void presentation() {
    	// On envoie ici la version et le nom du Sketch
    	sendSketchInfo(SN, SV);
    
    	// On présente les relais selon le nombre établi au départ.
    	for (int i=0; i< NB_OUTPUTS; i++){
    		present(i, S_BINARY );
    	}
    }
    
    
    void loop(){
    
      
    
    	// Send a HeartBeat frequently so Domoticz see us as alive.
    	if (millis() > lastHeartBeat + HEARTBEAT_DELAY){
    		lastHeartBeat = millis();
    		sendHeartbeat();
        }
    }
    
    
    void receive(const MyMessage &message){
    
    	boolean currentStatus;
    
    	switch(message.type){
    		case V_CUSTOM:
    			// Revert output status :
    			currentStatus=bitRead(outputStates, message.sensor);
    			changeOutputState(message.sensor, !currentStatus);
    			break;
    		case V_STATUS:
    			changeOutputState(message.sensor, message.getBool());
    			break;
    	}
    
    
    	// Send new state :
    	currentStatus=bitRead(outputStates, message.sensor);
    	MyMessage msg(message.sensor, V_STATUS);
    	msg.set(currentStatus);
    	send(msg);
    
    }
    
    
    

    Thank if somebody known



  • I never used HAAS but have you looked at this page for how to set initial state? Then you can just send that to the controller.

    https://www.mysensors.org/build/relay


Log in to reply
 

Suggested Topics

  • 1
  • 2
  • 1
  • 17
  • 5

9
Online

11.4k
Users

11.1k
Topics

112.7k
Posts