esphome / esphome-core

🚨 No longer used 🚨 - The C++ framework behind ESPHome
https://esphome.io/
GNU General Public License v3.0
545 stars 113 forks source link

Auto discovery stopped working in dev branch #329

Closed mihalski closed 5 years ago

mihalski commented 5 years ago

Operating environment/Installation (Hass.io/Docker/pip/etc.):

Hass.io with esphomelibyaml-edge addon (current rebuild).

ESP (ESP32/ESP8266/Board/Sonoff):

Wemos D1 Mini Affected component:

MQTT

Description of problem: After the auto-discovery (and re-discovery in Home Assistant) were both implemented everything was perfect. Then after an update to esphomelib/yaml a couple of days ago it stopped working. Nothing is published to the homeassistant topic for Home Assistant to discover.

Problem-relevant YAML-configuration entries:

esphomeyaml:
  name: test2_esp
  platform: ESP8266
  board: d1_mini
  esphomelib_version: dev

wifi:
  ssid: 'DobNet'
  password: 'xxxxxxxxxxxxx'
  domain: .onosendai.xyz

mqtt:
  broker: '192.168.1.222'
  username: ''
  password: ''

# Enable logging
logger:
  logs:
    mqtt.component: DEBUG

ota:

i2c:
  sda: D2
  scl: D1
  scan: True

switch:
  - platform: restart
    name: "Test2 Restart"

sensor:
  - platform: bme280
    temperature:
      name: "Test2 Temperature"
      id: test_temp
    humidity:
      name: "Test2 Humidity"
      id: test_humidity 
    pressure:
      name: "Test2 Pressure"
      id: test_pressure
      accuracy_decimals: 0
    address: 0x76

  - platform: bh1750
    name: "Test2 Illuminance"
    address: 0x23
    filters: []

  - platform: wifi_signal
    name: "Test2 WiFi signal"

  - platform: rotary_encoder
    name: "Test2 Rotary Encoder"
    id: rot_value
    pin_a: D5
    pin_b: D6

font:
  - file: "OpenSansCondensed-Light.ttf"
    id: opensans16
    size: 16

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x32"
    rotation: 90
    # reset_pin: D0
    address: 0x3C
    update_interval: 50ms
    lambda: |-
      it.printf(0, 7, id(opensans16), "%.1fΒ°", id(test_temp).state);
      it.image(60, 0, id(humidity_image_trim));
      it.printf(0, id(rot_value).state, id(opensans16), "%.1f%%", id(test_humidity).state);

Traceback (if applicable):

Additional information:

[I][logger:066]: Log initialized
[C][ota:462]: There have been 4 suspected unsuccessful boot attempts.
[I][application:053]: Running through setup()...
[C][display.ssd1306:302]: Setting up I2C SSD1306...
[C][sensor.bme280:090]: Setting up BME280...
[C][sensor.bh1750:026]: Setting up BH1750 'Test2 Illuminance'...
[C][sensor.rotary_encoder:086]: Setting up Rotary Encoder 'Test2 Rotary Encoder'...
[C][wifi:036]: Setting up WiFi...
[D][wifi:248]: Starting scan...
[D][sensor.sensor:131]: 'Test2 Rotary Encoder': Sending state 0.00000steps with 0 decimals of accuracy
[D][sensor.bme280:208]: Got temperature=30.8Β°C pressure=1004.1hPa humidity=69.5%
[D][sensor.sensor:131]: 'Test2 Temperature': Sending state 30.80000Β°C with 1 decimals of accuracy
[D][sensor.sensor:131]: 'Test2 Pressure': Sending state 1004.08264hPa with 0 decimals of accuracy
[D][sensor.sensor:131]: 'Test2 Humidity': Sending state 69.46680% with 1 decimals of accuracy
[D][sensor.bh1750:090]: 'Test2 Illuminance': Got illuminance=10.8lx
[D][sensor.sensor:131]: 'Test2 Illuminance': Sending state 10.83333lx with 1 decimals of accuracy
[D][wifi:262]: Found networks:
[I][wifi:295]: - 'DobNet' (80:2A:A8:8A:21:B3) β–‚β–„β–†β–ˆ
[D][wifi:296]:     Channel: 11
[D][wifi:297]:     RSSI: -55 dB
[D][wifi:299]: - 'BobNet' (30:5A:3A:C5:65:D8) β–‚β–„β–†β–ˆ
[D][wifi:299]: - '' (86:D6:D0:AF:5E:8A) β–‚β–„β–†β–ˆ
[D][wifi:299]: - 'Telstra57AEA9' (E0:B9:E5:57:AE:A9) β–‚β–„β–†β–ˆ
[D][wifi:299]: - 'HP-Print-FA-Deskjet 2540 series' (64:51:06:FA:3A:FA) β–‚β–„β–†β–ˆ
[I][wifi:170]: WiFi Connecting to 'DobNet'...
[I][wifi:332]: WiFi connected!
[C][wifi:228]:   SSID: 'DobNet'
[C][wifi:229]:   IP Address: 192.168.1.184
[C][wifi:231]:   BSSID: 80:2A:A8:8A:21:B3
[C][wifi:233]:   Hostname: 'test2_esp'
[C][wifi:238]:   Signal strength: -60 dB β–‚β–„β–†β–ˆ
[C][wifi:239]:   Channel: 11
[C][wifi:240]:   Subnet: 255.255.255.0
[C][wifi:241]:   Gateway: 192.168.1.1
[C][wifi:242]:   DNS1: 192.168.1.1
[C][wifi:243]:   DNS2: 0.0.0.0
[C][ota:130]: Over-The-Air Updates:
[C][ota:131]:   Address: 192.168.1.184:8266
[W][ota:137]: Last Boot was an unhandled reset, will proceed to safe mode in 6 restarts
[C][mqtt.client:024]: Setting up MQTT...
[I][mqtt.client:170]: Connecting to MQTT...
[D][sensor.sensor:131]: 'Test2 WiFi signal': Sending state -60.00000dB with 0 decimals of accuracy
[I][mqtt.client:209]: MQTT Connected!
[W][mqtt.client:384]: Publish failed for topic='api/sensor/test2_esp/test2_humidity/config' will retry later..
[I][application:089]: setup() finished successfully!
[I][application:097]: You're running esphomelib v1.10.0-dev compiled on Dec 22 2018, 21:04:44
[C][wifi:324]: WiFi:
[C][wifi:228]:   SSID: 'DobNet'
[C][wifi:229]:   IP Address: 192.168.1.184
[C][wifi:231]:   BSSID: 80:2A:A8:8A:21:B3
[C][wifi:233]:   Hostname: 'test2_esp'
[C][wifi:238]:   Signal strength: -61 dB β–‚β–„β–†β–ˆ
[C][wifi:239]:   Channel: 11
[C][wifi:240]:   Subnet: 255.255.255.0
[C][wifi:241]:   Gateway: 192.168.1.1
[C][wifi:242]:   DNS1: 192.168.1.1
[C][wifi:243]:   DNS2: 0.0.0.0
[C][i2c:043]: I2C Bus:
[C][i2c:044]:   SDA Pin: GPIO4
[C][i2c:045]:   SCL Pin: GPIO5
[C][i2c:046]:   Frequency: 1000 Hz
[I][i2c:048]: Scanning i2c bus for active devices...
[I][i2c:055]: Found i2c device at address 0x23
[I][i2c:055]: Found i2c device at address 0x3C
[I][i2c:055]: Found i2c device at address 0x76
[C][logger:094]: Logger:
[C][logger:095]:   Level: DEBUG
[C][logger:096]:   Log Baud Rate: 115200
[C][logger:098]:   Level for 'mqtt.component': DEBUG
[C][display.ssd1306:315]: I2C SSD1306:
[C][display.ssd1306:316]:   Address: 0x3C
[C][display.ssd1306:317]:   Model: SSD1306 128x32
[C][display.ssd1306:319]:   External VCC: NO
[C][display.ssd1306:320]:   Rotation: 90Β°
[C][display.ssd1306:321]:   Update Interval: 50 ms
[C][sensor.bme280:151]: BME280:
[C][sensor.bme280:152]:   Address: 0x76
[C][sensor.bme280:165]:     Temperature Oversampling: 16x
[C][sensor.bme280:166]:     Pressure Oversampling: 16x
[C][sensor.bme280:167]:     Humidity Oversampling: 16x
[C][sensor.bme280:168]:     IIR Filter: OFF
[C][sensor.bme280:169]:   Update Interval: 15000 ms
[C][sensor.bh1750:033]: BH1750 'Test2 Illuminance':
[C][sensor.bh1750:034]:   Address: 0x23
[C][sensor.bh1750:046]:   Resolution: 0.5
[C][sensor.bh1750:047]:   Update Interval: 15000 ms
[C][sensor.rotary_encoder:102]: Rotary Encoder 'Test2 Rotary Encoder':
[C][sensor.rotary_encoder:103]:   Pin A: GPIO14 (Mode: INPUT)
[C][sensor.rotary_encoder:104]:   Pin B: GPIO12 (Mode: INPUT)
[C][ota:130]: Over-The-Air Updates:
[C][ota:131]:   Address: 192.168.1.184:8266
[W][ota:137]: Last Boot was an unhandled reset, will proceed to safe mode in 6 restarts
[C][mqtt.client:058]: MQTT:
[C][mqtt.client:060]:   Server Address: 192.168.1.222:1883 (192.168.1.222)
[C][mqtt.client:061]:   Username: ''
[C][mqtt.client:062]:   Client ID: 'test2_esp-5ccf7fee929f'
[C][mqtt.client:064]:   Discovery prefix: 'api'
[C][mqtt.client:065]:   Discovery retain: YES
[C][mqtt.client:067]:   Topic Prefix: 'test2_esp'
[C][mqtt.client:069]:   Log Topic: 'test2_esp/debug'
[C][mqtt.client:072]:   Availability: 'test2_esp/status'
[C][switch.mqtt:048]: MQTT switch 'Test2 Restart': 
[C][switch.mqtt:050]:   Icon: 'mdi:restart'
[C][switch.mqtt:055]:   State Topic: 'test2_esp/switch/test2_restart/state'
[C][switch.mqtt:055]:   Command Topic: 'test2_esp/switch/test2_restart/command'
[C][sensor.mqtt:029]: MQTT Sensor 'Test2 Temperature':
[C][sensor.mqtt:031]:   Expire After: 675s
[C][sensor.mqtt:033]:   Unit of Measurement: 'Β°C'
[C][sensor.mqtt:034]:   Accuracy Decimals: 1
[C][sensor.mqtt:041]:   State Topic: 'test2_esp/sensor/test2_temperature/state'
[C][sensor.mqtt:029]: MQTT Sensor 'Test2 Pressure':
[C][sensor.mqtt:031]:   Expire After: 675s
[C][sensor.mqtt:033]:   Unit of Measurement: 'hPa'
[C][sensor.mqtt:034]:   Accuracy Decimals: 0
[C][sensor.mqtt:036]:   Icon: 'mdi:gauge'
[C][sensor.mqtt:041]:   State Topic: 'test2_esp/sensor/test2_pressure/state'
[C][sensor.mqtt:029]: MQTT Sensor 'Test2 Humidity':
[C][sensor.mqtt:031]:   Expire After: 675s
[C][sensor.mqtt:033]:   Unit of Measurement: '%'
[C][sensor.mqtt:034]:   Accuracy Decimals: 1
[C][sensor.mqtt:036]:   Icon: 'mdi:water-percent'
[C][sensor.mqtt:041]:   State Topic: 'test2_esp/sensor/test2_humidity/state'
[C][sensor.mqtt:029]: MQTT Sensor 'Test2 Illuminance':
[C][sensor.mqtt:031]:   Expire After: 45s
[C][sensor.mqtt:033]:   Unit of Measurement: 'lx'
[C][sensor.mqtt:034]:   Accuracy Decimals: 1
[C][sensor.mqtt:036]:   Icon: 'mdi:brightness-5'
[C][sensor.mqtt:041]:   State Topic: 'test2_esp/sensor/test2_illuminance/state'
[C][sensor.mqtt:029]: MQTT Sensor 'Test2 WiFi signal':
[C][sensor.mqtt:031]:   Expire After: 675s
[C][sensor.mqtt:033]:   Unit of Measurement: 'dB'
[C][sensor.mqtt:034]:   Accuracy Decimals: 0
[C][sensor.mqtt:036]:   Icon: 'mdi:wifi'
[C][sensor.mqtt:039]:   Unique ID: '5ccf7fee929f-wifisignal'
[C][sensor.mqtt:041]:   State Topic: 'test2_esp/sensor/test2_wifi_signal/state'
[C][sensor.mqtt:029]: MQTT Sensor 'Test2 Rotary Encoder':
[C][sensor.mqtt:033]:   Unit of Measurement: 'steps'
[C][sensor.mqtt:034]:   Accuracy Decimals: 0
[C][sensor.mqtt:036]:   Icon: 'mdi:rotate-right'
[C][sensor.mqtt:041]:   State Topic: 'test2_esp/sensor/test2_rotary_encoder/state'
[I][application:114]: Running through first loop()
[I][application:141]: First loop finished successfully!
[D][sensor.bme280:208]: Got temperature=29.2Β°C pressure=1004.0hPa humidity=50.1%
[D][sensor.bh1750:090]: 'Test2 Illuminance': Got illuminance=10.0lx
[D][sensor.sensor:131]: 'Test2 Illuminance': Sending state 10.00000lx with 1 decimals of accuracy
[D][sensor.bme280:208]: Got temperature=28.5Β°C pressure=1004.0hPa humidity=50.7%
[D][sensor.bh1750:090]: 'Test2 Illuminance': Got illuminance=11.7lx
[D][sensor.sensor:131]: 'Test2 Illuminance': Sending state 11.66667lx with 1 decimals of accuracy
[D][sensor.bme280:208]: Got temperature=28.2Β°C pressure=1003.9hPa humidity=51.5%
[D][sensor.bh1750:090]: 'Test2 Illuminance': Got illuminance=11.7lx
[D][sensor.sensor:131]: 'Test2 Illuminance': Sending state 11.66667lx with 1 decimals of accuracy
[D][sensor.bme280:208]: Got temperature=28.0Β°C pressure=1004.1hPa humidity=51.9%
[D][sensor.bh1750:090]: 'Test2 Illuminance': Got illuminance=10.0lx
[D][sensor.sensor:131]: 'Test2 Illuminance': Sending state 10.00000lx with 1 decimals of accuracy
oscar-b commented 5 years ago

Looks like it publishes to api/ instead of default auto discovery prefix.

mihalski commented 5 years ago

Special thanks to @oscar-b ! The solution is to specify discovery_prefix in the config:

mqtt:
  discovery_prefix: homeassistant
oscar-b commented 5 years ago

Problem is here: https://github.com/OttoWinter/esphomelib/blob/ddebb4c08492465524355454f70316938019ffe6/src/esphomelib/mqtt/mqtt_client_component.h#L262-L267

brandond commented 5 years ago

Otto is also a core dev for Home Assistant, so I'm guessing there's a corresponding change coming on that side. I was about to try updating Home Assistant to dev as well to see if that gets it working again.

This is a pretty unpleasant surprise though, even if upgrading fixes it.

brandond commented 5 years ago

I just updated my Home Assistant server to 0.85.0.dev0 (homeassistant/home-assistant:dev on docker hub) and autodiscovery is still not working.

@OttoWinter - what's the intended migration path here? Sure hoping there's something I can do on the Home Assistant side, as the device I upgraded happens to be a hard-to-reach esp01_1m device that I have to retrieve and flash via serial adapter.

mihalski commented 5 years ago

@brandond Have you not tried the fix I suggested? Works for me.

OttoWinter commented 5 years ago

Oh... facepalm

That, ladies and gentlemen, is a bug - And thank you very much for reporting the full log and spotting the discovery prefix. That would have taken lots of time to find for myself πŸ™ƒ

And I can tell you how it happened: While developing the esphomelib native API, the api namespace was first called homeassistant because it was made for use with HA. But then I thought of other use cases (for example inter node communication) and decided to change the name to just api.

That change would have required me going through lots of files and changing probably around 50-100 occurences of homeassistant to api. So I did what most programmers would do in that case 😜 Find and Replace. I thought I only applied it to the API folder but apparently not.