Posted these question on several forum's, and decided to post it here too...
I am building a pump system, and everything is done in Node-Red . So i have calculated time for which i want to run the pump for( to output desired liquid amount). So i decided to send the delay to the esp32 (because i have +20 pumps and the mqtt protocol can't gets delayed and it is not reliable for this type of task) but i can't figure out how to call the delay with the received message inside on_message ... Does anyone have an idea?
Administrators if you think this post is off topic, and not for this forum, please delete it.
So hang on - explain a little more - are you going to have 20 separate systems that will be running 20 different pumps with variable times ?
What is the interface that you will be using to pass the delay time for each system ??
What have you configured device wise in ESPHome ?
I use ESPHome but have not really looked at the code to see if there is something like a countdown system - not really sure it is going to be the best solution overall
I have one esp32 configured and connected to my mqtt broker, and connected 20 relays to it.
So far i added the switch option with name and id and pin number for each pump(pump1,pump2...) (When using MQTT with command topics from Iog the relays are switching perfect on/off) plan to use MQTT to send the interval from my node-red to every pump topic command so for example:
Topic:pump_system/pump1
Payload: 5000 (ms)
The esp itself should turn on the relay, wait for X time(in this case 5000) and then switch off.
I am at my job and can't access the HA to send the code...
Based on the documentation it looks like you could be able to do this with a lambda function triggered on MQTT message receive. See the examples at this section https://esphome.io/components/mqtt.html#on-message-trigger and the on_json_message example that follows it.
Well i tried in the browser... let me check with the pip package...
Still the same error:
ā[32mINFO Reading configuration...ā[0m
ā[31mERROR Error while reading config: mapping values are not allowed here
in "esphome.yml", line 28, column 11ā[0m
I will give up on MQTT , and go with the ESP-HOME API , and try to delay it on the node-red side, if not then i am better off using Arduino IDE to program it (had at least some experience in the past with it) and i think i will find more documentation for it...
One more idea. Did you try with only a one line lambda (if the issue is with the multiline ones)? Maybe you could use a global variable for the delay, update it from a separate topic and then use the variable within the normal switch trigger (from another MQTT topic).
TBH I have no idea if the global variable can be used like this but somehow the automation template / lambda system seemed very versatile.
Well passed to use the rest api for the node-red to HA communication. Its really fast , the ping is about 5ms and its working okay i belive. Have to finish this project but if i ever stumble upon this one more time I would have to do it the right way