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 ONand 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?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login