NodeManager Relay in Homeassistant



  • I'm trying to use NodeManager for a node that switches a realy. The problem is, that the HA MySensor component clashes with the way NodeManager handels actuators.

    NodeManager presents the relay to the GW, but never send any message with a value to the GW. However HA needs at least one initial value before the relay is recognized.
    Any idea how to deal with this? Either by forcing NodeManager to send an initial value, or by allowing HA to register the Node and its childs upon presentation and not on first value transmission?

    Here is some code of what I'm trying:

    // before
    void before() {
      // setup the serial port baud rate
      Serial.begin(MY_BAUD_RATE);  
      nodeManager.setReportIntervalSeconds(10);
    
      /*
       * Register below your sensors
      */
      id = nodeManager.registerSensor(SENSOR_RELAY, 3);
      SensorRelay* relay = (SensorRelay*)nodeManager.get(id);
      // A Method to send an intial value for the relay to the GW
     // realy->Send(false);
      /*
       * Register above your sensors
      */
      nodeManager.before();
    }
    

    Or maybe this must be done during the loop with:

    void loop() {
      // call NodeManager loop routine
      nodeManager.loop();
      SensorRelay* relay = (SensorRelay*)nodeManager.get(1);
      //relay->SendValueOnce(false);
    }
    

  • Mod

    is there a way to add a button that turns relay on or off? Or just create a mock sketch that presents the same child ids and then sends a value for each child, then restore the nodemanager sketch: not the ideal solution but I think it could work



  • @gohan hmmmm. Well problem with this is, that I will need to redo this everytime I purge the config of my MySensor network within homeassistant, and I know that will happen almost each time I add a Node, so on the long run this will be annoying.

    I found another suuuper hacky solution.

    Within the NodeManager.cpp I edited the onLoop function of the underlying SensorDigitalOutput. This is the method the SensorRelay inherits from.

    void SensorDigitalOutput::onLoop() {
      // set the value to -1 so to avoid reporting to the gateway during loop
      //_value_int = -1;
      //_last_value_int = -1;
      // if a safeguard is set, check if it is time for it
      if (_safeguard_timer->isRunning()) {
        // update the timer
        _safeguard_timer->update();
        // if the time is over, turn the output off
        if (_safeguard_timer->isOver()) setStatus(OFF);
      }
    }
    
    

    I commented out the _value_int = -1; and the _last_value_int = -1;. Now it reporst the reading once upon a node start. I guess setTrackLastValue is set to true somewhere.

    Maybe it possible to add another method to the SnesorDigitalOutput, that allows to toggle these -1 settings in the loop.


  • Mod

    Well, I did say it wasn't the best way 😁



  • @Malte-Deiseroth
    Hi any progress on this? I am looking into documentation and eventually find this thread



  • @Michał-Szura I had problems with relay and HA too. The best solution was to save the state of the relay in the EEPROM and to recall the value after a defined amount of time and send it to HA in loop(). This way you do not have to restart the relay node everytime you restart HA.


Log in to reply
 

Suggested Topics

  • 1
  • 5
  • 3
  • 5
  • 2
  • 17

59
Online

11.4k
Users

11.1k
Topics

112.7k
Posts