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. Development
  3. Not all Relais visible in Domoticz

Not all Relais visible in Domoticz

Scheduled Pinned Locked Moved Development
9 Posts 3 Posters 1.1k 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.
  • DickD Offline
    DickD Offline
    Dick
    wrote on last edited by
    #1

    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());
    	}
    }
    
    1 Reply Last reply
    0
    • nagelcN Offline
      nagelcN Offline
      nagelc
      wrote on last edited by
      #2

      For me, sometimes Domoticz does not show a switch until it gets a value, even though the switch was presented. I add a small routine to Loop() with a flag so it only runs the first time after startup. Then i send the default value for each switch, Usually Off. It is not very elegant, but seems to work.
      If (startup) {
      Send initial value for each switch/relay
      startup=false;
      }

      DickD 1 Reply Last reply
      1
      • nagelcN nagelc

        For me, sometimes Domoticz does not show a switch until it gets a value, even though the switch was presented. I add a small routine to Loop() with a flag so it only runs the first time after startup. Then i send the default value for each switch, Usually Off. It is not very elegant, but seems to work.
        If (startup) {
        Send initial value for each switch/relay
        startup=false;
        }

        DickD Offline
        DickD Offline
        Dick
        wrote on last edited by
        #3

        @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?

        mfalkviddM 1 Reply Last reply
        0
        • DickD Dick

          @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?

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by mfalkvidd
          #4

          @dick add

          static bool startup = true;
          

          before the If (startup) line.

          You might also need to add delay(100) after each present and send, to avoid stressing the radio and power source too much.

          nagelcN DickD 2 Replies Last reply
          1
          • mfalkviddM mfalkvidd

            @dick add

            static bool startup = true;
            

            before the If (startup) line.

            You might also need to add delay(100) after each present and send, to avoid stressing the radio and power source too much.

            nagelcN Offline
            nagelcN Offline
            nagelc
            wrote on last edited by
            #5

            @mfalkvidd Exactly. Thanks for clarifying.

            1 Reply Last reply
            1
            • mfalkviddM mfalkvidd

              @dick add

              static bool startup = true;
              

              before the If (startup) line.

              You might also need to add delay(100) after each present and send, to avoid stressing the radio and power source too much.

              DickD Offline
              DickD Offline
              Dick
              wrote on last edited by
              #6

              @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;
              }
              }```
              mfalkviddM 1 Reply Last reply
              0
              • DickD Dick

                @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;
                }
                }```
                mfalkviddM Offline
                mfalkviddM Offline
                mfalkvidd
                Mod
                wrote on last edited by
                #7

                @dick if needs to be lowercase. Change "If" to "if".

                DickD 1 Reply Last reply
                0
                • mfalkviddM mfalkvidd

                  @dick if needs to be lowercase. Change "If" to "if".

                  DickD Offline
                  DickD Offline
                  Dick
                  wrote on last edited by
                  #8

                  @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.

                  1 Reply Last reply
                  1
                  • nagelcN Offline
                    nagelcN Offline
                    nagelc
                    wrote on last edited by nagelc
                    #9

                    Another thing to try. Try changing the button IDs to 6 and 7.

                    You define the button child IDs as 3 and 4.
                    The relays are presented with child ID's 1 through 5 by the loop in Presentation(). So the buttons have the same child IDs as two of the relays. Some sensors can have the same child ID, like temperature and humidity, but I don't know about S_DOOR and S_BINARY.

                    Also, delete this code i suggested. It needs some tweaking and I suspect the issue is really the overlap of the child IDs:
                    static bool startup = true;
                    If (startup) {
                    Send initial value for each switch/relay
                    startup=false;
                    }

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


                    8

                    Online

                    11.7k

                    Users

                    11.2k

                    Topics

                    113.0k

                    Posts


                    Copyright 2019 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