Thanks for the link to the Lambda Magic. I’m aware of Lambda, but I had not seen that site. I’m quite new to create my own ESPHome code.
Yes, UART was my first thought too, but I wanted to ask an open question in case there is some clever function I don’t know about. ESPome have all kind of weird & wonderful things already built in!
But with UART it’s easy to add a RS232 level shifter circuit like MAX232 on each side to add some more robustness to the signal and avoid exposing the ESP32 I/O directly to the environment.
For “error correction” it will probably be enough here to go at low speed and just send the data maybe three times and only accept it if all three are the same.
A simple “protocol” maybe can be something like:
Send all data three times in one stream
Wait for the other node to respond with the same data to confirm
If the responded data is wrong, resend the correct data again
Stop retrying and rise an alarm if the respond is wrong five times in a row
Anyone that has done something similar and is willing to share some code?
Did you look into just having one esp and say long wire runs to the greenhouse sensors from the pump one? Not sure how feasible that is and guessing you’ve thought about it but curious if/how that was knocked out.
To be honest, I’d put wireless and long-wires-in-a-wet-environment on the same level as far as expected reliability… To improve wireless reliability, I’d just put a cheapo dedicated router for that purpose.
Keep in mind that pure wired also implies hardwiring a way to upload firmware updates, no logging, … (unless you keep wireless for “non-essential” functions like this).
One ESP is of course the easiest way and something I have considered, but it will have some drawbacks in my opinion.
As I will have sensors in both the greenhouse (temp, moister, light humidity…) and in the pump (water level, critical low level, leakage…) I’m facing similar problems with long sensor cables regardless where I place the ESP.
One ESP will make it harder to add more sensors at the “wrong” place later on as more cables likely has to be installed.
As the functions of the systems are very different (pump control vs evaluating environment sensors) I think it can be easier to develop, test, and maintenance if it is separate systems.
My experience is that a proper installed hardwired connection hardly never can beat wireless. Well ok, maybe hardwire isn’t the best chose for space flights then…
However, as it looks like there is no easy “of the shelf” solution to handle hardwired signals between two ESPHome I’m starting to thinking on a plan B for wireless, at least to start with:
Problem 1: Flooding
The biggest fear is that the stop/shut off command not will be received and causing a flooded greenhouse.
Solution 1: Hart beat
This can probably be handled in a way where the “pump ESP” only open the water valve for a short time. That means the “greenhouse ESP” must resend that trigger as long it’s requesting for more water. This will acting like a hart beat / watchdog and stop the water if the signal for some reason is lost.
Problem 2: Drying / HA down
I will have the automations local in the ESP not being dependent of Home Assistant running.
Is it possible for two ESPHome nodes to communicate and trig the water “hart beat” if HA is down but wifi is up?
That web server solution looks interesting, but I’m afraid that may me a little over my head to master, at least for the moment.
Thinking this over a little more during some grass cutting the last hours I may have a solution that hopefully will be both quite easy and reliably enough for my needs:
Two ESP as discussed above, one for the pump and one for the greenhouse.
Connect the two ESP trough UART and MAX232 level shifters.
Use the UART Switch and Lambda Magic Custom UART Switch to send and receive the “valve open hart beat signal” witch will open the water valve for a short time, and close it again if a new hart beat is not received.
More signals should be possible add through UART the same way if needed, and the text sensor is probably reliable and fault tolerant enough for this purpose as the received string is a couple of bytes that must mach exactly to flip the switch.
All other kind of “non critical / for fun” signals can be handeld wireless.
For now I think this will be the way I go, at least to start with.
Any obvious thought errors?
I’m not that deep into this new fancy web rubbish. I’ll stick to an good old trusted UART, like I used to in the -90s!
Well to be honest, it feels like a web server is a little to much and komplex for my needs, but I can be wrong. Could be worth to have a look at.
However, I will start with the UART trace as that (hopefully) will give me a system with both robustness and some flexibility where the core functions are working regardless of wifi, HA or any other surrounding systems, as long as I have 230VAC power.
You are absolutely right about that the level shifters are not needed from a signal level aspect, but it is not wise, and not a common praxis, to expose the “naked” I/Os to the world. Especially if the wires are long, like they will be in my case, the risk is quite high that the sensitive, high impedance 3,3V inputs will pick up some noise that can interfere or block the signal, or worse be destroyed by some electro static discharge (ESD).
Those risks can be reduced by using the MAX232 level shifter as they will boost the signal several volts (to RS232 level) and bring some basic ESD protection to it as well.
Not needed in theory or on the bench, but probably nearly a “must have” in the real world.
Nope, not at all.
But until I know better I believe that the Magic Lambda Custom UART Switch example will do pretty much what I want - I hope!
As long as the interrupt pick up the receiving message and i don’t overflow the input buffer, I think it will be pretty straight forward.
We’ll find out…
I think I´m on something here that can have the potential to work.
This is what I have done:
The “Custom UART Text Sensor” example is taken stight off from Lambda Magic
I replaced the “Custom UART Switch” with a own variant of a binary sensor, using the “delayed_off” for the heartbeat.function.
The function is:
If the right string is recievd by the UART the output will turn on for 5s and then turn off
If the right string is recievd again within 5s the output will remain on
The flag “b_prohibit” allows the output to only be set once and clears the “uart_readline” textsensor, forcing a new string to be recieved to keep the output enabled.
If the string is sent once per second it can lose up to 4 of 5 strings and still work, and will stop within 5s if the string is stuck or lost.
The if statement “if (id(uart_readline).state == “OPEN_VALVE_1”)” can be extended with an or statement ( || ) to allow different triggers if needed.
I’m using "uart.write: “Water ON” and “OFF” for testing so far instead of digital outputs.
I have just tested this a little on the bench, but so far it looks good!