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. OpenHardware.io
  3. 💬 AC-DC double solid state relay module

💬 AC-DC double solid state relay module

Scheduled Pinned Locked Moved OpenHardware.io
hlk-pm01solid state relaylight switchlightacdc
226 Posts 67 Posters 103.5k Views 65 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.
  • johnym30J Offline
    johnym30J Offline
    johnym30
    wrote on last edited by
    #181

    Either pressing on or off in domoticz, i have always power on the second outpout.

    S 1 Reply Last reply
    0
    • johnym30J johnym30

      Either pressing on or off in domoticz, i have always power on the second outpout.

      S Offline
      S Offline
      stray
      wrote on last edited by
      #182

      @johnym30 Can you post your sketch?

      1 Reply Last reply
      0
      • johnym30J Offline
        johnym30J Offline
        johnym30
        wrote on last edited by johnym30
        #183

        This is my sketch

        // MySensor Debug
        #define MY_DEBUG
        
        // Enables repeater functionality (relays messages from other nodes)
        #define MY_REPEATER_FEATURE
        
        // Comment line below if you don't want to use the temperature sensor
        #define MY_RADIO_NRF24
        #define MY_TRANSPORT_WAIT_READY_MS
        #define MY_PARENT_NODE_ID 2
        #define MY_RADIO_NRF24
        #include <MySensors.h>
        #include <SPI.h>
        #include <Bounce2.h>
        
        #define RELAY_PIN_1   3  // Arduino Digital I/O pin number for relay 
        #define RELAY_PIN_2  5
        #define BUTTON_PIN_1  4  // Arduino Digital I/O pin number for button 
        #define BUTTON_PIN_2 7
        
        #define CHILD_ID_1 8 // Id of the sensor child for 1st relay
        #define CHILD_ID_2 9 // Id of the sensor child for 2nd relay
        
        // Relay status
        #define RELAY_ON 1
        #define RELAY_OFF 0
        
        // Source of state change (used when printing debug information)
        #define CHANGE_STATE_SOURCE_RADIO 0
        #define CHANGE_STATE_SOURCE_SWITCH 1
        
        
        
        Bounce debouncer1 = Bounce();
        int oldValue;
        bool state1;
        Bounce debouncer2 = Bounce();
        int oldValue2;
        bool state2;
        
        MyMessage msg(CHILD_ID_1, V_LIGHT);
        MyMessage msg2(CHILD_ID_2, V_LIGHT);
        
        
        
        void presentation() {
          // Send the sketch version information to the gateway and Controller
          sendSketchInfo("Double Relay & Button", "0.2");
          // Register all sensors to gw (they will be created as child devices)
          present(CHILD_ID_1, S_LIGHT);
          present(CHILD_ID_2, S_LIGHT);
        
        }
        
        void setup()
        {
          // Setup the button
          pinMode(BUTTON_PIN_1, INPUT);
          // Activate internal pull-up
          digitalWrite(BUTTON_PIN_1, HIGH);
        
          // Setup the button
          pinMode(BUTTON_PIN_2, INPUT);
          // Activate internal pull-up
          digitalWrite(BUTTON_PIN_2, HIGH);
        
          // After setting up the button, setup debouncer
          debouncer1.attach(BUTTON_PIN_1);
          debouncer1.interval(5);
        
          debouncer2.attach(BUTTON_PIN_2);
          debouncer2.interval(5);
        
          // Set the initial values of oldValue/oldValue2 variables from status of physical switches
          //  if this is not done the loop() will detect status change and switch the relays on or off
          debouncer1.update();
          debouncer2.update();
          oldValue = debouncer1.read();
          oldValue2 = debouncer2.read();
        
        
          // Make sure relays are off when starting up
          setRelayState(RELAY_PIN_1, RELAY_OFF);
          // Then set relay pins in output mode
          pinMode(RELAY_PIN_1, OUTPUT);
        
          digitalWrite(RELAY_PIN_2, RELAY_OFF);
          // Then set relay pins in output mode
          pinMode(RELAY_PIN_2, OUTPUT);
        
          // Set relay to last known state (using eeprom storage)
          state1 = loadState(CHILD_ID_1);
          setRelayState(RELAY_PIN_1, state1);
        
          state2 = loadState(CHILD_ID_2);
          setRelayState(RELAY_PIN_2, state2);
        }
        
        
        /*
           Example on how to asynchronously check for new messages from gw
        */
        void loop()
        {
          debouncer1.update();
          debouncer2.update();
          // Get the update value
          int value1 = debouncer1.read();
          int value2 = debouncer2.read();
        
          if (value1 != oldValue) {
            send(msg.set(state1 ? false : true), true); // Send new state and request ack back
            // Write some debug info
            printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID_1, value1);
          }
          oldValue = value1;
        
          if (value2 != oldValue2) {
            send(msg2.set(state2 ? false : true), true); // Send new state and request ack back
            // Write some debug info
            printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID_2, value2);
          }
          oldValue2 = value2;
        
        }
        
        void receive(const MyMessage &message) {
          // We only expect one type of message from controller. But we better check anyway.
          if (message.isAck()) {
        #ifdef MY_DEBUG
            Serial.println(F("This is an ack from gateway"));
        #endif
          }
          else if (message.type == V_LIGHT && message.sensor == CHILD_ID_1) {
            // Change relay state
            state1 = message.getBool();
            setRelayState(RELAY_PIN_1, state1);
            // Store state in eeprom
            saveState(CHILD_ID_1, state1);
            // Write some debug info
            printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID_1, state1);
          }
          else if (message.type == V_LIGHT && message.sensor == CHILD_ID_2) {
            state2 = message.getBool();
            setRelayState(RELAY_PIN_2, state2);
            // Store state in eeprom
            saveState(CHILD_ID_2, state2);
            // Write some debug info
            printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID_2, state2);
          }
        }
        
        // Set status of a relay pin
        void setRelayState(byte relayPin, bool value) {
          digitalWrite(relayPin, value ? RELAY_ON : RELAY_OFF);
        }
        
        // Print debug info, centralized in one place to minimize memory usage and have only one #ifdef MY_DEBUG for all state change messages
        void printStateChangedDebug(int source, int sensorID, bool value) {
        #ifdef MY_DEBUG
          Serial.print(F("Sensor value changed, source="));
          Serial.print(source == CHANGE_STATE_SOURCE_RADIO ? F("Radio") : F("Physical switch"));
          Serial.print(F(", Sensor="));
          Serial.print(sensorID);
          Serial.print(F(", New status: "));
          Serial.println(value);
        #endif
        }
        
        S 1 Reply Last reply
        0
        • johnym30J johnym30

          This is my sketch

          // MySensor Debug
          #define MY_DEBUG
          
          // Enables repeater functionality (relays messages from other nodes)
          #define MY_REPEATER_FEATURE
          
          // Comment line below if you don't want to use the temperature sensor
          #define MY_RADIO_NRF24
          #define MY_TRANSPORT_WAIT_READY_MS
          #define MY_PARENT_NODE_ID 2
          #define MY_RADIO_NRF24
          #include <MySensors.h>
          #include <SPI.h>
          #include <Bounce2.h>
          
          #define RELAY_PIN_1   3  // Arduino Digital I/O pin number for relay 
          #define RELAY_PIN_2  5
          #define BUTTON_PIN_1  4  // Arduino Digital I/O pin number for button 
          #define BUTTON_PIN_2 7
          
          #define CHILD_ID_1 8 // Id of the sensor child for 1st relay
          #define CHILD_ID_2 9 // Id of the sensor child for 2nd relay
          
          // Relay status
          #define RELAY_ON 1
          #define RELAY_OFF 0
          
          // Source of state change (used when printing debug information)
          #define CHANGE_STATE_SOURCE_RADIO 0
          #define CHANGE_STATE_SOURCE_SWITCH 1
          
          
          
          Bounce debouncer1 = Bounce();
          int oldValue;
          bool state1;
          Bounce debouncer2 = Bounce();
          int oldValue2;
          bool state2;
          
          MyMessage msg(CHILD_ID_1, V_LIGHT);
          MyMessage msg2(CHILD_ID_2, V_LIGHT);
          
          
          
          void presentation() {
            // Send the sketch version information to the gateway and Controller
            sendSketchInfo("Double Relay & Button", "0.2");
            // Register all sensors to gw (they will be created as child devices)
            present(CHILD_ID_1, S_LIGHT);
            present(CHILD_ID_2, S_LIGHT);
          
          }
          
          void setup()
          {
            // Setup the button
            pinMode(BUTTON_PIN_1, INPUT);
            // Activate internal pull-up
            digitalWrite(BUTTON_PIN_1, HIGH);
          
            // Setup the button
            pinMode(BUTTON_PIN_2, INPUT);
            // Activate internal pull-up
            digitalWrite(BUTTON_PIN_2, HIGH);
          
            // After setting up the button, setup debouncer
            debouncer1.attach(BUTTON_PIN_1);
            debouncer1.interval(5);
          
            debouncer2.attach(BUTTON_PIN_2);
            debouncer2.interval(5);
          
            // Set the initial values of oldValue/oldValue2 variables from status of physical switches
            //  if this is not done the loop() will detect status change and switch the relays on or off
            debouncer1.update();
            debouncer2.update();
            oldValue = debouncer1.read();
            oldValue2 = debouncer2.read();
          
          
            // Make sure relays are off when starting up
            setRelayState(RELAY_PIN_1, RELAY_OFF);
            // Then set relay pins in output mode
            pinMode(RELAY_PIN_1, OUTPUT);
          
            digitalWrite(RELAY_PIN_2, RELAY_OFF);
            // Then set relay pins in output mode
            pinMode(RELAY_PIN_2, OUTPUT);
          
            // Set relay to last known state (using eeprom storage)
            state1 = loadState(CHILD_ID_1);
            setRelayState(RELAY_PIN_1, state1);
          
            state2 = loadState(CHILD_ID_2);
            setRelayState(RELAY_PIN_2, state2);
          }
          
          
          /*
             Example on how to asynchronously check for new messages from gw
          */
          void loop()
          {
            debouncer1.update();
            debouncer2.update();
            // Get the update value
            int value1 = debouncer1.read();
            int value2 = debouncer2.read();
          
            if (value1 != oldValue) {
              send(msg.set(state1 ? false : true), true); // Send new state and request ack back
              // Write some debug info
              printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID_1, value1);
            }
            oldValue = value1;
          
            if (value2 != oldValue2) {
              send(msg2.set(state2 ? false : true), true); // Send new state and request ack back
              // Write some debug info
              printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID_2, value2);
            }
            oldValue2 = value2;
          
          }
          
          void receive(const MyMessage &message) {
            // We only expect one type of message from controller. But we better check anyway.
            if (message.isAck()) {
          #ifdef MY_DEBUG
              Serial.println(F("This is an ack from gateway"));
          #endif
            }
            else if (message.type == V_LIGHT && message.sensor == CHILD_ID_1) {
              // Change relay state
              state1 = message.getBool();
              setRelayState(RELAY_PIN_1, state1);
              // Store state in eeprom
              saveState(CHILD_ID_1, state1);
              // Write some debug info
              printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID_1, state1);
            }
            else if (message.type == V_LIGHT && message.sensor == CHILD_ID_2) {
              state2 = message.getBool();
              setRelayState(RELAY_PIN_2, state2);
              // Store state in eeprom
              saveState(CHILD_ID_2, state2);
              // Write some debug info
              printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID_2, state2);
            }
          }
          
          // Set status of a relay pin
          void setRelayState(byte relayPin, bool value) {
            digitalWrite(relayPin, value ? RELAY_ON : RELAY_OFF);
          }
          
          // Print debug info, centralized in one place to minimize memory usage and have only one #ifdef MY_DEBUG for all state change messages
          void printStateChangedDebug(int source, int sensorID, bool value) {
          #ifdef MY_DEBUG
            Serial.print(F("Sensor value changed, source="));
            Serial.print(source == CHANGE_STATE_SOURCE_RADIO ? F("Radio") : F("Physical switch"));
            Serial.print(F(", Sensor="));
            Serial.print(sensorID);
            Serial.print(F(", New status: "));
            Serial.println(value);
          #endif
          }
          
          S Offline
          S Offline
          stray
          wrote on last edited by
          #184

          @johnym30 Can't see anything wrong with the sketch that causes the 2 outputs toggle at the same time. However, I have 2 remarks:

          1. Don't you need to set the pins to output before you set them low?
          2. You are not updating your gateway when you toggle the output with the switch.
          johnym30J 1 Reply Last reply
          0
          • S stray

            @johnym30 Can't see anything wrong with the sketch that causes the 2 outputs toggle at the same time. However, I have 2 remarks:

            1. Don't you need to set the pins to output before you set them low?
            2. You are not updating your gateway when you toggle the output with the switch.
            johnym30J Offline
            johnym30J Offline
            johnym30
            wrote on last edited by
            #185

            @stray the think is that the first relay is working normal and i see the updates in domoticz when i turn it on or off.It is just the second relay that gives me power either it is on or off in domoticz.That is why i am thinking maybe the second relay is broken

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Eawo
              wrote on last edited by
              #186

              hmm im having a hard time fitting these modules behind my lamp buttoms couse its swedish standar 70mm holes and the nrfmodule sticks out to much anyone know a good mod?

              dpressleD 1 Reply Last reply
              0
              • E Eawo

                hmm im having a hard time fitting these modules behind my lamp buttoms couse its swedish standar 70mm holes and the nrfmodule sticks out to much anyone know a good mod?

                dpressleD Offline
                dpressleD Offline
                dpressle
                wrote on last edited by
                #187

                @Eawo Here you go

                1 Reply Last reply
                0
                • johnym30J Offline
                  johnym30J Offline
                  johnym30
                  wrote on last edited by
                  #188

                  Hi everyone.Its me again!!!!
                  Everything seems to be working just fine when i am using domoticz interface, but when i am using the hardware switches the icons in domoticz update from off to on but my lights wont turn on. If i turn my hardware switch to off, the state in domoticz stays to on.What am i doing wrong????
                  My sketch below .

                  /**
                   * 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
                   *
                   * Script for double SSR relay board by Aproxx
                   * https://www.openhardware.io/view/77/AC-DC-double-solid-state-relay-module
                   * https://forum.mysensors.org/topic/3671/ac-dc-double-solid-state-relay-module
                   * Control 2 circuits either from controller or from physical buttons connected on pins 4 & 7
                   * Optional DS18b20 is connected on pin 8
                   * 
                   *  HISTORY :
                   * xx/xx/2016 original version by Aproxx
                   * 08/02/2016 upgraded to MySensors 2.0 by mr_const
                   * 08/30/2016 changes by Nca78 :
                   *        - fixed initialization of physical buttons/debouncer status
                   *        - centralized pin status change for relays in setRelayState method
                   *        - centralized debug information for state changes in one method + added debug info when changed by physical switches
                   *        - added #ifdef MY_DEBUG before each Serial.print (saves prog memory when not in debug mode) and F() macros for debug strings (saves RAM when in debug mode)
                   *        - added #define USE_TEMP_SENSOR to make temperature sensor optional (not used if line is commented)
                   *        - put back #define for repeater feature
                   *        - add #define TEMPERATURE_ROUNDING for custom temperature rounding
                  **/
                  
                  // MySensor Debug
                  //#define MY_DEBUG
                  
                  // Enables repeater functionality (relays messages from other nodes)
                  //#define MY_REPEATER_FEATURE
                  
                  // Comment line below if you don't want to use the temperature sensor
                  #define USE_TEMP_SENSOR
                  
                  #define MY_RADIO_NRF24
                  #include <MySensors.h>
                  #include <SPI.h>
                  #include <Bounce2.h>
                  
                  #define RELAY_PIN    3  // Arduino Digital I/O pin number for relay 
                  #define RELAY_PIN_2  5
                  #define BUTTON_PIN   4  // Arduino Digital I/O pin number for button 
                  #define BUTTON_PIN_2 7
                  
                  #define CHILD_ID 8 // Id of the sensor child for 1st relay
                  #define CHILD_ID_2 9 // Id of the sensor child for 2nd relay
                  
                  // Relay status
                  #define RELAY_ON 1
                  #define RELAY_OFF 0
                  
                  // Source of state change (used when printing debug information)
                  #define CHANGE_STATE_SOURCE_RADIO 0
                  #define CHANGE_STATE_SOURCE_SWITCH 1
                  
                  
                  // Temperature sensor definitions
                  #ifdef USE_TEMP_SENSOR
                  #include <OneWire.h>
                  #include <DallasTemperature.h>
                  #define ONE_WIRE_BUS 8
                  #define CHILD_DSB_ID 13 // Id of the sensor child for temperature sensor
                  #define TEMPERATURE_ROUNDING 10.f   // Change value to change rounding of temperature value: 10.f for 0.1°C change, 5.f for 0.2°C change, 2.f for 0.5°C change
                  #endif
                  
                  
                  
                  Bounce debouncer = Bounce();
                  int oldValue;
                  bool state;
                  Bounce debouncer2 = Bounce();
                  int oldValue2;
                  bool state2;
                  
                  MyMessage msg(CHILD_ID, V_LIGHT);
                  MyMessage msg2(CHILD_ID_2, V_LIGHT);
                  
                  #ifdef USE_TEMP_SENSOR
                  MyMessage msgTemp(CHILD_DSB_ID, V_TEMP);
                  OneWire oneWire(ONE_WIRE_BUS);
                  DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
                  #endif
                  
                  void presentation() {
                    // Send the sketch version information to the gateway and Controller
                    sendSketchInfo("Double Relay & Button", "0.2");
                    // Register all sensors to gw (they will be created as child devices)
                    present(CHILD_ID, S_LIGHT);
                    present(CHILD_ID_2, S_LIGHT);
                  #ifdef USE_TEMP_SENSOR
                    present(CHILD_DSB_ID, S_TEMP);
                  #endif
                  }
                  
                  void setup()
                  {
                  #ifdef USE_TEMP_SENSOR
                    sensors.begin();
                    sensors.setWaitForConversion(false);
                  #endif
                  
                    // Setup the button
                    pinMode(BUTTON_PIN, INPUT);
                    // Activate internal pull-up
                    digitalWrite(BUTTON_PIN, HIGH);
                  
                    // Setup the button
                    pinMode(BUTTON_PIN_2, INPUT);
                    // Activate internal pull-up
                    digitalWrite(BUTTON_PIN_2, HIGH);
                  
                    // After setting up the button, setup debouncer
                    debouncer.attach(BUTTON_PIN);
                    debouncer.interval(5);
                  
                    debouncer2.attach(BUTTON_PIN_2);
                    debouncer2.interval(5);
                  
                    // Set the initial values of oldValue/oldValue2 variables from status of physical switches
                    //  if this is not done the loop() will detect status change and switch the relays on or off
                    debouncer.update();
                    debouncer2.update();
                    oldValue = debouncer.read();
                    oldValue2 = debouncer2.read();
                  
                  
                    // Make sure relays are off when starting up
                    setRelayState(RELAY_PIN, RELAY_OFF);
                    // Then set relay pins in output mode
                    pinMode(RELAY_PIN, OUTPUT);
                  
                    digitalWrite(RELAY_PIN_2, RELAY_OFF);
                    // Then set relay pins in output mode
                    pinMode(RELAY_PIN_2, OUTPUT);
                  
                    // Set relay to last known state (using eeprom storage)
                    state = loadState(CHILD_ID);
                    setRelayState(RELAY_PIN, state);
                  
                    state2 = loadState(CHILD_ID_2);
                    setRelayState(RELAY_PIN_2, state2);
                  }
                  
                  
                  /*
                     Example on how to asynchronously check for new messages from gw
                  */
                  void loop()
                  {
                  #ifdef USE_TEMP_SENSOR
                    static float prevTemp = 0;
                  #endif
                  
                    debouncer.update();
                    debouncer2.update();
                    // Get the update value
                    int value = debouncer.read();
                    int value2 = debouncer2.read();
                  
                    if (value != oldValue) {
                      send(msg.set(state ? false : true), true); // Send new state and request ack back
                      // Write some debug info
                      printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID, value);
                    }
                    oldValue = value;
                  
                    if (value2 != oldValue2) {
                      send(msg2.set(state2 ? false : true), true); // Send new state and request ack back
                      // Write some debug info
                      printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID_2, value2);
                    }
                    oldValue2 = value2;
                  
                    // Fetch temperatures from Dallas sensors
                  #ifdef USE_TEMP_SENSOR
                    sensors.requestTemperatures();
                    // Fetch and round temperature to one decimal
                    float temperature = static_cast<float>(static_cast<int>(sensors.getTempCByIndex(0) * TEMPERATURE_ROUNDING)) / TEMPERATURE_ROUNDING;
                  
                    if (temperature != -127.00f && temperature != 85.00f && prevTemp != temperature) {
                      // Send in the new temperature
                      send(msgTemp.set(temperature, 1));
                  #ifdef MY_DEBUG
                      Serial.print("Sent temperature: ");
                      Serial.println(temperature);
                  #endif
                      prevTemp = temperature;
                    }
                  #endif
                  }
                  
                  void receive(const MyMessage &message) {
                    // We only expect one type of message from controller. But we better check anyway.
                    if (message.isAck()) {
                  #ifdef MY_DEBUG
                      Serial.println(F("This is an ack from gateway"));
                  #endif
                    }
                    else if (message.type == V_LIGHT && message.sensor == CHILD_ID) {
                      // Change relay state
                      state = message.getBool();
                      setRelayState(RELAY_PIN, state);
                      // Store state in eeprom
                      saveState(CHILD_ID, state);
                      // Write some debug info
                      printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID, state);
                    }
                    else if (message.type == V_LIGHT && message.sensor == CHILD_ID_2) {
                      state2 = message.getBool();
                      setRelayState(RELAY_PIN_2, state2);
                      // Store state in eeprom
                      saveState(CHILD_ID_2, state2);
                      // Write some debug info
                      printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID_2, state2);
                    }
                  }
                  
                  // Set status of a relay pin
                  void setRelayState(byte relayPin, bool value) {
                    digitalWrite(relayPin, value ? RELAY_ON : RELAY_OFF);
                  }
                  
                  // Print debug info, centralized in one place to minimize memory usage and have only one #ifdef MY_DEBUG for all state change messages
                  void printStateChangedDebug(int source, int sensorID, bool value) {
                  #ifdef MY_DEBUG
                    Serial.print(F("Sensor value changed, source="));
                    Serial.print(source == CHANGE_STATE_SOURCE_RADIO ? F("Radio") : F("Physical switch"));
                    Serial.print(F(", Sensor="));
                    Serial.print(sensorID);
                    Serial.print(F(", New status: "));
                    Serial.println(value);
                  #endif
                  }
                  
                  1 Reply Last reply
                  0
                  • johnym30J Offline
                    johnym30J Offline
                    johnym30
                    wrote on last edited by johnym30
                    #189

                    Anyone has the hardware switches working??? I can't make them work!!!! Help please!!!!!

                    1 Reply Last reply
                    0
                    • hekH Offline
                      hekH Offline
                      hek
                      Admin
                      wrote on last edited by
                      #190

                      I doubt anyone can help you without debug logs from your node and gateway.

                      You can also look at the logs yourself using this tool to see where messages get stuck or lost.

                      johnym30J 1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        Eawo
                        wrote on last edited by
                        #191

                        How do I wire if I have ''2 buttons on the same lamp'' and also want to connect '' 1buttom to 1lamp'' to the same module how do I wire 2button 1 lamp?

                        1 Reply Last reply
                        0
                        • hekH hek

                          I doubt anyone can help you without debug logs from your node and gateway.

                          You can also look at the logs yourself using this tool to see where messages get stuck or lost.

                          johnym30J Offline
                          johnym30J Offline
                          johnym30
                          wrote on last edited by
                          #192

                          @hek the think is that the switch works using Domoticz, but when i use the pins for the hardware switch , i get the icons updated in domotics to on or off but my lights stay off

                          Boots33B 1 Reply Last reply
                          0
                          • johnym30J johnym30

                            @hek the think is that the switch works using Domoticz, but when i use the pins for the hardware switch , i get the icons updated in domotics to on or off but my lights stay off

                            Boots33B Offline
                            Boots33B Offline
                            Boots33
                            Hero Member
                            wrote on last edited by Boots33
                            #193

                            @johnym30 It might be the way the code is written in your receive function.

                            When you toggle the hardware switch a message is sent to your controller with the new state, so Domoticz will get this and change the icons accordingly. The message you sent also asks for an ack back, it is this returning ack that is used to switch the relay.

                            The first If statement in your present code captures the ack and does a serial print but then does nothing else, so your ack is ignored by the rest of the code. So your relay will not be switched.

                            I see no reason why you need to test for an ack so try the following code and see if it helps

                            void receive(const MyMessage &message) { 
                            if (message.type == V_STATUS) {
                             switch (message.sensor) {
                              case CHILD_ID:    
                                state = message.getBool();          // Change relay state
                                setRelayState(RELAY_PIN, state);    
                                saveState(CHILD_ID, state);        // Store state in eeprom
                                // Write some debug info
                                printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID, state);
                                break; 
                              case CHILD_ID_2:
                                state2 = message.getBool();
                                setRelayState(RELAY_PIN_2, state2);
                                saveState(CHILD_ID_2, state2);     // Store state in eeprom
                                // Write some debug info
                                printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID_2, state2);
                                break;
                              }
                             }
                            }
                            

                            You might also like to move the the lines that set oldvalue to new value. They probably should be inside the relevant if statement. In the original relay with button actuator code they are outside but that is using push buttons not toggle switches.

                             if (value != oldValue) {
                                send(msg.set(state ? false : true), true); // Send new state and request ack back
                                // Write some debug info
                                printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID, value);
                                oldValue = value;
                              }
                              
                            
                              if (value2 != oldValue2) {
                                send(msg2.set(state2 ? false : true), true); // Send new state and request ack back
                                // Write some debug info
                                printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID_2, value2);
                                oldValue2 = value2;
                              }
                            

                            The other thing you should note is that as the code relies on an ack from your gateway to switch the relay your hardware switches will not work if the gateway is not available. You will need to further modify the code to ensure the switches work at all times.

                            johnym30J 1 Reply Last reply
                            0
                            • Boots33B Boots33

                              @johnym30 It might be the way the code is written in your receive function.

                              When you toggle the hardware switch a message is sent to your controller with the new state, so Domoticz will get this and change the icons accordingly. The message you sent also asks for an ack back, it is this returning ack that is used to switch the relay.

                              The first If statement in your present code captures the ack and does a serial print but then does nothing else, so your ack is ignored by the rest of the code. So your relay will not be switched.

                              I see no reason why you need to test for an ack so try the following code and see if it helps

                              void receive(const MyMessage &message) { 
                              if (message.type == V_STATUS) {
                               switch (message.sensor) {
                                case CHILD_ID:    
                                  state = message.getBool();          // Change relay state
                                  setRelayState(RELAY_PIN, state);    
                                  saveState(CHILD_ID, state);        // Store state in eeprom
                                  // Write some debug info
                                  printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID, state);
                                  break; 
                                case CHILD_ID_2:
                                  state2 = message.getBool();
                                  setRelayState(RELAY_PIN_2, state2);
                                  saveState(CHILD_ID_2, state2);     // Store state in eeprom
                                  // Write some debug info
                                  printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID_2, state2);
                                  break;
                                }
                               }
                              }
                              

                              You might also like to move the the lines that set oldvalue to new value. They probably should be inside the relevant if statement. In the original relay with button actuator code they are outside but that is using push buttons not toggle switches.

                               if (value != oldValue) {
                                  send(msg.set(state ? false : true), true); // Send new state and request ack back
                                  // Write some debug info
                                  printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID, value);
                                  oldValue = value;
                                }
                                
                              
                                if (value2 != oldValue2) {
                                  send(msg2.set(state2 ? false : true), true); // Send new state and request ack back
                                  // Write some debug info
                                  printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID_2, value2);
                                  oldValue2 = value2;
                                }
                              

                              The other thing you should note is that as the code relies on an ack from your gateway to switch the relay your hardware switches will not work if the gateway is not available. You will need to further modify the code to ensure the switches work at all times.

                              johnym30J Offline
                              johnym30J Offline
                              johnym30
                              wrote on last edited by
                              #194

                              @Boots33 Thanks they are working now!!!!!!!
                              Unfortunately i dont know about coding, i am more of a hardware guy, so i will just have to live with that.Hoping that in the future someone will write something and share it with us.
                              Thank you once more.

                              Boots33B 1 Reply Last reply
                              0
                              • johnym30J johnym30

                                @Boots33 Thanks they are working now!!!!!!!
                                Unfortunately i dont know about coding, i am more of a hardware guy, so i will just have to live with that.Hoping that in the future someone will write something and share it with us.
                                Thank you once more.

                                Boots33B Offline
                                Boots33B Offline
                                Boots33
                                Hero Member
                                wrote on last edited by Boots33
                                #195

                                @johnym30 There are only a few changes to be made to make the hardware switches more reliable. @hek showed in this post some code that could be used.

                                First you will need to add a line near the top of your sketch to allow the node to execute the loop part of the sketch even if no transport uplink is established. This code needs to be placed before #include <MySensors.h>

                                #define MY_TRANSPORT_WAIT_READY_MS 3000     //set how long to wait for transport ready.
                                

                                The number at the end of the line is used to set how long to wait in milliseconds. I have found that my nodes will usually connect within 3 seconds.

                                Then you need to modify the code in the loop part of your sketch.

                                if (value != oldValue) {
                                    state =  !state;                                                  // Toggle the state
                                    send(msg.set(state), false);                          // send new state to controller, no ack requested
                                    setRelayState(RELAY_PIN, state);                // switch the relay to the new state
                                    saveState(CHILD_ID, state);        // Store state in eeprom
                                    // Write some debug info
                                    printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID, value);
                                    oldValue = value;
                                  }
                                  
                                
                                  if (value2 != oldValue2) {
                                    state2 =  !state2;                                         // Toggle the state
                                    send(msg2.set(state2), false);                 // send new state to controller, no ack requested
                                    setRelayState(RELAY_PIN_2, state2);     // switch the relay to the new state
                                    saveState(CHILD_ID_2, state2);     // Store state in eeprom
                                    // Write some debug info
                                    printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID_2, value2);
                                    oldValue2 = value2;
                                  }
                                
                                1 Reply Last reply
                                0
                                • folkestorpF Offline
                                  folkestorpF Offline
                                  folkestorp
                                  wrote on last edited by
                                  #196

                                  @Boots33 Will you please upload your complete code. It is difficult to see the finale solution then I read all the posts.

                                  Boots33B 1 Reply Last reply
                                  0
                                  • folkestorpF folkestorp

                                    @Boots33 Will you please upload your complete code. It is difficult to see the finale solution then I read all the posts.

                                    Boots33B Offline
                                    Boots33B Offline
                                    Boots33
                                    Hero Member
                                    wrote on last edited by Boots33
                                    #197

                                    @folkestorp I have no node to try it on but the code will look like this. perhaps you can test it and let us know if it works. I have just placed it in the original code of a few posts up

                                    /**
                                     * 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
                                     *
                                     * Script for double SSR relay board by Aproxx
                                     * https://www.openhardware.io/view/77/AC-DC-double-solid-state-relay-module
                                     * https://forum.mysensors.org/topic/3671/ac-dc-double-solid-state-relay-module
                                     * Control 2 circuits either from controller or from physical buttons connected on pins 4 & 7
                                     * Optional DS18b20 is connected on pin 8
                                     * 
                                     *  HISTORY :
                                     * xx/xx/2016 original version by Aproxx
                                     * 08/02/2016 upgraded to MySensors 2.0 by mr_const
                                     * 08/30/2016 changes by Nca78 :
                                     *        - fixed initialization of physical buttons/debouncer status
                                     *        - centralized pin status change for relays in setRelayState method
                                     *        - centralized debug information for state changes in one method + added debug info when changed by physical switches
                                     *        - added #ifdef MY_DEBUG before each Serial.print (saves prog memory when not in debug mode) and F() macros for debug strings (saves RAM when in debug mode)
                                     *        - added #define USE_TEMP_SENSOR to make temperature sensor optional (not used if line is commented)
                                     *        - put back #define for repeater feature
                                     *        - add #define TEMPERATURE_ROUNDING for custom temperature rounding
                                    **/
                                    
                                    // MySensor Debug
                                    //#define MY_DEBUG
                                    
                                    // Enables repeater functionality (relays messages from other nodes)
                                    //#define MY_REPEATER_FEATURE
                                    
                                    // Comment line below if you don't want to use the temperature sensor
                                    #define USE_TEMP_SENSOR
                                    #define MY_TRANSPORT_WAIT_READY_MS 3000     //set how long to wait for transport ready.
                                    #define MY_RADIO_NRF24
                                    #include <MySensors.h>
                                    #include <SPI.h>
                                    #include <Bounce2.h>
                                    
                                    #define RELAY_PIN    3  // Arduino Digital I/O pin number for relay 
                                    #define RELAY_PIN_2  5
                                    #define BUTTON_PIN   4  // Arduino Digital I/O pin number for button 
                                    #define BUTTON_PIN_2 7
                                    
                                    #define CHILD_ID 8 // Id of the sensor child for 1st relay
                                    #define CHILD_ID_2 9 // Id of the sensor child for 2nd relay
                                    
                                    // Relay status
                                    #define RELAY_ON 1
                                    #define RELAY_OFF 0
                                    
                                    // Source of state change (used when printing debug information)
                                    #define CHANGE_STATE_SOURCE_RADIO 0
                                    #define CHANGE_STATE_SOURCE_SWITCH 1
                                    
                                    
                                    // Temperature sensor definitions
                                    #ifdef USE_TEMP_SENSOR
                                    #include <OneWire.h>
                                    #include <DallasTemperature.h>
                                    #define ONE_WIRE_BUS 8
                                    #define CHILD_DSB_ID 13 // Id of the sensor child for temperature sensor
                                    #define TEMPERATURE_ROUNDING 10.f   // Change value to change rounding of temperature value: 10.f for 0.1°C change, 5.f for 0.2°C change, 2.f for 0.5°C change
                                    #endif
                                    
                                    
                                    
                                    Bounce debouncer = Bounce();
                                    int oldValue;
                                    bool state;
                                    Bounce debouncer2 = Bounce();
                                    int oldValue2;
                                    bool state2;
                                    
                                    MyMessage msg(CHILD_ID, V_LIGHT);
                                    MyMessage msg2(CHILD_ID_2, V_LIGHT);
                                    
                                    #ifdef USE_TEMP_SENSOR
                                    MyMessage msgTemp(CHILD_DSB_ID, V_TEMP);
                                    OneWire oneWire(ONE_WIRE_BUS);
                                    DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
                                    #endif
                                    
                                    void presentation() {
                                      // Send the sketch version information to the gateway and Controller
                                      sendSketchInfo("Double Relay & Button", "0.2");
                                      // Register all sensors to gw (they will be created as child devices)
                                      present(CHILD_ID, S_LIGHT);
                                      present(CHILD_ID_2, S_LIGHT);
                                    #ifdef USE_TEMP_SENSOR
                                      present(CHILD_DSB_ID, S_TEMP);
                                    #endif
                                    }
                                    
                                    void setup()
                                    {
                                    #ifdef USE_TEMP_SENSOR
                                      sensors.begin();
                                      sensors.setWaitForConversion(false);
                                    #endif
                                    
                                      // Setup the button
                                      pinMode(BUTTON_PIN, INPUT);
                                      // Activate internal pull-up
                                      digitalWrite(BUTTON_PIN, HIGH);
                                    
                                      // Setup the button
                                      pinMode(BUTTON_PIN_2, INPUT);
                                      // Activate internal pull-up
                                      digitalWrite(BUTTON_PIN_2, HIGH);
                                    
                                      // After setting up the button, setup debouncer
                                      debouncer.attach(BUTTON_PIN);
                                      debouncer.interval(5);
                                    
                                      debouncer2.attach(BUTTON_PIN_2);
                                      debouncer2.interval(5);
                                    
                                      // Set the initial values of oldValue/oldValue2 variables from status of physical switches
                                      //  if this is not done the loop() will detect status change and switch the relays on or off
                                      debouncer.update();
                                      debouncer2.update();
                                      oldValue = debouncer.read();
                                      oldValue2 = debouncer2.read();
                                    
                                    
                                      // Make sure relays are off when starting up
                                      setRelayState(RELAY_PIN, RELAY_OFF);
                                      // Then set relay pins in output mode
                                      pinMode(RELAY_PIN, OUTPUT);
                                    
                                      digitalWrite(RELAY_PIN_2, RELAY_OFF);
                                      // Then set relay pins in output mode
                                      pinMode(RELAY_PIN_2, OUTPUT);
                                    
                                      // Set relay to last known state (using eeprom storage)
                                      state = loadState(CHILD_ID);
                                      setRelayState(RELAY_PIN, state);
                                    
                                      state2 = loadState(CHILD_ID_2);
                                      setRelayState(RELAY_PIN_2, state2);
                                    }
                                    
                                    
                                    /*
                                       Example on how to asynchronously check for new messages from gw
                                    */
                                    void loop()
                                    {
                                    #ifdef USE_TEMP_SENSOR
                                      static float prevTemp = 0;
                                    #endif
                                    
                                      debouncer.update();
                                      debouncer2.update();
                                      // Get the update value
                                      int value = debouncer.read();
                                      int value2 = debouncer2.read();
                                    
                                      if (value != oldValue) {
                                        state =  !state;                                                  // Toggle the state
                                        send(msg.set(state), false);                          // send new state to controller, no ack requested
                                        setRelayState(RELAY_PIN, state);                // switch the relay to the new state
                                        saveState(CHILD_ID, state);        // Store state in eeprom
                                        // Write some debug info
                                        printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID, value);
                                        oldValue = value;
                                      }
                                      
                                    
                                      if (value2 != oldValue2) {
                                        state2 =  !state2;                                         // Toggle the state
                                        send(msg2.set(state2), false);                 // send new state to controller, no ack requested
                                        setRelayState(RELAY_PIN_2, state2);     // switch the relay to the new state
                                        saveState(CHILD_ID_2, state2);     // Store state in eeprom
                                        // Write some debug info
                                        printStateChangedDebug(CHANGE_STATE_SOURCE_SWITCH, CHILD_ID_2, value2);
                                        oldValue2 = value2;
                                      }
                                      
                                    
                                      // Fetch temperatures from Dallas sensors
                                    #ifdef USE_TEMP_SENSOR
                                      sensors.requestTemperatures();
                                      // Fetch and round temperature to one decimal
                                      float temperature = static_cast<float>(static_cast<int>(sensors.getTempCByIndex(0) * TEMPERATURE_ROUNDING)) / TEMPERATURE_ROUNDING;
                                    
                                      if (temperature != -127.00f && temperature != 85.00f && prevTemp != temperature) {
                                        // Send in the new temperature
                                        send(msgTemp.set(temperature, 1));
                                    #ifdef MY_DEBUG
                                        Serial.print("Sent temperature: ");
                                        Serial.println(temperature);
                                    #endif
                                        prevTemp = temperature;
                                      }
                                    #endif
                                    }
                                    
                                    void receive(const MyMessage &message) { 
                                    if (message.type == V_STATUS) {
                                     switch (message.sensor) {
                                      case CHILD_ID:    
                                        state = message.getBool();          // Change relay state
                                        setRelayState(RELAY_PIN, state);    
                                        saveState(CHILD_ID, state);        // Store state in eeprom
                                        // Write some debug info
                                        printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID, state);
                                        break; 
                                      case CHILD_ID_2:
                                        state2 = message.getBool();
                                        setRelayState(RELAY_PIN_2, state2);
                                        saveState(CHILD_ID_2, state2);     // Store state in eeprom
                                        // Write some debug info
                                        printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID_2, state2);
                                        break;
                                      }
                                     }
                                    }
                                    
                                    
                                    
                                    // Set status of a relay pin
                                    void setRelayState(byte relayPin, bool value) {
                                      digitalWrite(relayPin, value ? RELAY_ON : RELAY_OFF);
                                    }
                                    
                                    // Print debug info, centralized in one place to minimize memory usage and have only one #ifdef MY_DEBUG for all state change messages
                                    void printStateChangedDebug(int source, int sensorID, bool value) {
                                    #ifdef MY_DEBUG
                                      Serial.print(F("Sensor value changed, source="));
                                      Serial.print(source == CHANGE_STATE_SOURCE_RADIO ? F("Radio") : F("Physical switch"));
                                      Serial.print(F(", Sensor="));
                                      Serial.print(sensorID);
                                      Serial.print(F(", New status: "));
                                      Serial.println(value);
                                    #endif
                                    }
                                    
                                    1 Reply Last reply
                                    1
                                    • folkestorpF Offline
                                      folkestorpF Offline
                                      folkestorp
                                      wrote on last edited by
                                      #198

                                      @Boots33 I have test your code without temp sensor. It works perfect. Thank you!!!

                                      Boots33B 1 Reply Last reply
                                      1
                                      • folkestorpF folkestorp

                                        @Boots33 I have test your code without temp sensor. It works perfect. Thank you!!!

                                        Boots33B Offline
                                        Boots33B Offline
                                        Boots33
                                        Hero Member
                                        wrote on last edited by
                                        #199

                                        @folkestorp great. Thanks for reporting back.

                                        1 Reply Last reply
                                        0
                                        • X Offline
                                          X Offline
                                          XerOps
                                          wrote on last edited by
                                          #200

                                          I got a problem. I connected the board directly to ä powersource but the adapter doesnt output 5V . The part before just output 230 v just fine. Any one has any sugestions on whatsapp im missing?

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


                                          17

                                          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