I’ve been using Tasmota for a couple of years on more than a dozen devices around the house. ESP Home looks like a better integration with Home Assistant, so I wanted to give it a try.
My first test was with a NodeMCU. Home Assistant found the switch I defined in the YAML file, but no state change was detected. [Is it pull down or pull up? I tried both.]
Having no success I compiled ESP Home for a Wemos D1 Mini and flashed it. This time, the switch doesn’t show up in the entities.
Any tips of what I may have done wrong?
esphome:
name: wemos_test
platform: ESP8266
board: d1_mini
wifi:
ssid: "Kaywinnet"
password: "806194xxxxx"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Wemos Test Fallback Hotspot"
password: "Oi136ZHGIzON"
captive_portal:
# Enable logging
logger:
level: DEBUG
# Enable Home Assistant API
api:
ota:
safe_mode: True
# Switch on D4, GPIO2
switch:
- platform: gpio
name: "Wemos_Test"
pin: D4
I should be seeing an entity: switch.wemos_test, but I am not. That is the question.
UPDATE: I didn’t realize that I had to run configuration again, but now the switch is in the list of entities. Now- How do I get the switch to respond. I pull the GPIO pin to ground or to 3V3, but the entity switch.wemos_test remains “off”.
I will start a new thread since my YAML and log is substantially different, and my issue has changed.
The first version should work as is. There is nothing obviously incorrect, so the switch should appear in HA after setting it up via integrations. You should debug here and not trying by accident
The second config is not that wrong, you would use that for example with a binary_sensor to use a physical button on your chip (like with the Sonoffs).
Here is a very simple example from one of my Sonoffs:
As you can see, i have just a switch to call by HA, and for the physical button there is a binary_sensor that is set internal aka not-shown-in-HA. If you push the button, you toggle the relay aka the switch inside your board (ESPx-NodeMCU, D1).
So it seems, something else is wrong that needs to be debuged, not changed.
It does work now, simulating a Sonoff Basic on a Wemos MD1 Mini. I think that I understand what I have. (I am almost a complete doofus when it comes to YAML code).
Do I even need a name on the binary sensor?
# Physical Button on D1 (GPIO5)
binary_sensor:
- platform: gpio
pin:
number: D1
inverted: False
mode: INPUT_PULLUP
name: Wemos_Switch"
internal: true
on_press:
- switch.toggle: led
# Virtual switch D0, GPIO16
# This is what I want the physical switch to control.
switch:
- platform: gpio
name: "Wemos_Switch"
pin:
number: D0
mode: output
id: led
In Tasmota I can say the physical switch is a button (toggles) or a switch (on/off).
This YAML is acting like a Sonoff Basic where the button toggles the output. How can I configure this so that the LED on D0 (my “virtual” switch) only toggles when the state of the physical switch changes?
In ESPHome everything is handled “on it’s own” and will afterwards be combined. In my example, the binary_sensor is the physical button to press. You might expect that this button does something physical on the board, but that’s not the case. See it that simple: everything that can do something, is one part in ESPHome. The button, the relay, the LED.
And these need to be combined, that’s why you call an id with your binary_sensor and that id is the relay. If you step back a little and take a wider look at ESPHome, it is surprisingly that simple.
That’s the beauty of ESPHome, because everything is one “component” and can be controlled on it’s own, you have the possibility to make a simple relay in your wall a light in HA. Here is one, as well very simple, example for a Shelly device. In principle a relay that is behind my light switch. It can be controlled via HA or with the physical wall switch.
Yes, thank you. Your Shelly example does clear things up a bit, (and adds more questions). I’ve spent the evening reading the cookbook and DIY examples and gleaned some ideas - and many more questions.
Where do I find documentation of “on_state” and “on_press” and other conditions? Is this unique to ESPHome or is it generic to YAML? Where are the various platforms described?
I am sure that once it clicks I will be converting many of my devices with Tasmota to ESPHome.
Under the component, in this case it is a binary_sensor, so here:
The way you have to write it is generic YAML. The things you write in YAML language is ESPHome specific.
The start page from ESPHome. The left side navigation is a little more usable.
Look at the binary_sensor component. Every component has a core part, and some extensions to the specific component, for example a touch input for a binary_sensor.
Written in ESPHome this looks something like this:
I’m getting somewhere, but I think my lack of experience with YAML is getting in my way.
For example, I want the LED on my Wemos to follow the button state. As long as the button is down, I want the LED on. Release the button and the LED should be off.
I can do it with an automation in Home Assistant because the state of binary_sensor.wemos_test_button is what I want the LED to follow. But shouldn’t I be able to do this completely within ESPHome?
Partial example here: this is from my mains meter reader, which has a sensor watching the light on the front of the meter that pulses for every watt-hour consumed. The meter is outside, and I wanted to “copy” the flashing light to my box, which is inside.
box_led is in my unit, driven by pin D1 of my ESP device (D1 Mini). It is inverted because I’ve wired the ESP as a current sink, so HIGH is off. The light sensor from the meter is on pin D2:
There’s more to the code than this, but it shows what you can do. I agree with @nickrout though — do work your way through the excellent and comprehensive documentation.
I appreciate the hand-holding that’s gotten me this far. Thanks to your guidance I can replicate a Sonoff Basic on a NodeMCU and on a Wemos D1 Mini. (I will mark the thread as solved.)
This morning, one of my devices was “unavailable” on Lovelace.
Here’s what I found.
In Developer Tools/States, I see duplicates of the entities for my switch: switch.wemos_switch (off)
and switch.wemos_switch_2 (off)
Either you’ve set two devices up with the same name, or you’ve reloaded the existing one over the new config. HA is avoiding a clash of names by adding the _2. You should be able to delete one and rename the other if needed from Configuration / Entities.