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



  • 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.


  • Mod

    @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.



  • @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...!


  • Mod

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



  • @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 !


  • Mod

    @bonamin thanks for reporting back!


Log in to reply
 

Suggested Topics

  • 2
  • 10
  • 8
  • 2
  • 15
  • 23
  • 20
  • 1

80
Online

10.3k
Users

10.7k
Topics

109.5k
Posts