Relay on when starting up



  • Hi there.
    First of all sorry for this topick as I think there already is something similar, but I just can not find one.

    The problem is that two of three of my ESP nodes starts up with a relay in ON position so lights go on as, let's say, power appears. This is starting to be problem because now winter is coming and quite often I go home from work and those two lights are (and have been for the majority of the day) ON.

    I do have this in my "setup"

       // Then set relay pins in output mode
      pinMode(RELAY_PIN, OUTPUT);
      // Make sure relays and LED are off when starting up
      digitalWrite(RELAY_PIN, RELAY_OFF);
    

    but it does not change anything. The difference from light that is not on is that those two lights have relays with turns on with LOW signal so I have this at start

    #define RELAY_ON                    0
    #define RELAY_OFF                   1
    

    The Home Assistant and openhab correctly reports ON and OFF states and all else is good.
    Thanks in advance.


  • Admin

    @archiijs can you post a picture of the wiring? My relays have two ways to connect- one keeps the circuit closed and the other open. Also, you mentioned you come home and the lights are on. Can you give more details about that?



  • @petewill said in Relay on when starting up:

    a picture of the wiring? My relays have two ways to connect- one ke

    Sorry for my long delay and thanks for your answer, seems like this should be the problem, I did not think about that.

    Right now, if I remember correctly lights are connected with relays normally closed contacts, and to be honest, I do not remember why I did that... It should be because of software before mysensors and some problems with that.

    As I get a lot of power cuts in this time of year nodes reboots often, so if this happens when I'm at work they stay at "ON" until I come home and switch them off.



  • As "setup()" (at least in most cases) requires a working network connection, you may put the "turn off"-code in a different function named "before()" or "preHwInit()" to make sure they are turned off at a very early stage of the nodes reboot.



  • Thanks for your input and this is also a valid point. I recently discovered this when I started to power some small sensors from arduinos gpio. and found that indeed Sensors stays off until the connection is made.
    I should check and implement this to all my nodes.



  • @archiijs Thanks for your feedback. Nevertheless: With your "old" code, the nodes should have turned off the relays, the change only assures it is done when there is no controller available at all and to a rather early point of the initialisation process.

    But when the relays stay on as long as you describe, there most likely exists a problem in the general layout of your MySensors network making the controller completely unreachable in case of power cutoffs.

    My personal bet on the root cause of this: This might happen due to the ESP's general codeing: Afaik they try to connect to the recent known network only for a distinct periode. If this has passed without the expected Wifi-AP beeing available (as it takes much longer for example to boot an ordinary router with integrated DSL-modem), it will open up it's own AP and thus will not reintegrate in your normal Wifi network. (I'n not sure if this also applies to the MySensors-ESP-code, but this is one of the reasons I personally dislike this mcu type).



  • @rejoe2 said in Relay on when starting up:

    he change only assures it is done when there is no controller

    Interesting thought.
    Yes, this is not the cause of the problem, but I think that it is better to move the code for turning the relay off to the beginning to improve overall experience. You know, every small change sums up.
    And my router take time to boot up



  • @archiijs You may check the available AP's in your house next time you have a power loss - if all the ESP's really open up a new one, you will never know whether you can reach all of your nodes reliably.
    You may test this possible behaviour also by compiling a copy of an existing node to a mcu using wrong Wifi registration data.



  • @rejoe2 said in Relay on when starting up:

    really open up a new one, you will never know whether you can reach all of your nodes reliably.

    Thanks for ideas, I will start to tackle them when I get some free time. Thanks all for input.


Log in to reply
 

Suggested Topics

  • 4
  • 2
  • 9
  • 2
  • 8
  • 4

13
Online

11.4k
Users

11.1k
Topics

112.7k
Posts