ESPHOME yaml: How could i pass an int received by mqtt.payload to use as a delay time

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

Craig

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.

But never mind that, even when i paste the sample from the link i get the following error...

I haven't played around with ESPHome much at all but did you try if it still compiles? Maybe the configuration syntax is not 100% valid YAML?

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

Strange. Maybe they've got a documentation bug then.

If you look at line 41 the syntax highlighting breaks. Try changing the outer "'s to single quotes?

Still the same error...

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...

At least it'll be a lot more flexible.

1 Like

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 :grin:

1 Like

I am really not sure how can i program that. I really dont have experience with it , and too busy to learn the esphomeyaml...

Yep, aren't we all. :slightly_smiling_face:

I still don't quite understand why do you consider MQTT less reliable than a REST API (if QoS is just properly set)?

Mostly latency between the hassio and esp32

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.