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. [SOLVED] Relay Sketch doesn't work every single time !

[SOLVED] Relay Sketch doesn't work every single time !

Scheduled Pinned Locked Moved Troubleshooting
6 Posts 2 Posters 65 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.
  • B Offline
    B Offline
    bonamin
    wrote on last edited by Yveaux
    #1

    Hello. I'm new here. Hope you are all doing fine !

    Intro to my problem:
    I found out about MySensors yesterday, and being as cool as it is, I tried to make my own MySensor devices. After some help from this forum and posts from other people I finally made my first "working" node. I actually tried making two.
    A Motion Sensor, and a Relay Control. As it seems nice to be able to control lights when motion is detected.
    I followed the instructions (and sketches) I found here: https://www.mysensors.org/build/motion
    and here: https://www.mysensors.org/build/relay

    My Setup:
    I'm using an Arduino Pro Mini for the nodes and a NodeMCU as the Gateway. The NRF24 is my choice of wireless communication.
    I am controlling everything through Home Assistant, although I am pretty new to that as well. Just installed it yesterday and I'm currently experimenting.

    Where I am so far:
    I am currently able to make both the Gateway, and the Nodes.
    I got them to work with Home Assistant but the Relay node seems to be behaving strangely.

    The Problem:
    While I see the Relay in Home Assistant, when I press it nothing happens. If I click it a couple of times, after the second-maybe third try, it will eventually turn on.
    If I try to turn it off, the same exact thing happens. I have to click it several times in order for it to work.

    If I spam-click it, it works again in a couple of clicks.

    The Motion Sensor node I made, seems to be activated INSTANTLY when actual motion happens in front of it. Instantly, and every single time. It does take a couple more seconds after motion stops to display "Motion Off" but when Motion happens its instant.

    My Relay node on the other hand doesn't work properly.
    Could you help me ? Thanks a lot in advance.

    The Code I'm using:
    I'm not going to post the code I'm using, as it's 100% copy-pasted from the sketches on the links above. I've changed Nothing, and tried nothing fancy.
    Just trying to get them to work first.

    Something I've noticed:
    Every SINGLE time I try to toggle the Relay from Home Assistant, I see a line in the Serial Monitor of the Gateway that looks something like this:

    !TSF:MSG:SEND,0-0-1-1,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=NACK:1
    

    So from what I can tell, something IS happening in the Gateway, but the message doesn't always reach the Node ? Or, well, I don't know.

    PS. If I made any mistakes excuse my English. It's not my native language.
    If I made and technical mistakes, excuse my lack of knowledge, I'm still learning.

    YveauxY 1 Reply Last reply
    0
    • B bonamin

      Hello. I'm new here. Hope you are all doing fine !

      Intro to my problem:
      I found out about MySensors yesterday, and being as cool as it is, I tried to make my own MySensor devices. After some help from this forum and posts from other people I finally made my first "working" node. I actually tried making two.
      A Motion Sensor, and a Relay Control. As it seems nice to be able to control lights when motion is detected.
      I followed the instructions (and sketches) I found here: https://www.mysensors.org/build/motion
      and here: https://www.mysensors.org/build/relay

      My Setup:
      I'm using an Arduino Pro Mini for the nodes and a NodeMCU as the Gateway. The NRF24 is my choice of wireless communication.
      I am controlling everything through Home Assistant, although I am pretty new to that as well. Just installed it yesterday and I'm currently experimenting.

      Where I am so far:
      I am currently able to make both the Gateway, and the Nodes.
      I got them to work with Home Assistant but the Relay node seems to be behaving strangely.

      The Problem:
      While I see the Relay in Home Assistant, when I press it nothing happens. If I click it a couple of times, after the second-maybe third try, it will eventually turn on.
      If I try to turn it off, the same exact thing happens. I have to click it several times in order for it to work.

      If I spam-click it, it works again in a couple of clicks.

      The Motion Sensor node I made, seems to be activated INSTANTLY when actual motion happens in front of it. Instantly, and every single time. It does take a couple more seconds after motion stops to display "Motion Off" but when Motion happens its instant.

      My Relay node on the other hand doesn't work properly.
      Could you help me ? Thanks a lot in advance.

      The Code I'm using:
      I'm not going to post the code I'm using, as it's 100% copy-pasted from the sketches on the links above. I've changed Nothing, and tried nothing fancy.
      Just trying to get them to work first.

      Something I've noticed:
      Every SINGLE time I try to toggle the Relay from Home Assistant, I see a line in the Serial Monitor of the Gateway that looks something like this:

      !TSF:MSG:SEND,0-0-1-1,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=NACK:1
      

      So from what I can tell, something IS happening in the Gateway, but the message doesn't always reach the Node ? Or, well, I don't know.

      PS. If I made any mistakes excuse my English. It's not my native language.
      If I made and technical mistakes, excuse my lack of knowledge, I'm still learning.

      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #2

      @bonamin the failure to send a message, as seen from the logs, is probably the reason that often the relay does not respond.
      This unfortunately is also the hardest to solve, as it can have many causes.
      E.g. The power supply to your nrf24 radios may be noisy. Try a different supply and add capacitors.
      The radios may be of bad quality. Exchange the radios.
      The radios might be too close or too far apart, or obstacles inbetween severely reduce range.
      Etc.

      http://yveaux.blogspot.nl

      B 1 Reply Last reply
      1
      • YveauxY Yveaux

        @bonamin the failure to send a message, as seen from the logs, is probably the reason that often the relay does not respond.
        This unfortunately is also the hardest to solve, as it can have many causes.
        E.g. The power supply to your nrf24 radios may be noisy. Try a different supply and add capacitors.
        The radios may be of bad quality. Exchange the radios.
        The radios might be too close or too far apart, or obstacles inbetween severely reduce range.
        Etc.

        B Offline
        B Offline
        bonamin
        wrote on last edited by
        #3

        @Yveaux Oh I see !!! I didn't know so many things can play a role.

        Well, I am using a couple of breadboards onto which I mounted the microcontrollers and the radios. So maybe something isn't properly connected.

        For the radios I use an NRF24 "adapter" that already has a voltage regulator and some capacitors onboard. So I did not add my own capacitors to be honest.

        But I do power everything from my laptop's USB port, and the two devices (node and gateway) sit very close to each other. Actually one on each side of the laptop.

        I'm gonna try powering each from a dedicated power supply, and I'll also try some space between them. I will also try different NRFs as I have a bunch. I bought 10 of them I think.

        I will post my findings here. Thank you for your reply sir...!

        YveauxY 1 Reply Last reply
        1
        • B bonamin

          @Yveaux Oh I see !!! I didn't know so many things can play a role.

          Well, I am using a couple of breadboards onto which I mounted the microcontrollers and the radios. So maybe something isn't properly connected.

          For the radios I use an NRF24 "adapter" that already has a voltage regulator and some capacitors onboard. So I did not add my own capacitors to be honest.

          But I do power everything from my laptop's USB port, and the two devices (node and gateway) sit very close to each other. Actually one on each side of the laptop.

          I'm gonna try powering each from a dedicated power supply, and I'll also try some space between them. I will also try different NRFs as I have a bunch. I bought 10 of them I think.

          I will post my findings here. Thank you for your reply sir...!

          YveauxY Offline
          YveauxY Offline
          Yveaux
          Mod
          wrote on last edited by
          #4

          @bonamin start with a few meters between the nodes and free sight (no walls). Quick test and could make a difference.

          http://yveaux.blogspot.nl

          B 1 Reply Last reply
          0
          • YveauxY Yveaux

            @bonamin start with a few meters between the nodes and free sight (no walls). Quick test and could make a difference.

            B Offline
            B Offline
            bonamin
            wrote on last edited by
            #5

            @Yveaux hello again !

            After your advice I tried changing a couple of things around, and it seems that the issue was power as you suggested !

            The NRFs worked great, the code was running fine as well, but it seems that something wasn't powered properly. I guess that's what happens during prototyping.

            Now it seems to be working fine and without lag !!!

            My next step is to test with multiple sensors connected and possibly try to alter some code to make a multi-purpose sensor if that's possible !

            Thank you for your help and your advice. I appreciate it !
            Have a nice day !

            YveauxY 1 Reply Last reply
            0
            • B bonamin

              @Yveaux hello again !

              After your advice I tried changing a couple of things around, and it seems that the issue was power as you suggested !

              The NRFs worked great, the code was running fine as well, but it seems that something wasn't powered properly. I guess that's what happens during prototyping.

              Now it seems to be working fine and without lag !!!

              My next step is to test with multiple sensors connected and possibly try to alter some code to make a multi-purpose sensor if that's possible !

              Thank you for your help and your advice. I appreciate it !
              Have a nice day !

              YveauxY Offline
              YveauxY Offline
              Yveaux
              Mod
              wrote on last edited by
              #6

              @bonamin thanks for reporting back!

              http://yveaux.blogspot.nl

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


              12

              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