ESPHOMELIB mqtt question

Good afternoon all,

Starting to play around with esphomelib i am trying to build a sprinkler controller with it. so far for a simple turn on and turn off i have one relay working, just need to duplicate code to get the rest working.

What i am trying to figure out a way that i can pass the amount of time i want the realy to stay one using mqtt. say one day i want it to trigger for 15 mins but the next only 10 min. rather then hard coding with a set time or relying on home assistant to control the relay directly. I can see this being a benefit in the fact that if homeassistant or something goes wrong i have a lesser chance of the water staying on till i find it.

Yes i could code the entire thing my self but i am trying out this new library, so ya.

Anyone have any ideas? Thanks!

Your best be would be to pass the time to the ESP with MQTT subscribe:

Write an automation in HA to publish an input_number’s value to the topic (retained) when the input number is changed.

I’m a little fuzzy on how you would use this data as I haven’t used templates (lambda) in ESPhome yet. Seems to be pretty similar to the way it is done in HA:

EDIT: also that’s a good idea about making it as independent from HA as possible.

Thank you, i think that is what i am looking for. If i use a global variable and use mqtt to change that and then call that global variable to set the delay. If i was just coding it using c++ it would be pretty straight forward. Trying to wrap my head around this. Also going to have to figure out to do this with out delay, I guess what i need to do is figure out how to bury some c++ code inside…as i don’t want it to hang while it is waiting for 15 mins for a zone to go off.

As for making it independent, that is my main goal of everything. I want every unit to operate as independent as possible if anything is going wrong. This is the main reason that i switched from tasmota to espurna, i didn’t like how tasmota would lock up if the unit lost wifi. ESPHOMELIB looks interesting so i figured i would give it a shot as i was building the sprinkler controller anyways figured it would be a good platform to test it out before i tried it on anything else.

Interesting, if anyone runs across it but i just realized that delay in esphomelib is not a true c++ delay, well that’s what they say anyways, i will test it to night but they claim it to be a ““smart” asynchronous delay”. So we will see…

OK, in need of some help, any idea how to pass time, well nicer time…

I am using a global variable then using the following to return that variable to to control the delay. the problem is i seem to be setting the time in ms… ok i am not really sure what i am actually setting the time in is my first problem.

  - delay: !lambda |-
     return id(zone_run_time);

I have two ideas to fix this A: do math on the variable inside the function so i could set the variable in min but it would be converted in the function, but i need to know what unit of measure it defaults to when is doesn’t have a descriptor , or B: is there a way that i can add “min” to the end of the variable?

Thanks, hope that makes sense kinda tired

Maybe you should’ve posted in the esphomelib section so the main dev sees this thread. I haven’t ever opened a thread can you change it if you edit your opening post to edit the category?

thanks for pointing that out didn’t realize that there was a sub category, fixed it