Nodemanager: How to control a local output from a local input?



  • I am trying to make a temperature control system that has a temperature sensor and a relay.
    I use an ESP32 and set it op as gateway. The sensor and relay are connected to the ESP32
    The sensor and relay should form a closed loop and should be able to run independently from the (Domoticz) controller.
    I want to use the Nodemanager to be able to track the temperature and relay state.
    In my first test I can read my sensor and I can switch my relay from Domoticz.
    I tried to add some code to the loop() to read the temperature locally and print it to the serial port:
    When I e.g. try to print Tsensor.getChild(0)->getValueString() it throws an error.
    My question: what is the proper way to do this?
    How can I get the sensor value and set the relay?
    Any suggestions are much appreciated



  • Reply to myself:
    Looking thought the sources and the forum found out that you can do this using hooks.
    so enabled hooking

    #define NODEMANAGER_HOOKING ON
    

    and added the reference to the hook to before.

    void before() {
     Tsensor.setMeasureTimerMode(TIME_INTERVAL);   // set timer 
     Tsensor.setMeasureTimerValue(1); // interval to 1 sec measurement
    
     Tsensor.setPostLoopHook(&myfirstHook);
     ..etc.etc...
     nodemanager.before();
    }
    

    And finally the hook

    void myfirstHook(Sensor* sensor){
      float temperature =  Tsensor.children.get(1)->getValueFloat()
      Serial.println(temperature);
      if (temperature>setpoint) { 
            if (Relay.getStatus()==OFF){
            Relay.setStatus(ON);      // switch off
            } 
      
    
    }
    

    The error that I got initially was caused by using the wrong child: 0 (it starts from 1).

    I wonder if it is possible to do interval < 1 second?


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 1
  • 4
  • 2
  • 1

54
Online

11.4k
Users

11.1k
Topics

112.7k
Posts