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. Error sending switch command at Gateway

Error sending switch command at Gateway

Scheduled Pinned Locked Moved Domoticz
3 Posts 2 Posters 619 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.
  • EmeE Offline
    EmeE Offline
    Eme
    wrote on last edited by Eme
    #1

    Hello All...
    I am having a problem with sending a 4 relay block code to Domoticz Gateway … sometimes the relays switch without any problem, but other times, it breaks out to an "Error sending switch command".

    I saw an earlier post at https://forum.mysensors.org/topic/4658/solved-error-sending-switch-command with the same issue. The solution proffered there didn't have much impart. One second it's working fine and the next its breaking into errors.

    I couldn't find a .1uf Capacitor, so I used an electrolytic 1uf instead. Worked fine in another Nfr+ radio Project, but I don't know if that's the problem here. My sketch is a follows:-

    // Example sketch showing how to control physical relays. 
    // This example will remember relay state even after power failure.
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    
    #define MY_NODE_ID 6  // Set this to fix your Radio ID or use AUTO or 1
    #define MY_REGISTRATION_FEATURE // Forece registration
    #define MY_REGISTRATION_RETRIES 5
    
    #include <Wire.h>
    #include <TimeLib.h>
    #include <SPI.h>
    #include <MySensors.h>
    #include <LCD.h>
    #include <LiquidCrystal.h>
    #include <LiquidCrystal_I2C.h>
    
    // For Debug
    #ifdef DEBUG_ON
    #define DEBUG_PRINT(x)   Serial.print(x)
    #define DEBUG_PRINTLN(x) Serial.println(x)
    #else
    #define DEBUG_PRINT(x)
    #define DEBUG_PRINTLN(x)
    #define SERIAL_START(x)
    #endif
    
    #define RELAY_PIN 2  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 4 // Total number of attached relays
    #define RELAY_ON 0  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    #define SKETCH_NAME "Swimming Pool Node"
    #define SKETCH_VERSION "0.1.4"
    #define CHILD_ID 0
    
    MyMessage msg(1,V_LIGHT);
    unsigned long SLEEP_TIME = 5000;   // Sleep time inbetween reads in milliseconds
    void setup()
    {
      for (int sensor=1, pin=RELAY_PIN; 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);   // to remember last state
        digitalWrite(pin, loadState? 0 : 0);   // Keep everything off after power failure
      }
    }
    
    void presentation() { 
      sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
    
      // Fetch relay status
      for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
        pinMode(pin, OUTPUT); // Then set relay pins in output mode  
    //    boolean savedState = loadState(sensor); // Set relay to last known state (using eeprom storage)
    //    digitalWrite(pin, savedState?RELAY_ON:RELAY_OFF);
    //    send(msg.set(savedState? 0 : 1));
      }
          DEBUG_PRINTLN(F("Sensor Presentation Complete"));
    }
    void loop() 
    {
    // Alway process incoming messages whenever possible
    // Sleep until interrupt comes in on motion sensor. Send update every two minute.
    //  sleep(digitalPinToInterrupt(msg.sensor-1+RELAY_PIN), CHANGE, SLEEP_TIME);
    wait(SLEEP_TIME);
    }
    void receive(const MyMessage &message){
    // Change relay state if message is receieved
    
       if (message.type == V_STATUS){
       digitalWrite(message.sensor-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
    // Store state in eeprom
       saveState(message.sensor-1+RELAY_PIN, message.getBool());
    // Write some debug info
       Serial.print("Incoming change for sensor ID: ");
       Serial.print(message.sensor);
       Serial.print(", New status: ");
       Serial.println(message.getBool());
        } 
      }
    

    I hear tagging this trio solves problems, so here goes... @tekka, @kk02067 and @hek to help me with this one. So sorry guys.

    EmeE 1 Reply Last reply
    0
    • EmeE Eme

      Hello All...
      I am having a problem with sending a 4 relay block code to Domoticz Gateway … sometimes the relays switch without any problem, but other times, it breaks out to an "Error sending switch command".

      I saw an earlier post at https://forum.mysensors.org/topic/4658/solved-error-sending-switch-command with the same issue. The solution proffered there didn't have much impart. One second it's working fine and the next its breaking into errors.

      I couldn't find a .1uf Capacitor, so I used an electrolytic 1uf instead. Worked fine in another Nfr+ radio Project, but I don't know if that's the problem here. My sketch is a follows:-

      // Example sketch showing how to control physical relays. 
      // This example will remember relay state even after power failure.
      
      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      
      #define MY_NODE_ID 6  // Set this to fix your Radio ID or use AUTO or 1
      #define MY_REGISTRATION_FEATURE // Forece registration
      #define MY_REGISTRATION_RETRIES 5
      
      #include <Wire.h>
      #include <TimeLib.h>
      #include <SPI.h>
      #include <MySensors.h>
      #include <LCD.h>
      #include <LiquidCrystal.h>
      #include <LiquidCrystal_I2C.h>
      
      // For Debug
      #ifdef DEBUG_ON
      #define DEBUG_PRINT(x)   Serial.print(x)
      #define DEBUG_PRINTLN(x) Serial.println(x)
      #else
      #define DEBUG_PRINT(x)
      #define DEBUG_PRINTLN(x)
      #define SERIAL_START(x)
      #endif
      
      #define RELAY_PIN 2  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 4 // Total number of attached relays
      #define RELAY_ON 0  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
      #define SKETCH_NAME "Swimming Pool Node"
      #define SKETCH_VERSION "0.1.4"
      #define CHILD_ID 0
      
      MyMessage msg(1,V_LIGHT);
      unsigned long SLEEP_TIME = 5000;   // Sleep time inbetween reads in milliseconds
      void setup()
      {
        for (int sensor=1, pin=RELAY_PIN; 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);   // to remember last state
          digitalWrite(pin, loadState? 0 : 0);   // Keep everything off after power failure
        }
      }
      
      void presentation() { 
        sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      
        // Fetch relay status
        for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
          // Register all sensors to gw (they will be created as child devices)
          present(sensor, S_BINARY);
          pinMode(pin, OUTPUT); // Then set relay pins in output mode  
      //    boolean savedState = loadState(sensor); // Set relay to last known state (using eeprom storage)
      //    digitalWrite(pin, savedState?RELAY_ON:RELAY_OFF);
      //    send(msg.set(savedState? 0 : 1));
        }
            DEBUG_PRINTLN(F("Sensor Presentation Complete"));
      }
      void loop() 
      {
      // Alway process incoming messages whenever possible
      // Sleep until interrupt comes in on motion sensor. Send update every two minute.
      //  sleep(digitalPinToInterrupt(msg.sensor-1+RELAY_PIN), CHANGE, SLEEP_TIME);
      wait(SLEEP_TIME);
      }
      void receive(const MyMessage &message){
      // Change relay state if message is receieved
      
         if (message.type == V_STATUS){
         digitalWrite(message.sensor-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
      // Store state in eeprom
         saveState(message.sensor-1+RELAY_PIN, message.getBool());
      // Write some debug info
         Serial.print("Incoming change for sensor ID: ");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
          } 
        }
      

      I hear tagging this trio solves problems, so here goes... @tekka, @kk02067 and @hek to help me with this one. So sorry guys.

      EmeE Offline
      EmeE Offline
      Eme
      wrote on last edited by
      #2

      @eme Okay I solved this by redoing the MySensors Gateway added 4.7uf cap and everything works fine now.

      dbemowskD 1 Reply Last reply
      0
      • EmeE Eme

        @eme Okay I solved this by redoing the MySensors Gateway added 4.7uf cap and everything works fine now.

        dbemowskD Offline
        dbemowskD Offline
        dbemowsk
        wrote on last edited by dbemowsk
        #3

        @eme If you are talking on the side of the nRF24 radio module then yes, the 4.7uf or above AFAIK is recommended in here as a minimum. I could see this happening if there were occasional packet collisions with the gateway because the radio cannot refresh fast enough due to of the quick draw of power on the radio.

        Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
        Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

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


        26

        Online

        11.7k

        Users

        11.2k

        Topics

        113.1k

        Posts


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

        • Don't have an account? Register

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