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. Troubleshooting
  3. "Error sending switch command, check device/hardware !"

"Error sending switch command, check device/hardware !"

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 5 Posters 2.2k Views 3 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.
  • S Offline
    S Offline
    sama
    wrote on last edited by
    #1

    hello .
    I have problem with switch command.i am using this sketch:

    /**
     * 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.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     *
     * DESCRIPTION
     * Example sketch for a "light switch" where you can control light or something
     * else from both HA controller and a local physical button
     * (connected between digital pin 3 and GND).
     * This node also works as a repeader for other nodes
     * http://www.mysensors.org/build/relay
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enabled repeater feature for this node
    #define MY_REPEATER_FEATURE
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define RELAY_PIN1  6  // Arduino Digital I/O pin number for relay 
    #define BUTTON_PIN1  3  // Arduino Digital I/O pin number for button 
    #define CHILD_ID1 1   // Id of the sensor child
    #define RELAY_PIN2  7  // Arduino Digital I/O pin number for relay 
    #define BUTTON_PIN2  4  // Arduino Digital I/O pin number for button 
    #define CHILD_ID2 2   // Id of the sensor child
    #define RELAY_PIN3  8  // Arduino Digital I/O pin number for relay 
    #define BUTTON_PIN3  5  // Arduino Digital I/O pin number for button 
    #define CHILD_ID3 3   // Id of the sensor child
    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    Bounce debouncer1 = Bounce();
    int oldValue1 = 0;
    bool state1;
    Bounce debouncer2 = Bounce();
    int oldValue2 = 0;
    bool state2;
    Bounce debouncer3 = Bounce();
    int oldValue3 = 0;
    bool state3;
    
    MyMessage msg1(CHILD_ID1, V_LIGHT);
    MyMessage msg2(CHILD_ID2, V_LIGHT);
    MyMessage msg3(CHILD_ID3, V_LIGHT);
    
    void setup()
    {
      // Setup the button
      pinMode(BUTTON_PIN1, INPUT);
      digitalWrite(BUTTON_PIN1, HIGH);
      pinMode(BUTTON_PIN2, INPUT);
      digitalWrite(BUTTON_PIN2, HIGH);
      pinMode(BUTTON_PIN3, INPUT);
      digitalWrite(BUTTON_PIN3, HIGH);
    
      // After setting up the button, setup debouncer
      debouncer1.attach(BUTTON_PIN1);
      debouncer1.interval(5);
      debouncer2.attach(BUTTON_PIN2);
      debouncer2.interval(5);
      debouncer3.attach(BUTTON_PIN3);
      debouncer3.interval(5);
    
      // Make sure relays are off when starting up
      digitalWrite(RELAY_PIN1, RELAY_OFF);
      pinMode(RELAY_PIN1, OUTPUT);
      digitalWrite(RELAY_PIN2, RELAY_OFF);
      pinMode(RELAY_PIN2, OUTPUT);
      digitalWrite(RELAY_PIN3, RELAY_OFF);
      pinMode(RELAY_PIN3, OUTPUT);
    
      // Set relay to last known state (using eeprom storage)
      state1 = loadState(CHILD_ID1);
      digitalWrite(RELAY_PIN1, state1 ? RELAY_ON : RELAY_OFF);
      state2 = loadState(CHILD_ID2);
      digitalWrite(RELAY_PIN2, state2 ? RELAY_ON : RELAY_OFF);
      state3 = loadState(CHILD_ID3);
      digitalWrite(RELAY_PIN3, state3 ? RELAY_ON : RELAY_OFF);
    }
    
    void presentation()  {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay & Button", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID1, S_LIGHT);
      present(CHILD_ID2, S_LIGHT);
      present(CHILD_ID3, S_LIGHT);
    }
    
    /*
    *  Example on how to asynchronously check for new messages from gw
    */
    void loop()
    {
      { debouncer1.update();
        // Get the update value
        int value1 = debouncer1.read();
        if (value1 != oldValue1 && value1 == 0) {
          send(msg1.set(state1 ? false : true), true); // Send new state and request ack back
        }
        oldValue1 = value1;
      }
      { debouncer2.update();
        // Get the update value
        int value2 = debouncer2.read();
        if (value2 != oldValue2 && value2 == 0) {
          send(msg2.set(state2 ? false : true), true); // Send new state and request ack back
        }
        oldValue2 = value2;
      }
      { debouncer3.update();
        // Get the update value
        int value3 = debouncer3.read();
        if (value3 != oldValue3 && value3 == 0) {
          send(msg3.set(state3 ? false : true), true); // Send new state and request ack back
        }
        oldValue3 = value3;
      }
    }
    
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.isAck()) {
        Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_LIGHT) {
        switch (message.sensor) {
          case 1:
            state1 = message.getBool();
            digitalWrite(message.sensor + 2, state1 ? RELAY_ON : RELAY_OFF);
    
            break;
          case 2:
            state2 = message.getBool();
            digitalWrite(message.sensor + 2, state2 ? RELAY_ON : RELAY_OFF);
    
            break;
          case 3:
            state3 = message.getBool();
            digitalWrite(message.sensor + 2, state3 ? RELAY_ON : RELAY_OFF);
    
            break;
    
        }
    
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    

    this is a 3 channel relay with button.
    some time commands sent and some time could not be sent and show "Error sending switch command, check device/hardware !" I did take steps in accordance site and use a 4.7uf capacitor between vcc and gnd in radio . now some time command sent . some time could not be sent and i wait for a time (1 min , 2 min and more) and again send command and this is ok ! also when for test i sent some consecutive command (on/off/on/off/on) so again i see "Error sending switch command, check device/hardware !" i wait again and after a while work again and ok !
    I did search between topics and i see some suggest to use this module:
    link text
    so i use this but the problem did not solve for me .
    also i use a repeater between node and gateway but...
    Does anyone a proposal for my problem ?

    Best Regards S_m .

    AnticimexA 1 Reply Last reply
    0
    • S sama

      hello .
      I have problem with switch command.i am using this sketch:

      /**
       * 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.
       *
       *******************************
       *
       * REVISION HISTORY
       * Version 1.0 - Henrik Ekblad
       *
       * DESCRIPTION
       * Example sketch for a "light switch" where you can control light or something
       * else from both HA controller and a local physical button
       * (connected between digital pin 3 and GND).
       * This node also works as a repeader for other nodes
       * http://www.mysensors.org/build/relay
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Enabled repeater feature for this node
      #define MY_REPEATER_FEATURE
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <Bounce2.h>
      
      #define RELAY_PIN1  6  // Arduino Digital I/O pin number for relay 
      #define BUTTON_PIN1  3  // Arduino Digital I/O pin number for button 
      #define CHILD_ID1 1   // Id of the sensor child
      #define RELAY_PIN2  7  // Arduino Digital I/O pin number for relay 
      #define BUTTON_PIN2  4  // Arduino Digital I/O pin number for button 
      #define CHILD_ID2 2   // Id of the sensor child
      #define RELAY_PIN3  8  // Arduino Digital I/O pin number for relay 
      #define BUTTON_PIN3  5  // Arduino Digital I/O pin number for button 
      #define CHILD_ID3 3   // Id of the sensor child
      #define RELAY_ON 1
      #define RELAY_OFF 0
      
      Bounce debouncer1 = Bounce();
      int oldValue1 = 0;
      bool state1;
      Bounce debouncer2 = Bounce();
      int oldValue2 = 0;
      bool state2;
      Bounce debouncer3 = Bounce();
      int oldValue3 = 0;
      bool state3;
      
      MyMessage msg1(CHILD_ID1, V_LIGHT);
      MyMessage msg2(CHILD_ID2, V_LIGHT);
      MyMessage msg3(CHILD_ID3, V_LIGHT);
      
      void setup()
      {
        // Setup the button
        pinMode(BUTTON_PIN1, INPUT);
        digitalWrite(BUTTON_PIN1, HIGH);
        pinMode(BUTTON_PIN2, INPUT);
        digitalWrite(BUTTON_PIN2, HIGH);
        pinMode(BUTTON_PIN3, INPUT);
        digitalWrite(BUTTON_PIN3, HIGH);
      
        // After setting up the button, setup debouncer
        debouncer1.attach(BUTTON_PIN1);
        debouncer1.interval(5);
        debouncer2.attach(BUTTON_PIN2);
        debouncer2.interval(5);
        debouncer3.attach(BUTTON_PIN3);
        debouncer3.interval(5);
      
        // Make sure relays are off when starting up
        digitalWrite(RELAY_PIN1, RELAY_OFF);
        pinMode(RELAY_PIN1, OUTPUT);
        digitalWrite(RELAY_PIN2, RELAY_OFF);
        pinMode(RELAY_PIN2, OUTPUT);
        digitalWrite(RELAY_PIN3, RELAY_OFF);
        pinMode(RELAY_PIN3, OUTPUT);
      
        // Set relay to last known state (using eeprom storage)
        state1 = loadState(CHILD_ID1);
        digitalWrite(RELAY_PIN1, state1 ? RELAY_ON : RELAY_OFF);
        state2 = loadState(CHILD_ID2);
        digitalWrite(RELAY_PIN2, state2 ? RELAY_ON : RELAY_OFF);
        state3 = loadState(CHILD_ID3);
        digitalWrite(RELAY_PIN3, state3 ? RELAY_ON : RELAY_OFF);
      }
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Relay & Button", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID1, S_LIGHT);
        present(CHILD_ID2, S_LIGHT);
        present(CHILD_ID3, S_LIGHT);
      }
      
      /*
      *  Example on how to asynchronously check for new messages from gw
      */
      void loop()
      {
        { debouncer1.update();
          // Get the update value
          int value1 = debouncer1.read();
          if (value1 != oldValue1 && value1 == 0) {
            send(msg1.set(state1 ? false : true), true); // Send new state and request ack back
          }
          oldValue1 = value1;
        }
        { debouncer2.update();
          // Get the update value
          int value2 = debouncer2.read();
          if (value2 != oldValue2 && value2 == 0) {
            send(msg2.set(state2 ? false : true), true); // Send new state and request ack back
          }
          oldValue2 = value2;
        }
        { debouncer3.update();
          // Get the update value
          int value3 = debouncer3.read();
          if (value3 != oldValue3 && value3 == 0) {
            send(msg3.set(state3 ? false : true), true); // Send new state and request ack back
          }
          oldValue3 = value3;
        }
      }
      
      void receive(const MyMessage &message) {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.isAck()) {
          Serial.println("This is an ack from gateway");
        }
      
        if (message.type == V_LIGHT) {
          switch (message.sensor) {
            case 1:
              state1 = message.getBool();
              digitalWrite(message.sensor + 2, state1 ? RELAY_ON : RELAY_OFF);
      
              break;
            case 2:
              state2 = message.getBool();
              digitalWrite(message.sensor + 2, state2 ? RELAY_ON : RELAY_OFF);
      
              break;
            case 3:
              state3 = message.getBool();
              digitalWrite(message.sensor + 2, state3 ? RELAY_ON : RELAY_OFF);
      
              break;
      
          }
      
          // Write some debug info
          Serial.print("Incoming change for sensor:");
          Serial.print(message.sensor);
          Serial.print(", New status: ");
          Serial.println(message.getBool());
        }
      }
      

      this is a 3 channel relay with button.
      some time commands sent and some time could not be sent and show "Error sending switch command, check device/hardware !" I did take steps in accordance site and use a 4.7uf capacitor between vcc and gnd in radio . now some time command sent . some time could not be sent and i wait for a time (1 min , 2 min and more) and again send command and this is ok ! also when for test i sent some consecutive command (on/off/on/off/on) so again i see "Error sending switch command, check device/hardware !" i wait again and after a while work again and ok !
      I did search between topics and i see some suggest to use this module:
      link text
      so i use this but the problem did not solve for me .
      also i use a repeater between node and gateway but...
      Does anyone a proposal for my problem ?

      Best Regards S_m .

      AnticimexA Offline
      AnticimexA Offline
      Anticimex
      Contest Winner
      wrote on last edited by
      #2

      @Reza just stop creating new accounts please.

      Do you feel secure today? No? Start requiring some signatures and feel better tomorrow ;)

      R 1 Reply Last reply
      2
      • AnticimexA Anticimex

        @Reza just stop creating new accounts please.

        R Offline
        R Offline
        Reza
        wrote on last edited by
        #3

        @Anticimex
        when some people is living in a building so this is not all account are one person ! sama is my friend . i introduce mysensors to her . so he had problem and question about this with me and i told to her i dont know go and register a account or use my account ! i have just 2 account one account is this and another account is for when i lost my user pass (this ) after found i comeback to this account ....

        1 Reply Last reply
        0
        • scalzS Offline
          scalzS Offline
          scalz
          Hardware Contributor
          wrote on last edited by scalz
          #4

          @Reza
          looks funky but maybe..

          This is a problem you have already asked for..

          So the best you can do is:

          • remove your relays and connect leds instead
          • test this for few days.

          If there is no issues, it means that's on your hardware. And we can't scope it at distance. Can be a bad power supply input on your hardware (no filtering), parasites due to relay switch (better to use relay driver, tvs diode, capa for filtering) etc..
          I suggest you to read some docs on internet about this. That's the diy side, when using simple chinese relays modules.

          1 Reply Last reply
          2
          • N Offline
            N Offline
            novicit
            wrote on last edited by
            #5

            @sama, I had similar problems, always with relay nodes. The solution that has worked 100% of the time for me is to add a delay(100) as described by @kk02067 at the end of the forum thread of the same name:
            https://forum.mysensors.org/topic/4987/error-sending-switch-command-check-device-hardware
            Don't know if this will solve your problem, but worth a try.

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


            18

            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