Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Controllers
  3. Home Assistant
  4. How can initialize relays first time.

How can initialize relays first time.

Scheduled Pinned Locked Moved Home Assistant
2 Posts 2 Posters 131 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    diltech
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • skywatchS Offline
      skywatchS Offline
      skywatch
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      12

      Online

      11.7k

      Users

      11.2k

      Topics

      113.1k

      Posts


      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • MySensors
      • OpenHardware.io
      • Categories
      • Recent
      • Tags
      • Popular