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?
Suggested Topics
-
Sensors db
My Project • 16 Apr 2014, 07:06 • Dvbit 16 Apr 2014, 17:37 -
Battery Level
NodeManager • 7 Aug 2022, 21:11 • bbastos 7 Aug 2022, 21:11 -
DS18B20 ESP32 nodemanager problem
NodeManager • 13 Sept 2022, 10:59 • A3V 15 Sept 2022, 22:11 -
Compilation error
NodeManager • 19 Sept 2020, 15:41 • htaxil 18 Oct 2020, 09:37 -
Help needed with connecting MySensors node to Home Assistant
NodeManager • 2 Apr 2023, 10:43 • vivek101 2 Apr 2023, 21:21 -
Nrf5x on NodeManager
NodeManager • 9 Apr 2019, 14:26 • nullos 6 Nov 2020, 09:28