Esphomelib - library to greatly simplify Home Assistant integration with ESP32

I’ve just tested it on a ESP8266 with a DHT22 and a PIR sensor and it’s work like a charm.
I’ve used ESPEasy a little but this is a better match with HA. Especially with MQTT autodiscovery.
Guides could use some work to get everyone started with the project (primarily with platformio).
One thing I’ve noticed is that if MQTT server (I’m using Mosquitto) is restarted/reset along with Home Assistant the sensors don’t seem to “regenerate” until esphomelib is restarted?

Yes the guides are quite poor… Fortunately, setting up has just become a lot easier with esphomeyaml. All you need to run now is a single command:

esphomeyaml configuration.yaml run

One thing I’ve noticed is that if MQTT server (I’m using Mosquitto) is restarted/reset along with Home Assistant the sensors don’t seem to “regenerate” until esphomelib is restarted?

What do you mean with “regenerate”? Do they not report any new values or do you mean them not showing up at all through the front-end? esphomelib should restart itself automatically if the connection to the broker is lost. So restarting manually shouldn’t really be necessary (just tested it too, and it’s working for me :/)

1 Like

I don’t know what happend but MQTT works nicely. I guess my test setup was pulling my leg or I was impatient.
Great work by the way :slight_smile:

Nice with the esphomeyaml. I made 3 modules this weekend using it.

There is something going on with MQTT.
I’m using Mosquitto and if I shutdown the server and start it again fast enough the MQTT values aren’t recreated. (My Mosquitto don’t save anything when shutdown/rebooted).

Solution seems to either shut it down for a longer period (1-2 minuttes) so the Esphomelib modules reboot or make them reconnect using my wifi controller (Ubiquiti Unifi).

It seems to happen here (graped via serial console on a module).
Does that make sense?
[I][mqtt.client:reconnect:96]: Reconnecting to MQTT…
[D][mqtt.client:reconnect:99]: Attempting MQTT connection…
[W][mqtt.client:reconnect:131]: MQTT connection failed, rc=-2
[W][mqtt.client:reconnect:132]: Try again in 1 second
[D][mqtt.client:reconnect:99]: Attempting MQTT connection…
[W][mqtt.client:reconnect:131]: MQTT connection failed, rc=-2
[W][mqtt.client:reconnect:132]: Try again in 1 second
[D][mqtt.client:reconnect:99]: Attempting MQTT connection…
[W][mqtt.client:reconnect:131]: MQTT connection failed, rc=-2
[W][mqtt.client:reconnect:132]: Try again in 1 second
[D][mqtt.client:reconnect:99]: Attempting MQTT connection…
[I][mqtt.client:reconnect:128]: MQTT Connected!

@OttoWinter I’m really impressed! stunning and excellent work!

my testsetup with a dht22 sensor works. Debug info is published every 15s (like i defined in the yaml) but beside the the debug data real values are not published in the given interval

is that a bug or my fault?

Log from mosquitto_pub:

chris@metis:~$ sub |grep testsensor
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=24.3°C Humidity=54.9%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=24.3°C Humidity=54.4%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=24.2°C Humidity=53.9%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.9°C Humidity=53.6%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.7°C Humidity=53.4%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.5°C Humidity=53.7%
testsensor/debug [I][ota:loop:101]: Boot seems successful, resetting boot loop counter.
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.4°C Humidity=53.8%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.3°C Humidity=53.7%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.2°C Humidity=53.7%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.2°C Humidity=53.8%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.1°C Humidity=53.6%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.1°C Humidity=53.5%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.1°C Humidity=53.7%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.1°C Humidity=53.8%
testsensor/debug [D][sensor.mqtt:push_out_value:83]: 'Temperature': Pushing out value 23.580004 with accuracy 1
testsensor/sensor/temperature/state 23.6
testsensor/debug [D][sensor.mqtt:push_out_value:83]: 'Humidity': Pushing out value 53.939999 with accuracy 0
testsensor/sensor/humidity/state 54
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.1°C Humidity=54.2%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.1°C Humidity=54.2%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.1°C Humidity=54.2%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=54.0%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=54.0%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.9%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.7%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.5%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.5%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.5%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.4%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.4%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.4%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.4%
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.3%
testsensor/debug [D][sensor.mqtt:push_out_value:83]: 'Temperature': Pushing out value 23.020002 with accuracy 1
testsensor/sensor/temperature/state 23.0
testsensor/debug [D][sensor.mqtt:push_out_value:83]: 'Humidity': Pushing out value 53.706673 with accuracy 0
testsensor/sensor/humidity/state 54
testsensor/debug [D][sensor.dht:update:50]: Got Temperature=23.0°C Humidity=53.2%

my test.yaml:

» cat testsensor.yaml 
esphomeyaml:
  name: testsensor
  platform: ESP32
  board: lolin32

wifi:
  ssid: 'ssid'
  password: 'password'

mqtt:
  broker: '192.168.0.27'
  username: 'esp'
  password: 'password'

# Enable logging
logger:

ota:
sensor:
  - platform: dht
    pin: 17 
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
    update_interval: 15s
    indent preformatted text by 4 spaces

Yeah I don’t really have a way around that. The problem is that the ESPs have way too little memory space to store complete MQTT messages on them for a longer time. So I think there are two solutions to the problem:

  1. Don’t restart the MQTT broker :sweat_smile:
  2. Restart the nodes using the Restart Switch.

The logs you’re seeing are normal if the MQTT broker is restarting. As the logs say, the node is attempting to reconnect, and failing a few times as the broker is not fully booted up.

Yes that’s expected because esphomelib/esphomeyaml automatically put a sliding window moving average filter on the sensor values. So the values will only be “pushed out” to MQTT on every 15th value (this is done 1. to make less noisy sensor values and 2. to decrease network traffic).

You can however disable the filter like this:

sensor:
  - platform: dht
    temperature:
      name: "Outside Temperature"
      filters:
    humidity:
      name: "Outside Humidity"
      filters:

ah ok rather a feature than a bug =)

I don’t plan on doing random reboots of the MQTT server, but it’s nice to know how the software behaves in different scenarios so I know what to expect :thinking: So no issue at all. :smile:

My devices show up as “unavailable” a lot. Any suggestions?
Wifi coverage is good and no other devices have problems with getting disconnected.

Testing systems before using them, that’s very very good :+1: :smile:

About the unavailable: I had something like that with an ESP8266 too some time ago, but it just magically disappeared. Unfortunately, I can’t really help too much without serial monitor logs :confused: (“unavailable” means that there’s no MQTT connection)

I’ll try to capture something in the log. I tried the last hour but of course it don’t happen when logging :thinking:

@OttoWinter I am trying to use esphomeyaml and i am installing from a windows 10 laptop running python. I get a this error at the end and dont see the nodemcu being connected to wifi nor to home assistant (MQTT is set to discovery).

| | |-- v1.0
| | |--
| | | |-- v1.0
Calculating size .pioenvs\garage\firmware.elf
text data bss dec hex filename
307734 12952 30536 351222 55bf6 .pioenvs\garage\firmware.elf
============================================ [SUCCESS] Took 16.67 seconds ============================================
e[32mINFO [esphomeyaml.main] Successfully compiled program.e[0m
e[32mINFO [esphomeyaml.main] Uploading binary…e[0m
e[32mINFO [esphomeyaml.espota] Starting on 0.0.0.0:24448e[0m
e[32mINFO [esphomeyaml.espota] Upload size: 324832e[0m
e[32mINFO [esphomeyaml.espota] Sending invitation to garage.local e[0m
e[31mERROR [esphomeyaml.espota] Failede[0m
e[31mERROR [esphomeyaml.espota] Host garage.local Not Founde[0m

Hmmm, that log means that the OTA update is failing because the node isn’t connected to WiFi (or has a new hostname). There could be several reasons for that and only the serial logs will help with that - also, I haven’t really tested esphomeyaml with Windows all that much as I don’t have a Windows system of my own and had to ask a friend to test it once.

Anyway, what did esphomeyaml say when you first tried to upload the binary via the serial connection? The “first” firmware upload to the ESP always has to happen via the USB cable as OTA isn’t setup if no firmware is installed on the ESP. Anything esphomeyaml garage.yaml logs is outputting when connected via USB cable (serial)?

I fixed a lot of things before getting to this. But i doubt the firmware even loaded the first time.

  1. I downgraded from Python 3.6 to 2.7
  2. I had to run cmd as admin since esphomeyaml complained about some permissions
  3. Then esphomeyaml was not able to find the COM port, so i installed the CP210 universal driver after which esphomeyaml didnt complain about the COM port when esp was connected
  4. After all that i got this into this issue.

Do you think i should delete everything and start from scratch? I am not getting in esphomeyaml garage.yaml logs

I deleted the garage.yaml and the garage folder and tried again using the esphomeyaml garage.yaml wizard. THe yaml got created again. Now i executed the command esphomeyaml garage.yaml run but i get same error. I dont think the firmware is getting uploaded through the USB the first time. It somehow thinks it should connect with wifi.

Compiling .pioenvs\garage\FrameworkArduino\umm_malloc\umm_malloc.c.o
Archiving .pioenvs\garage\libFrameworkArduino.a
Linking .pioenvs\garage\firmware.elf
Calculating size .pioenvs\garage\firmware.elf
Building .pioenvs\garage\firmware.bin
text data bss dec hex filename
301318 11792 30520 343630 53e4e .pioenvs\garage\firmware.elf
============================================ [SUCCESS] Took 150.90 seconds ============================================
e[32mINFO [esphomeyaml.main] Successfully compiled program.e[0m
e[32mINFO [esphomeyaml.main] Uploading binary…e[0m
e[32mINFO [esphomeyaml.espota] Starting on 0.0.0.0:57905e[0m
e[32mINFO [esphomeyaml.espota] Upload size: 317264e[0m
e[32mINFO [esphomeyaml.espota] Sending invitation to garage.local e[0m
e[31mERROR [esphomeyaml.espota] Failede[0m
e[31mERROR [esphomeyaml.espota] Host garage.local Not Founde[0m

@OttoWinter may i know what platform you build this on if not windows? mac or linux?

Hmmm, seems like esphomeyaml is not discovering your USB device. Then it automatically tries to upload via OTA (In order to have the same command for serial and OTA uploads). All the points you listed above are pretty much all required for esphomeyaml (for example, we need python 2 as a dependency platformio doesn’t support python 3).

Could you try running platformio device list and platformio run -d garage -t upload. These commands should force it I use platformio which might have a different serial port handling.

I created this on my Mac Laptop and also teste uploads and so on a lot with a RPi 2&3.

Yup that worked and i am able to see the nodemcu in my router. Awesssommmeee…Thanks a lot mate.

I will try now adding some sensors and integrating with Home Assistant.

Could you maybe post the output of platformio device list even though it works now? I would really like to actually fix the issue :grinning:

Sure. here is the output.

> COM5
> ----
> Hardware ID: USB VID:PID=10C4:EA60 SER=0001 LOCATION=1-1.1
> Description: Silicon Labs CP210x USB to UART Bridge (COM5)
> 
> COM4
> ----
> Hardware ID: USB VID:PID=03F0:241D SER=6 LOCATION=1-1.2
> Description: HP un2420 HS-USB QDLoader (COM4)

Also, it doesnt work through OTA. I have to connect to my laptop through USB and use your command to upload.