Hello all.
I am a newb and just starting to play around with Homeassistant/ESPhome. I have a very simple application that I would like to design and am looking for some advice. Here is what I would like to do:
Wemos D1 mini 1
(Push a button wired to it)
Wemos D1 mini 2
(LED wired to it)
Whenever the pushbutton on the Wemos 1 is pressed, light up the attached LED on Wemos 2.
If the pushbutton on Wemos 1 is not pressed, do NOT light up the LED on Wemos 2.
I think this is fairly simple, but despite searching, I am struggling. Can anyone offer some advice? I have both successfully connected to Homeassistant and I can see them in my interface. In fact, the pushbutton shows its status in the interface perfectly, but the LED is not working. Below are my current attempts for each Wemos.
Sorry, I suppose neither of you understood my current situation. Both devices are recognized in Homeassistant, but I am having trouble with them working together in the way that I would like. Here is the complete code:
I am not sure why you are being rude and difficult? Why bother even replying with an answer like that?
I tried to be concise in my original post and highlight what I assumed to be the problem. It’s true, I did not use the code syntax when posting, but I figured it was a simple and short enough code so it was not essential.
Then, I posted the code in full as requested and you just throw insults at me? I am confused, where is the problem?
I read through the examples and thought (with little confidence) that I could light the LED by simply enabling a GPIO pin. Clearly I was not correct. For what it’s worth, I did not come up with that code on my own I copied it from some examples I saw…I am still trying to understand the flow and variables available.
Please correct me if I am wrong…I assume the “Light” section tells home assistant that it should use a light icon or something? I had used the other code because I didn’t quite understand why a relay or switch would be different (electrically) from an LED, ie. You make a pin HIGH, how does the micro controller know the difference?
Regardless, I am happy to try your suggestion and will post back with an update.
I have a different question…maybe not right for this forum.
I understand the logic of setting each esp to connect to HA and letting HA handle the automation (if button pressed, then light up), but is it possible to have the two units operate more independently and have HA simply monitor status?
One example I can think of:
ESP1->publishes status to MQTT server
ESP2->reads MQTT status and responds
HA->monitors MQTT server and shows results
Is there any benefit to this approach or something similar?
There’s a benefit if you don’t use Home Assistant, but still want to make the two devices talk.
There’s not a benefit if you are already running Home Assistant. Mind that letting them talk through MQTT requires an MQTT broker, so you switch one external component with the other and still end up with three components in total. It doesn’t make them more independently.
If you want to let the two connect directly to each other, I there’s there is some integration work being done on something called ESP-Now, but I have never really looked at it closely. No idea how mature or complete it is. It might be worth checking out though.
the MQTT broker works providing a BUS for messages. when posting a message, the TOPIC is read by the devices that subscribed that topic, so …
if your ESP1 publish in the topic that ESP2 is subscribed, it will trigger the action .
nevertheless , if you already have the MQTT broker, I would recommend to have HA doing the automation. More simple and more managable IMHO
Thank you all I had some more time to play with this today and I was able to add the light element and create an automation to get things working!
With a working example, I will tweak and hopefully build from here. Perhaps I will look into the MQTT approach at a later date, but this was not very difficult to get running (once I had the light code corrected).