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

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Relay not reacting first 3 seconds

Relay not reacting first 3 seconds

Scheduled Pinned Locked Moved Development
4 Posts 2 Posters 1.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • derksuhD Offline
    derksuhD Offline
    derksuh
    wrote on last edited by
    #1

    Hello all,

    I have the following sketch working with a pimatic installation. When i switch on the relay nothing happens
    when i keep switching it on and off than after 2 or 3 times it starts reacting. But every time i wait a couple of seconds
    i have to switch it on and off a couple of times before it reacts. This is th epimatic log output if i switch it on the first time.

    debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;!TSF:MSG:LEN,2!=7
    19:53:48debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSF:MSG:READ,25-12-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
    19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
    19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;MCO:BGN:STP
    19:45:45debug [pimatic-mysensors]: <- Presented Node  [ '0', '255', '0', '0', '18', '2.1.1' ]
    19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;MCO:REG:NOT NEEDED
    19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
    19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSM:INIT:GW MODE
    19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSM:INIT:TSP OK
    19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSF:WUR:MS=0
    19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSM:INIT
    19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGA--,VER=2.1.1
    19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;!TSF:MSG:SEND,0-0-5-5,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=NACK:1
    19:45:44debug [pimatic-mysensors]: -> Sending  5;1;1;1;2;1
    

    if it starts reacting i get this output.

    debug [pimatic-mysensors]: <- MySensorDHT  { sender: 5, sensor: 1, type: 2, value: '1' }
    19:45:04debug [pimatic-mysensors]: <- MySensorSwitch  { sender: 5, sensor: 1, type: 2, value: '1' }
    19:45:04debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSF:MSG:ACK
    19:45:04debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSF:MSG:READ,5-5-0,s=1,c=1,t=2,pt=0,l=1,sg=0:1
    19:45:04debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSF:MSG:SEND,0-0-5-5,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1
    19:45:04debug [pimatic-mysensors]: -> Sending  5;1;1;1;2;1```
    
    
    This is the sketch i am using
    
    ```#define MY_NODE_ID 5
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DHT.h>  
    
    #define CHILD_ID_HUM 1
    #define CHILD_ID_TEMP 2
    #define HUMIDITY_SENSOR_DIGITAL_PIN 6
    unsigned long WAIT_TIME = 30000; // Sleep time between reads (in milliseconds)
    unsigned long lastRefreshTime = 0; // Use this to implement a non-blocking delay function
    
    #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 0  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    
    
    
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    
    void setup()  
    { 
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      metric = getConfig().isMetric;
    
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
        // Request the latest relay status from the gateway 
      Serial.println("Requesting initial value from controller");
      request(RELAY_1, V_STATUS);
    }
    
    void presentation()  
    { 
      // Send the Sketch Version Information to the Gateway
      sendSketchInfo("Badkamer", "1.3");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
    
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_LIGHT);
      }
    }
    
    
    void loop()      
    { 
      boolean needRefresh = (millis() - lastRefreshTime) > WAIT_TIME;
      if (needRefresh)
      {
          lastRefreshTime = millis();
          
          float temperature = dht.getTemperature();
          if (isnan(temperature)) {
              Serial.println("Failed reading temperature from DHT");
          } else if (temperature != lastTemp) {
            lastTemp = temperature;
            if (!metric) {
              temperature = dht.toFahrenheit(temperature);
            }
            send(msgTemp.set(temperature, 1));
            Serial.print("T: ");
            Serial.println(temperature);
          }
          
          float humidity = dht.getHumidity();
          if (isnan(humidity)) {
              Serial.println("Failed reading humidity from DHT");
          } else if (humidity != lastHum) {
              lastHum = humidity;
              send(msgHum.set(humidity, 1));
              Serial.print("H: ");
              Serial.println(humidity);
          }
    
      }
      
    }
    
    void receive(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(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
         // Store state in eeprom
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
    }
    
    rejoe2R 1 Reply Last reply
    0
    • derksuhD derksuh

      Hello all,

      I have the following sketch working with a pimatic installation. When i switch on the relay nothing happens
      when i keep switching it on and off than after 2 or 3 times it starts reacting. But every time i wait a couple of seconds
      i have to switch it on and off a couple of times before it reacts. This is th epimatic log output if i switch it on the first time.

      debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;!TSF:MSG:LEN,2!=7
      19:53:48debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSF:MSG:READ,25-12-0,s=0,c=0,t=0,pt=0,l=0,sg=0:
      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;MCO:BGN:INIT OK,TSP=1
      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;MCO:BGN:STP
      19:45:45debug [pimatic-mysensors]: <- Presented Node  [ '0', '255', '0', '0', '18', '2.1.1' ]
      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;MCO:REG:NOT NEEDED
      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSM:READY:ID=0,PAR=0,DIS=0
      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSM:INIT:GW MODE
      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSM:INIT:TSP OK
      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSF:WUR:MS=0
      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSM:INIT
      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGA--,VER=2.1.1
      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;!TSF:MSG:SEND,0-0-5-5,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=NACK:1
      19:45:44debug [pimatic-mysensors]: -> Sending  5;1;1;1;2;1
      

      if it starts reacting i get this output.

      debug [pimatic-mysensors]: <- MySensorDHT  { sender: 5, sensor: 1, type: 2, value: '1' }
      19:45:04debug [pimatic-mysensors]: <- MySensorSwitch  { sender: 5, sensor: 1, type: 2, value: '1' }
      19:45:04debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSF:MSG:ACK
      19:45:04debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSF:MSG:READ,5-5-0,s=1,c=1,t=2,pt=0,l=1,sg=0:1
      19:45:04debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;TSF:MSG:SEND,0-0-5-5,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1
      19:45:04debug [pimatic-mysensors]: -> Sending  5;1;1;1;2;1```
      
      
      This is the sketch i am using
      
      ```#define MY_NODE_ID 5
      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #include <SPI.h>
      #include <MySensors.h>  
      #include <DHT.h>  
      
      #define CHILD_ID_HUM 1
      #define CHILD_ID_TEMP 2
      #define HUMIDITY_SENSOR_DIGITAL_PIN 6
      unsigned long WAIT_TIME = 30000; // Sleep time between reads (in milliseconds)
      unsigned long lastRefreshTime = 0; // Use this to implement a non-blocking delay function
      
      #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 1 // Total number of attached relays
      #define RELAY_ON 0  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
      
      
      
      DHT dht;
      float lastTemp;
      float lastHum;
      boolean metric = true; 
      MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      
      
      void setup()  
      { 
        dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
      
        metric = getConfig().isMetric;
      
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          // Then set relay pins in output mode
          pinMode(pin, OUTPUT);   
          // Set relay to last known state (using eeprom storage) 
          digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
        }
          // Request the latest relay status from the gateway 
        Serial.println("Requesting initial value from controller");
        request(RELAY_1, V_STATUS);
      }
      
      void presentation()  
      { 
        // Send the Sketch Version Information to the Gateway
        sendSketchInfo("Badkamer", "1.3");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_HUM, S_HUM);
        present(CHILD_ID_TEMP, S_TEMP);
      
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          // Register all sensors to gw (they will be created as child devices)
          present(sensor, S_LIGHT);
        }
      }
      
      
      void loop()      
      { 
        boolean needRefresh = (millis() - lastRefreshTime) > WAIT_TIME;
        if (needRefresh)
        {
            lastRefreshTime = millis();
            
            float temperature = dht.getTemperature();
            if (isnan(temperature)) {
                Serial.println("Failed reading temperature from DHT");
            } else if (temperature != lastTemp) {
              lastTemp = temperature;
              if (!metric) {
                temperature = dht.toFahrenheit(temperature);
              }
              send(msgTemp.set(temperature, 1));
              Serial.print("T: ");
              Serial.println(temperature);
            }
            
            float humidity = dht.getHumidity();
            if (isnan(humidity)) {
                Serial.println("Failed reading humidity from DHT");
            } else if (humidity != lastHum) {
                lastHum = humidity;
                send(msgHum.set(humidity, 1));
                Serial.print("H: ");
                Serial.println(humidity);
            }
      
        }
        
      }
      
      void receive(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(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
           // Store state in eeprom
           Serial.print("Incoming change for sensor:");
           Serial.print(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
         } 
      }
      
      rejoe2R Offline
      rejoe2R Offline
      rejoe2
      wrote on last edited by
      #2

      @derksuh Could you check, if your GW is rebooting all the time?
      The debug message

      19:45:45debug [pimatic-mysensors]: <- I_LOG_MESSAGE  0;255;3;0;9;MCO:BGN:INIT GW,CP=RNNGA--,VER=2.1.1
      

      looks like a reboot to me.
      Root cause could be a faulty AVR board definition (should be latest (1.6.18+) or <=1.6.11). Affected: Serial GWs and Ethernet-GW's.

      Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

      1 Reply Last reply
      0
      • derksuhD Offline
        derksuhD Offline
        derksuh
        wrote on last edited by
        #3

        @rejoe2 said in Relay not reacting first 3 seconds:

        AVR board definition

        If this is the problem then could i do something about it?

        rejoe2R 1 Reply Last reply
        0
        • derksuhD derksuh

          @rejoe2 said in Relay not reacting first 3 seconds:

          AVR board definition

          If this is the problem then could i do something about it?

          rejoe2R Offline
          rejoe2R Offline
          rejoe2
          wrote on last edited by
          #4

          @derksuh For information which version of the board defs you use (and for up- and downgrading also): Within the Arduino IDE you can just use the boardmanager (Tools menue, as far as I remember) to do this...

          Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

          1 Reply Last reply
          0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          7

          Online

          12.0k

          Users

          11.2k

          Topics

          113.4k

          Posts


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

          • Don't have an account? Register

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