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. Domoticz
  4. Temp and Relay node

Temp and Relay node

Scheduled Pinned Locked Moved Domoticz
19 Posts 6 Posters 10.0k Views 5 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.
  • mikeeM mikee

    When I´m uploading sketch both two relays start to light and during upload switch off and when uploaded turn on.

    Moshe LivneM Offline
    Moshe LivneM Offline
    Moshe Livne
    Hero Member
    wrote on last edited by
    #6

    @mikee The switching on and off is normal as the sketch tries to restore the last saved state of the relay.
    do this:
    first try this sketch:

    #include <SPI.h>
    void setup() {
        pinMode(3, OUTPUT);
        digitalWrite(3, HIGH);
        delay(10000);
        digitalWrite(3, LOW);
        delay(10000);
        digitalWrite(3, HIGH);
        delay(10000);
        digitalWrite(3, LOW);
    }
    
    void loop()
    {}
    
        
    

    This should turn your relay (assuming it is on pin 3) on and off twice with 10 seconds between operations. I don't have one connected now so cant check it but it does compile and should work. you can also try this on arduino with no NRF.
    Let me know if it works or not

    1 Reply Last reply
    0
    • mikeeM Offline
      mikeeM Offline
      mikee
      wrote on last edited by
      #7

      Hi Moshe,
      I´ll try this after I come home, thanks

      1 Reply Last reply
      0
      • R Offline
        R Offline
        robosensor
        wrote on last edited by
        #8

        You should not query sensor temperatures every 750 ms. Try this code with proper pause between sensor readings: http://forum.mysensors.org/topic/1562/door-motion-and-temperature-sensor/34

        Also, your code is in constant 750ms delay, so incoming messages are delayed or even skipped. You should use newer code from git with non-blocking sensor readings: https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino

        Your code looks like this now:

        void loop()
        {
            gw.process(); 
            delay(750); // 750ms of no incoming messages processing, no response to relay msgs
        }
        
        1 Reply Last reply
        0
        • sundberg84S Offline
          sundberg84S Offline
          sundberg84
          Hardware Contributor
          wrote on last edited by
          #9

          Hi @mikee.

          It seems like the same problem in having at the moment: link
          Domoticz send command, node recieves and the node/relay led turns on but the coil does not activate.

          I tried with higher volatge and then the coil activated. I dont know why this happens but seems like some power issues.
          I have measure 5v over the signal but maybe to low mA to activate? According to datasheet you need 71.4mA
          I dont know how to measure this or if thats is more than the arduino can handle?

          Controller: Proxmox VM - Home Assistant
          MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
          MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
          RFLink GW - Arduino Mega + RFLink Shield, 433mhz

          Moshe LivneM 1 Reply Last reply
          0
          • mikeeM Offline
            mikeeM Offline
            mikee
            wrote on last edited by
            #10

            Exactly - I tried other sketch yesterday, that worked same way - LED turned on, but contacts stayed off. I will try to power the relay board separately with raw voltage from Arduino (9V)

            Moshe LivneM 1 Reply Last reply
            0
            • mikeeM mikee

              Exactly - I tried other sketch yesterday, that worked same way - LED turned on, but contacts stayed off. I will try to power the relay board separately with raw voltage from Arduino (9V)

              Moshe LivneM Offline
              Moshe LivneM Offline
              Moshe Livne
              Hero Member
              wrote on last edited by
              #11

              @mikee the relays can't take more than 5.5v.
              @robosensor is very right. The relay sensor sketch in the examples is made to also be a repeater node. repeater nodes (and nodes that can receive incoming messages) are looping endlessly processing messages. when you merged the sketches you got a sketch that tried to loop endlessley and to pause 750ms at the same time. this won't work.... you need to use the non blocking functions and implement the delay in the sketch the way the examples he sent are doing it.

              1 Reply Last reply
              0
              • sundberg84S sundberg84

                Hi @mikee.

                It seems like the same problem in having at the moment: link
                Domoticz send command, node recieves and the node/relay led turns on but the coil does not activate.

                I tried with higher volatge and then the coil activated. I dont know why this happens but seems like some power issues.
                I have measure 5v over the signal but maybe to low mA to activate? According to datasheet you need 71.4mA
                I dont know how to measure this or if thats is more than the arduino can handle?

                Moshe LivneM Offline
                Moshe LivneM Offline
                Moshe Livne
                Hero Member
                wrote on last edited by
                #12

                @sundberg84 try the mini sketch above - it does not use the NRF and has no network or controller dependence so it will tell you if there is enough juice to power the relays.

                1 Reply Last reply
                0
                • mikeeM Offline
                  mikeeM Offline
                  mikee
                  wrote on last edited by
                  #13

                  Thanks @robosensor , I´ll try it.
                  @Moshe Livne, Sure they can - on coil (at least mine is built so), but board must have jumpers to separate it . Input must be 5V- of course transistor would burn. I'll try your suggestions, thanks

                  1 Reply Last reply
                  0
                  • mikeeM Offline
                    mikeeM Offline
                    mikee
                    wrote on last edited by
                    #14

                    Hi Guys,
                    So after few day I´m back again :expressionless: . I started with @Moshe Livne test – worked just fine - thanks. I found more relay examples and the one from @petewill http://forum.mysensors.org/topic/775/8-lamp-outlet-smart-plug-module worked!!! Now I´m trying to merge new Dallas sketch – mentioned by robosensor with petewill s 8$ outlet:

                    #include <MySensor.h>  
                    #include <SPI.h>
                    #include <DallasTemperature.h>
                    #include <OneWire.h>
                    
                    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                    #define MAX_ATTACHED_DS18B20 16
                    //Relay 
                    #define RELAY_PIN  5  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                    #define RELAY_CHILD 0
                    #define NUMBER_OF_RELAYS 1 // 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
                    
                    //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                    OneWire oneWire(ONE_WIRE_BUS);
                    DallasTemperature sensors(&oneWire);
                    MySensor gw;
                    float lastTemperature[MAX_ATTACHED_DS18B20];
                    int numSensors=0;
                    boolean receivedConfig = false;
                    boolean metric = true; 
                    // Initialize temperature message
                    MyMessage msgT(0,V_TEMP);
                    MyMessage msg(RELAY_CHILD,V_LIGHT);
                    
                    
                    void setup()  
                    { 
                      // Startup OneWire 
                      sensors.begin();
                      // requestTemperatures() will not block current thread
                      sensors.setWaitForConversion(false);
                    
                      // Startup and initialize MySensors library. Set callback for incoming messages. 
                      gw.begin(); 
                    
                      // Send the sketch version information to the gateway and Controller
                      gw.sendSketchInfo("Temperature Sensor w relay", "1.0");
                    
                      // Fetch the number of attached temperature sensors  
                      numSensors = sensors.getDeviceCount();
                    
                      // Present all sensors to controller
                      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
                         gw.present(i, S_TEMP);
                         gw.present(RELAY_CHILD, S_LIGHT);
                          digitalWrite(RELAY_PIN, RELAY_OFF);
                          pinMode(RELAY_PIN, OUTPUT);
                      }
                    }
                    
                    
                    void loop()     
                    {     
                      // Process incoming messages (like config from server)
                      gw.process(); 
                    
                      // Fetch temperatures from Dallas sensors
                      sensors.requestTemperatures();
                    
                      // query conversion time and sleep until conversion completed
                      int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                      // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                      gw.sleep(conversionTime);
                    
                      // Read temperatures and send them to controller 
                      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
                     
                        // Fetch and round temperature to one decimal
                        float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                     
                        // Only send data if temperature has changed and no error
                        if (lastTemperature[i] != temperature && temperature != -127.00) {
                     
                          // Send in the new temperature
                          gw.send(msgT.setSensor(i).set(temperature,1));
                          lastTemperature[i]=temperature;
                        }
                      }
                      }
                      
                      void incomingMessage(const MyMessage &message) {
                      // We only expect one type of message from controller. But we better check anyway.
                      if (message.type==V_LIGHT) {
                         // Change relay state
                         digitalWrite(RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
                         // Store state in eeprom
                    //     gw.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());
                       } 
                    
                      
                      
                    
                      
                      //gw.sleep(SLEEP_TIME);
                    }
                    

                    It compiles, temperatures are working but relay is not working, can someone help me, pls.

                    @sundberg84 next day after I switch to latest Domoticz beta system started to freeze again. I´ts only after relay switch command pushed by user or even by timer (when I checked the logs of the switch all times are loged 5-7 minutes later than the switch time). Is there any tutorial or does exist system how to switch my Domoticz to your version (2606), without installing all Domoticz manually? I was able to run SD versions only and 2606 is zip file.
                    Thanks for your time Guys

                    1 Reply Last reply
                    0
                    • AWIA Offline
                      AWIA Offline
                      AWI
                      Hero Member
                      wrote on last edited by
                      #15

                      You need to initialize the incoming messages in gw.begin() otherwise you will never receive a message. i.e. gw.begin(incomingMessage, AUTO, false);

                      For the update of Domoticz, switch on the beta channel in settings and push the update button. No need to reinstall.

                      1 Reply Last reply
                      0
                      • mikeeM Offline
                        mikeeM Offline
                        mikee
                        wrote on last edited by
                        #16

                        HI, @AWI I tried

                        gw.begin(incomingMessage, AUTO, false);
                        

                        and then

                        gw.begin(incomingMessage, NODE_ID);
                        

                        After I changed #define RELAY_CHILD 0 to 6 and once (one of many tries) I turned it on, but couldn’t turn it off. In serial monitor of node is no command to switch visible.

                        #include <MySensor.h>  
                        #include <SPI.h>
                        #include <DallasTemperature.h>
                        #include <OneWire.h>
                        #define NODE_ID 19
                        #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                        #define MAX_ATTACHED_DS18B20 16
                        //Relay 
                        #define RELAY_PIN  5  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                        #define RELAY_CHILD 0
                        #define NUMBER_OF_RELAYS 1 // 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
                        
                        //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                        OneWire oneWire(ONE_WIRE_BUS);
                        DallasTemperature sensors(&oneWire);
                        MySensor gw;
                        float lastTemperature[MAX_ATTACHED_DS18B20];
                        int numSensors=0;
                        boolean receivedConfig = false;
                        boolean metric = true; 
                        // Initialize temperature message
                        MyMessage msgT(0,V_TEMP);
                        MyMessage msg(RELAY_CHILD,V_LIGHT);
                        
                        
                        void setup()  
                        { 
                          // Startup OneWire 
                          sensors.begin();
                          // requestTemperatures() will not block current thread
                          sensors.setWaitForConversion(false);
                        
                          // Startup and initialize MySensors library. Set callback for incoming messages. 
                          gw.begin(incomingMessage, AUTO, false); 
                        
                          // Send the sketch version information to the gateway and Controller
                          gw.sendSketchInfo("Temperature Sensor w relay", "1.0");
                        
                          // Fetch the number of attached temperature sensors  
                          numSensors = sensors.getDeviceCount();
                        
                          // Present all sensors to controller
                          for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
                             gw.present(i, S_TEMP);
                             gw.present(RELAY_CHILD, S_LIGHT);
                              digitalWrite(RELAY_PIN, RELAY_OFF);
                              pinMode(RELAY_PIN, OUTPUT);
                          }
                        }
                        void loop()     
                        {     
                          // Process incoming messages (like config from server)
                          gw.process(); 
                        
                          // Fetch temperatures from Dallas sensors
                          sensors.requestTemperatures();
                        
                          // query conversion time and sleep until conversion completed
                          int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                          // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                          gw.sleep(conversionTime);
                        
                          // Read temperatures and send them to controller 
                          for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
                         
                            // Fetch and round temperature to one decimal
                            float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                         
                            // Only send data if temperature has changed and no error
                            if (lastTemperature[i] != temperature && temperature != -127.00) {
                         
                              // Send in the new temperature
                              gw.send(msgT.setSensor(i).set(temperature,1));
                              lastTemperature[i]=temperature;
                            }
                          }
                        }
                          void incomingMessage(const MyMessage &message) {
                          // We only expect one type of message from controller. But we better check anyway.
                          if (message.type==V_LIGHT) {
                             // Change relay state
                             digitalWrite(RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
                             // Store state in eeprom
                        //     gw.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());
                           }   
                          //gw.sleep(SLEEP_TIME);
                        }
                        #include <MySensor.h>  
                        #include <SPI.h>
                        #include <DallasTemperature.h>
                        #include <OneWire.h>
                        
                        #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                        #define MAX_ATTACHED_DS18B20 16
                        //Relay 
                        #define RELAY_PIN  5  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                        #define RELAY_CHILD 0
                        #define NUMBER_OF_RELAYS 1 // 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
                        
                        //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                        OneWire oneWire(ONE_WIRE_BUS);
                        DallasTemperature sensors(&oneWire);
                        MySensor gw;
                        float lastTemperature[MAX_ATTACHED_DS18B20];
                        int numSensors=0;
                        boolean receivedConfig = false;
                        boolean metric = true; 
                        // Initialize temperature message
                        MyMessage msgT(0,V_TEMP);
                        MyMessage msg(RELAY_CHILD,V_LIGHT);
                        
                        
                        void setup()  
                        { 
                          // Startup OneWire 
                          sensors.begin();
                          // requestTemperatures() will not block current thread
                          sensors.setWaitForConversion(false);
                        
                          // Startup and initialize MySensors library. Set callback for incoming messages. 
                          gw.begin(incomingMessage, AUTO, false); 
                        
                          // Send the sketch version information to the gateway and Controller
                          gw.sendSketchInfo("Temperature Sensor w relay", "1.0");
                        
                          // Fetch the number of attached temperature sensors  
                          numSensors = sensors.getDeviceCount();
                        
                          // Present all sensors to controller
                          for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
                             gw.present(i, S_TEMP);
                             gw.present(RELAY_CHILD, S_LIGHT);
                              digitalWrite(RELAY_PIN, RELAY_OFF);
                              pinMode(RELAY_PIN, OUTPUT);
                          }
                        }
                        void loop()     
                        {     
                          // Process incoming messages (like config from server)
                          gw.process(); 
                        
                          // Fetch temperatures from Dallas sensors
                          sensors.requestTemperatures();
                        
                          // query conversion time and sleep until conversion completed
                          int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                          // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                          gw.sleep(conversionTime);
                        
                          // Read temperatures and send them to controller 
                          for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
                         
                            // Fetch and round temperature to one decimal
                            float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                         
                            // Only send data if temperature has changed and no error
                            if (lastTemperature[i] != temperature && temperature != -127.00) {
                         
                              // Send in the new temperature
                              gw.send(msgT.setSensor(i).set(temperature,1));
                              lastTemperature[i]=temperature;
                            }
                          }
                        }
                          void incomingMessage(const MyMessage &message) {
                          // We only expect one type of message from controller. But we better check anyway.
                          if (message.type==V_LIGHT) {
                             // Change relay state
                             digitalWrite(RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
                             // Store state in eeprom
                        //     gw.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());
                           }   
                          //gw.sleep(SLEEP_TIME);
                        }
                        

                        Is something wrong with identification of relay? Temperatures are working just fine.

                        AWIA 1 Reply Last reply
                        0
                        • mikeeM mikee

                          HI, @AWI I tried

                          gw.begin(incomingMessage, AUTO, false);
                          

                          and then

                          gw.begin(incomingMessage, NODE_ID);
                          

                          After I changed #define RELAY_CHILD 0 to 6 and once (one of many tries) I turned it on, but couldn’t turn it off. In serial monitor of node is no command to switch visible.

                          #include <MySensor.h>  
                          #include <SPI.h>
                          #include <DallasTemperature.h>
                          #include <OneWire.h>
                          #define NODE_ID 19
                          #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                          #define MAX_ATTACHED_DS18B20 16
                          //Relay 
                          #define RELAY_PIN  5  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                          #define RELAY_CHILD 0
                          #define NUMBER_OF_RELAYS 1 // 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
                          
                          //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                          OneWire oneWire(ONE_WIRE_BUS);
                          DallasTemperature sensors(&oneWire);
                          MySensor gw;
                          float lastTemperature[MAX_ATTACHED_DS18B20];
                          int numSensors=0;
                          boolean receivedConfig = false;
                          boolean metric = true; 
                          // Initialize temperature message
                          MyMessage msgT(0,V_TEMP);
                          MyMessage msg(RELAY_CHILD,V_LIGHT);
                          
                          
                          void setup()  
                          { 
                            // Startup OneWire 
                            sensors.begin();
                            // requestTemperatures() will not block current thread
                            sensors.setWaitForConversion(false);
                          
                            // Startup and initialize MySensors library. Set callback for incoming messages. 
                            gw.begin(incomingMessage, AUTO, false); 
                          
                            // Send the sketch version information to the gateway and Controller
                            gw.sendSketchInfo("Temperature Sensor w relay", "1.0");
                          
                            // Fetch the number of attached temperature sensors  
                            numSensors = sensors.getDeviceCount();
                          
                            // Present all sensors to controller
                            for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
                               gw.present(i, S_TEMP);
                               gw.present(RELAY_CHILD, S_LIGHT);
                                digitalWrite(RELAY_PIN, RELAY_OFF);
                                pinMode(RELAY_PIN, OUTPUT);
                            }
                          }
                          void loop()     
                          {     
                            // Process incoming messages (like config from server)
                            gw.process(); 
                          
                            // Fetch temperatures from Dallas sensors
                            sensors.requestTemperatures();
                          
                            // query conversion time and sleep until conversion completed
                            int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                            // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                            gw.sleep(conversionTime);
                          
                            // Read temperatures and send them to controller 
                            for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
                           
                              // Fetch and round temperature to one decimal
                              float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                           
                              // Only send data if temperature has changed and no error
                              if (lastTemperature[i] != temperature && temperature != -127.00) {
                           
                                // Send in the new temperature
                                gw.send(msgT.setSensor(i).set(temperature,1));
                                lastTemperature[i]=temperature;
                              }
                            }
                          }
                            void incomingMessage(const MyMessage &message) {
                            // We only expect one type of message from controller. But we better check anyway.
                            if (message.type==V_LIGHT) {
                               // Change relay state
                               digitalWrite(RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
                               // Store state in eeprom
                          //     gw.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());
                             }   
                            //gw.sleep(SLEEP_TIME);
                          }
                          #include <MySensor.h>  
                          #include <SPI.h>
                          #include <DallasTemperature.h>
                          #include <OneWire.h>
                          
                          #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                          #define MAX_ATTACHED_DS18B20 16
                          //Relay 
                          #define RELAY_PIN  5  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
                          #define RELAY_CHILD 0
                          #define NUMBER_OF_RELAYS 1 // 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
                          
                          //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
                          OneWire oneWire(ONE_WIRE_BUS);
                          DallasTemperature sensors(&oneWire);
                          MySensor gw;
                          float lastTemperature[MAX_ATTACHED_DS18B20];
                          int numSensors=0;
                          boolean receivedConfig = false;
                          boolean metric = true; 
                          // Initialize temperature message
                          MyMessage msgT(0,V_TEMP);
                          MyMessage msg(RELAY_CHILD,V_LIGHT);
                          
                          
                          void setup()  
                          { 
                            // Startup OneWire 
                            sensors.begin();
                            // requestTemperatures() will not block current thread
                            sensors.setWaitForConversion(false);
                          
                            // Startup and initialize MySensors library. Set callback for incoming messages. 
                            gw.begin(incomingMessage, AUTO, false); 
                          
                            // Send the sketch version information to the gateway and Controller
                            gw.sendSketchInfo("Temperature Sensor w relay", "1.0");
                          
                            // Fetch the number of attached temperature sensors  
                            numSensors = sensors.getDeviceCount();
                          
                            // Present all sensors to controller
                            for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
                               gw.present(i, S_TEMP);
                               gw.present(RELAY_CHILD, S_LIGHT);
                                digitalWrite(RELAY_PIN, RELAY_OFF);
                                pinMode(RELAY_PIN, OUTPUT);
                            }
                          }
                          void loop()     
                          {     
                            // Process incoming messages (like config from server)
                            gw.process(); 
                          
                            // Fetch temperatures from Dallas sensors
                            sensors.requestTemperatures();
                          
                            // query conversion time and sleep until conversion completed
                            int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                            // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                            gw.sleep(conversionTime);
                          
                            // Read temperatures and send them to controller 
                            for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
                           
                              // Fetch and round temperature to one decimal
                              float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                           
                              // Only send data if temperature has changed and no error
                              if (lastTemperature[i] != temperature && temperature != -127.00) {
                           
                                // Send in the new temperature
                                gw.send(msgT.setSensor(i).set(temperature,1));
                                lastTemperature[i]=temperature;
                              }
                            }
                          }
                            void incomingMessage(const MyMessage &message) {
                            // We only expect one type of message from controller. But we better check anyway.
                            if (message.type==V_LIGHT) {
                               // Change relay state
                               digitalWrite(RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
                               // Store state in eeprom
                          //     gw.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());
                             }   
                            //gw.sleep(SLEEP_TIME);
                          }
                          

                          Is something wrong with identification of relay? Temperatures are working just fine.

                          AWIA Offline
                          AWIA Offline
                          AWI
                          Hero Member
                          wrote on last edited by
                          #17

                          @mikee how many temperature sensors are you using? The id of the relay sensor should be higher than that number (better to use a value higher than Max number. Else there is overlap.
                          You are also presenting the relay more than once in the init loop. Once should be enough. When switching the relay from the controller it should be visible in the serial output of the node.

                          1 Reply Last reply
                          0
                          • mikeeM Offline
                            mikeeM Offline
                            mikee
                            wrote on last edited by
                            #18

                            Hi @AWI , I have 5 DS 18b20s , i chose CHILD ID 6 because of that , so I´m gonna lower max . temp sensor No.
                            Witch line in sketch is duplicity of relay presentation (sorry for dumb questions),
                            Thanks so much

                            AWIA 1 Reply Last reply
                            0
                            • mikeeM mikee

                              Hi @AWI , I have 5 DS 18b20s , i chose CHILD ID 6 because of that , so I´m gonna lower max . temp sensor No.
                              Witch line in sketch is duplicity of relay presentation (sorry for dumb questions),
                              Thanks so much

                              AWIA Offline
                              AWIA Offline
                              AWI
                              Hero Member
                              wrote on last edited by AWI
                              #19

                              @mikee in the setup loop for the temp sensors you are also presenting the relay. So one time for each temp sensor. You can just place it outside of the loop.

                                for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
                                   gw.present(i, S_TEMP);
                                   gw.present(RELAY_CHILD, S_LIGHT);
                                    digitalWrite(RELAY_PIN, RELAY_OFF);
                                    pinMode(RELAY_PIN, OUTPUT);
                                }
                              

                              It won't solve your problem but is more decent. Then try to make sure you are getting the relay input from the controller by looking at the serial output of the node

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


                              13

                              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