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
HenryWhiteH

HenryWhite

@HenryWhite
About
Posts
103
Topics
10
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • 💬 Relay
    HenryWhiteH HenryWhite

    @mfalkvidd when updating the example sketch you could maybe consider my version of the relay sketch which offers some nice additions: https://forum.mysensors.org/topic/6638/multiple-relays-motion-sketch-fully-customizable-optional-timer-manual-override

    Announcements

  • Mains voltage current sensor?
    HenryWhiteH HenryWhite

    @maghac said in Mains voltage current sensor?:

    so I can sense when they're done and alert someone to go empty them.

    If you just want to do that, you could also use a vibration sensor to determine whether the dryer/ washing machine has finished or not.

    Hardware

  • Multiple Relays + Motion sketch, fully customizable, optional timer, manual override
    HenryWhiteH HenryWhite

    @AndreD said in Multiple Relays + Motion sketch, fully customizable, optional timer, manual override:

    How to send the relay to the gateway every 30 seconds?

    Why would you need that?

    Development

  • 💬 Relay
    HenryWhiteH HenryWhite

    @Rene046 you could try my sketch: https://forum.mysensors.org/topic/6638/multiple-relays-motion-sketch-fully-customizable-optional-timer-manual-override

    Announcements

  • Sensor dht+relay won't send data or present
    HenryWhiteH HenryWhite

    @MasMat said in Sensor dht+relay won't send data or present:

    @gohan you mean "delay(500)"? Will that not affect the radio function if it is waiting for a command for the relay for example?

    That's what wait() is for (mysensors specific) , it will not interfere with the radio commumication.

    Troubleshooting

  • nRF24L01+ and without +. arduino pro micro?
    HenryWhiteH HenryWhite

    @slowbo here you can find the documentation: https://www.mysensors.org/download/sensor_api_20
    There's also a list of all available config options.

    Troubleshooting

  • Multiple Relays + Motion sketch, fully customizable, optional timer, manual override
    HenryWhiteH HenryWhite

    @markjgabb said in Multiple Relays + Motion sketch, fully customizable, optional timer, manual override:

    awesome work...this sketch is brilliant....

    what happens if you retrigger motion before timer runs out?
    will it always handle a restart of the timer correctly?

    Yes, the timer will be reset.

    Development

  • motion sensor and 2 relay code
    HenryWhiteH HenryWhite

    I finalized my sketch, you can find it here: https://forum.mysensors.org/topic/6638/multiple-relays-motion-sketch-fully-customizable-optional-timer-manual-override

    Troubleshooting

  • Multiple Relays + Motion sketch, fully customizable, optional timer, manual override
    HenryWhiteH HenryWhite

    Hi!

    I recently modified the relay example sketch so that it fits my needs; maybe some of you can make use of my little work too.

    Here's what you can do / what the features are:

    • Easily add as much Relays / FETs as you want (or as much as the arduino allows) by entering the according pin numbers in the RELAYS[ ]-Array
    • You can trigger each relay from your controller
    • You can add a motion sensor and specify which (MOTION_ACTIVATED_RELAYS[ ]) of your relays should be triggered through motion and for how long (ON_TIMES[ ])
    • The state of the motion sensor will be reported to your controller
    • When a relay is changed through motion, the change will also be reported to your controller
    • You can send a manual override from your controller, so that the motion will still be reported, but none of the relays will be triggered through motion
    /**
       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
       Version 1.1 - HenryWhite
    
       DESCRIPTION
       Example sketch showing how to control physical relays.
       This example will remember relay state after power failure.
       Optional attachment of motion sensor to control the relays is possible.
       Notes:
          -- The Child-IDs of the attached relays range from 1 up to (1-(NUMBER_OF_RELAYS))
          -- Make sure to adjust the potentiometer for triggertime on your motion sensor as leftmost as possible,
             because the countdown will not start until the motion sensor reports back a "0" (no movement)
    
    */
    
    //----------------------- Library Configuration ---------------------
    //#define MY_DEBUG                          // uncomment to enable debug prints to serial monitor
    //#define MY_REPEATER_FEATURE               // uncomment to enable repeater functionality for this node
    //#define MY_NODE_ID 20                     // uncomment to define static node ID
    
    // Enable and uncomment attached radio type
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    //#define MY_TRANSPORT_WAIT_READY_MS 1      // uncomment this to enter the loop() and setup()-function even when the node cannot be registered to gw
    
    //----------------------- Relay and Motion Sensor Configuration -----------------------
    #define MOTION                                                    // un-comment to enable motion sensing
    #define NUMBER_OF_RELAYS  2                                       // Total number of attached relays. Must be equal to total number of elements in array below!
    const int RELAYS[]                  =     {3,  5};                // digital pins of attached relays
    const int MOTION_ACTIVATED_RELAYS[] =     {1,  0};                // 1 to trigger the relay through motion, 0 to not trigger. Array length must correspond to RELAYS[] array.
    const long ON_TIMES[]               =     {300, 0};               // Specify for each element in MOTION_ACTIVATED_RELAYS, how long the specified relay should be active in seconds.
    #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
    #define MOTION_PIN        2                                       // The digital input pin of the motion sensor
    #define MOTION_CHILD_ID   0                                       // Set the child id of the motion sensor
    bool ack = 1;                                                     // set this to 1 if you want destination node to send ack back to this node
    
    //----------------------- DO NOT CHANGE -----------------------------
    #include <MySensors.h>
    MyMessage motion_msg(MOTION_CHILD_ID, V_TRIPPED);   // Initialize motion message
    unsigned long trigger_millis[NUMBER_OF_RELAYS];     // Used for the timer
    bool lastTripped = 0;                               // Used to store last motion sensor value
    bool manual_override = 0;                           // if this gets set to 1 (e.g. by a switch or a command from the gateway), motion triggering of relays is deactivated
    MyMessage relay_msg;                                // Initialize relay message
    
    void before()
    {
      int i;
      for (int sensor = 1, i = 0; sensor <= NUMBER_OF_RELAYS; sensor++, i++) {
        // set relay pins to output mode
        pinMode(RELAYS[i], OUTPUT);
        // Restore relay to last known state (using eeprom storage)
        digitalWrite(RELAYS[i], loadState(sensor) ? RELAY_ON : RELAY_OFF);
      }
      // set motion pin to output mode, if MOTION is defined
    #ifdef MOTION
      pinMode(MOTION_PIN, INPUT);
    #endif
    }
    
    void setup()
    {
    #ifdef MOTION
      // give the motion sensor some time to settle
      Serial.println("Starting up. Please wait 8 seconds...");
      delay(8000);
    #endif
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay/Motion", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      for (int sensor = 1; sensor <= NUMBER_OF_RELAYS; sensor++) {
        present(sensor, S_BINARY, "Relay", ack);
      }
    #ifdef MOTION
      present(MOTION_CHILD_ID, S_MOTION, "Motion Sensor", ack);
    #endif
    
    }
    
    void loop()
    {
    #ifdef MOTION
      if (!manual_override) {
        // Read digital motion value
        bool tripped = digitalRead(MOTION_PIN) == HIGH;
    
        if (lastTripped != tripped) {
          Serial.print("New Motion State: ");
          Serial.println(tripped);
          // Send tripped value to gw
          send(motion_msg.set(tripped ? "1" : "0"));
          lastTripped = tripped;
    
          // Change relay states, send new state to gw and store state in eeprom
          if (tripped == 1) {
            for (int i = 0; i < NUMBER_OF_RELAYS; i++) {
              if (MOTION_ACTIVATED_RELAYS[i] == 1) {
                digitalWrite(RELAYS[i], RELAY_ON);
                relay_msg_constructor(i + 1, V_STATUS);
                send(relay_msg.set(RELAY_ON));
                trigger_millis[i] = millis();
                Serial.print("Relay ");
                Serial.print(RELAYS[i]);
                Serial.println(" turned on");
                saveState(i, 1);
              }
            }
          }
        }
    
        for (int i = 0; i < NUMBER_OF_RELAYS; i++) {
          if (tripped == 1 and MOTION_ACTIVATED_RELAYS[i] == 1 and trigger_millis[i] != 0) {
            trigger_millis[i] = millis();
          }
          if ((trigger_millis[i] + ON_TIMES[i] * 1000 < millis()) and MOTION_ACTIVATED_RELAYS[i] == 1 and trigger_millis[i] != 0) {
            digitalWrite(RELAYS[i], RELAY_OFF);
            relay_msg_constructor(i + 1, V_STATUS);
            send(relay_msg.set(RELAY_OFF));
            Serial.print("Relay ");
            Serial.print(RELAYS[i]);
            Serial.println(" turned off");
            saveState(i, 0);
            trigger_millis[i] = 0;
          }
        }
      }
      else {
        bool tripped = digitalRead(MOTION_PIN) == HIGH;
        if (lastTripped != tripped) {
          Serial.print("New Motion State: ");
          Serial.println(tripped);
          // Send tripped value to gw
          send(motion_msg.set(tripped ? "1" : "0"));
          lastTripped = tripped;
        }
        for (int i = 0; i < NUMBER_OF_RELAYS; i++) {
          if (MOTION_ACTIVATED_RELAYS[i] == 1 and trigger_millis[i] != 0) {
            trigger_millis[i] = 0;                            // reset running timers
          }
        }
      }
    #endif
    }
    
    void receive(const MyMessage &message)
    {
      // Handle incoming relay commands
      if (message.type == V_STATUS) {
        // Change relay state
        if (RELAYS[message.sensor - 1]) {
          digitalWrite(RELAYS[message.sensor - 1], message.getBool() ? RELAY_ON : RELAY_OFF);
    
          // Store state in eeprom
          saveState(message.sensor - 1, message.getBool());
          // Write some debug info
          Serial.print("Incoming change for sensor:");
          Serial.print(message.sensor);
          Serial.print(", New status: ");
          Serial.println(message.getBool());
        }
      }
    
      // Handle incoming manual override/bypass of motion sensor
      if (message.type == V_ARMED and message.sensor == 0) {
        manual_override = message.getBool();
        Serial.print("Manual Override: ");
        Serial.println(manual_override);
      }
    }
    
    void relay_msg_constructor(int sensor, uint8_t type)
    {
      relay_msg.setSensor(sensor);
      relay_msg.setType(type);
    }
    

    Additional Notes:

    • The Child-IDs of the attached relays range from 1 up to (1-(NUMBER_OF_RELAYS))
    • The default Child-ID for the motion sensor is 0
    • Make sure to adjust the potentiometer for triggertime on your motion sensor as leftmost as possible, because the countdown-timer will not start until the motion sensor reports back a "0" (no movement)
    Development

  • motion sensor and 2 relay code
    HenryWhiteH HenryWhite

    @gohan said in motion sensor and 2 relay code:

    Just remove the FOR cycle in the loop function

    It's much easier than that: Just set NUMBER_OF_MOTION_RELAYS to 0

    Troubleshooting

  • motion sensor and 2 relay code
    HenryWhiteH HenryWhite

    This is my sketch for relays + motion sensor:

    You can specify everything in the "#define"-section of the code.
    Features:

    • multiple Relays
    • optional motion sensor
    • specify which relays should be triggered through the motion sensor
    • child ID of the motion sensor: 0
    • The Child-IDs of the attached relays range from 1 up to (1-(NUMBER_OF_RELAYS))

    A few things are missing at the moment (e.g. report the state of the motion-activated relays to the controller), but it should work out of the box.

    /**
       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
       Version 1.1 - HenryWhite
    
       DESCRIPTION
       Example sketch showing how to control physical relays.
       This example will remember relay state after power failure.
       Optional attachment of motion sensor to control the relays is possible.
       Note: The Child-IDs of the attached relays range from 1 up to (1-(NUMBER_OF_RELAYS))
    */
    
    //----------------------- Library Configuration ---------------------
    #define MY_DEBUG                          // uncomment to enable debug prints to serial monitor
    //#define MY_REPEATER_FEATURE               // uncomment to enable repeater functionality for this node
    //#define MY_NODE_ID 20                       // uncomment to define static node ID
    
    // Enable and uncomment attached radio type
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    //#define MY_TRANSPORT_WAIT_READY_MS 1      // uncomment this to enter the loop() and setup()-function even when the node cannot be registered to gw
    
    //----------------------- Relay Configuration -----------------------
    const int RELAYS[] = {6, 3, 5};             // digital pins of attached relays
    #define NUMBER_OF_RELAYS 3                  // 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
    
    //----------------------- Motion Sensor Configuration ---------------
    #define MOTION                              // un-comment to enable motion sensing
    #define MOTION_PIN 2                        // The digital input pin of the motion sensor
    const int MOTION_RELAY_PINS[] = {5};        // The digital input pins of the relays, which should be triggered through motion
    #define NUMBER_OF_MOTION_RELAYS 1           // Total number of relays, which should be triggered through motion
    #define MOTION_CHILD_ID 0                   // Set the child id of the motion sensor
    
    //----------------------- DO NOT CHANGE -----------------------------
    #include <MySensors.h>
    MyMessage msg(MOTION_CHILD_ID, V_TRIPPED);  // Initialize motion message
    bool lastTripped = 0;
    
    
    void before()
    {
      int i;
      for (int sensor = 1, i = 0; sensor <= NUMBER_OF_RELAYS; sensor++, i++) {
        // set relay pins to output mode
        pinMode(RELAYS[i], OUTPUT);
        // Restore relay to last known state (using eeprom storage)
        digitalWrite(RELAYS[i], loadState(sensor) ? RELAY_ON : RELAY_OFF);
      }
      // set motion pin to output mode, if MOTION is defined
    #ifdef MOTION
      pinMode(MOTION_PIN, INPUT);
    #endif
    }
    
    void setup()
    {
      
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Relay/Motion", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      for (int sensor = 1; sensor <= NUMBER_OF_RELAYS; sensor++) {
        present(sensor, S_BINARY);
      }
    #ifdef MOTION
      present(MOTION_CHILD_ID, S_MOTION);
    #endif
    
    }
    
    
    void loop()
    {
    #ifdef MOTION
      // Read digital motion value
      bool tripped = digitalRead(MOTION_PIN) == HIGH;
      
      if (lastTripped != tripped) {
        Serial.print("New Motion State: ");
        Serial.println(tripped);
        // Change relay states and store state in eeprom
        for (int i = 0; i < NUMBER_OF_MOTION_RELAYS; i++) {
          digitalWrite(MOTION_RELAY_PINS[i], tripped ? RELAY_ON : RELAY_OFF);
          saveState(i, tripped);
        }
        // Send tripped value to gw
        send(msg.set(tripped ? "1" : "0"));
        lastTripped = tripped;
      }
    #endif
    }
    
    void receive(const MyMessage &message)
    {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type == V_STATUS) {
        // Change relay state
        digitalWrite(RELAYS[message.sensor - 1], message.getBool() ? RELAY_ON : RELAY_OFF);
        // Store state in eeprom
        saveState(message.sensor - 1, message.getBool());
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    }
    
    Troubleshooting

  • [SOLVED] No Serial prints for loop(), using MySensors 2.1.1
    HenryWhiteH HenryWhite

    @korttoma thanks! It works now. :)
    Could have saved me hours of troubleshooting if I knew that prior :/

    Troubleshooting

  • [SOLVED] No Serial prints for loop(), using MySensors 2.1.1
    HenryWhiteH HenryWhite

    I found the problem, but not the solution.

    First, I added #define MY_TRANSPORT_WAIT_READY_MS 1 to the sketch.
    Now the loop()-Function gets executed.
    Problem: My node isn't registered by the gateway:

    New Motion State: 1
    80949 !MCO:SND:NODE NOT REG
    81582 TSF:MSG:READ,0-0-20,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    81588 TSF:MSG:FPAR OK,ID=0,D=1
    82950 TSM:FPAR:OK
    82952 TSM:ID
    82952 TSM:ID:OK
    82954 TSM:UPL
    82958 TSF:MSG:SEND,20-20-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    84967 TSM:UPL
    84969 TSF:MSG:SEND,20-20-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 
    

    :arrow_right: My Gateway is running on an old version of MySensors, I believe it's 1.5.4
    Do I have to update the gateway? I thought I could leave it at 1.5.4.

    Troubleshooting

  • [SOLVED] No Serial prints for loop(), using MySensors 2.1.1
    HenryWhiteH HenryWhite

    Hi,

    I'm getting all the debug messages if I define #MY_DEBUG, but none of my Serial prints in the loop functions are shown.
    However, Serial prints in the receive function are shown.

    Example sketch:

    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    #define MY_NODE_ID 20
    
    #include <MySensors.h>
    
    #define RELAY_1  5  // 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 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    
    void before()
    {
    	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);
    	}
    }
    
    void setup()
    {
    
    }
    
    void presentation()
    {
    	// Send the sketch version information to the gateway and Controller
    	sendSketchInfo("Relay", "1.0");
    
    	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_BINARY);
    	}
    }
    
    
    void loop()
    {
      Serial.println("This doesn't print :(");
      delay(1000);
      
    }
    
    void receive(const MyMessage &message)
    {
    	// We only expect one type of message from controller. But we better check anyway.
    	if (message.type==V_STATUS) {
    		Serial.println("This does print!");
    	}
    }
    

    It would be really nice if someone could help me with this problem.

    Troubleshooting

  • Shielded nRF24 - better Range?
    HenryWhiteH HenryWhite

    @Igor-Antolić said in Shielded nRF24 - better Range?:

    @HenryWhite That is nice to hear that you ordered 2 items, however now I am confused because you said before that you thik aboit "E01-ML01DP5 Ebyte 20dBm 2100m SPI NRF24L01+PA+LNA", not these red ones (without PA and without external antenna).

    the red ones are intended for the nodes, I'm still thinking of getting the item in my first post for my gateway.

    Hardware

  • Shielded nRF24 - better Range?
    HenryWhiteH HenryWhite

    @xlibor I just ordered 2 of them, will report back if they solved my range problem ;)

    Hardware

  • 💬 Window Sensor with Sensebender (high WAF)
    HenryWhiteH HenryWhite

    Nice idea!
    You can get the window alarm even cheaper: https://www.aliexpress.com/item/Wireless-Small-Independent-Door-Alarm-Sensors-Protection-Door-Window-Magnetic-Burglar-Alarm-Systems-Security-Device-Home/32785764947.html?spm=2114.13010608.0.0.HStmEr

    OpenHardware.io door window mysensors waf nrf24l01

  • Shielded nRF24 - better Range?
    HenryWhiteH HenryWhite

    Hi!

    I have significant range problems within my apartment (thick walls I think). I'm currently using the PA+LNA version (wrapped in aluminium foil) as gateway and the standard nRF's as senders/receivers.

    However, I just stumbled upon these modules, which are shielded by design: https://www.aliexpress.com/item/1-piece-Long-Range-E01-ML01DP5-Ebyte-20dBm-2100m-SPI-NRF24L01-PA-LNA-2-4GHz-RF/32756789147.html?spm=2114.13010208.99999999.262.GYIB1G

    The question is: When I swap my current PA+LNA gateway with one of these shielded modules, can there be an improvement in the range to the other modules?

    Hardware

  • Do repeater nodes increase message delay?
    HenryWhiteH HenryWhite

    *push *

    Troubleshooting

  • Do repeater nodes increase message delay?
    HenryWhiteH HenryWhite

    Hi!

    although my apartment is not that big, I need at least 2 repeater nodes to cover every room. However, when I use the repeater nodes, everything is delayed 1-2 seconds.

    For example: I have multiple motion detectors - the ones which are connected to the gateway over a repeater take 1-2 seconds longer until their "triggered"-message reaches the gateway.

    Is this normal?
    How can I reduce this delay?

    I'm using Arduino Pro Minis (5V) for my repeaters. Nothing else runs on them.

    Troubleshooting
  • Login

  • Don't have an account? Register

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