esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 35 forks source link

htu21d Humidity Sensor: Calling set_heater causes device to crash #4975

Open Nippey opened 11 months ago

Nippey commented 11 months ago

The problem

(Already started a thread in discord, but I think a bug is better suited here: https://discordapp.com/channels/429907082951524364/1161952623952408657)

I am using multiple Si7021 via htu21d component in a quite humind environment. Therefore I want to implement the heating function to tackle humidity buildup.

I configured an automation to activate the heaters. Calling id(garage_sensor).set_heater_level(4); works fine. But calling id(garage_sensor).set_heater(true); triggers a reboot.

For testing, I reduced it to a single sensor. I can trigger it via "Garage Sensor Heater Switch" either with HA or with the Dashboard.

At [19:54:26] below, you can see that I clicked the switch; then follows, what I assume a segmentation fault.

Which version of ESPHome has the issue?

2023.9.3

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

NA

What platform are you using?

ESP32

Board

ESP32-WROOM-32

Component causing the issue

htu21d

Example YAML snippet

esphome:
  name: esp32-garage-hum

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

# Enable logging
logger:

i2c:
   - id: bus_garage
     sda: 16
     scl: 17
     scan: true
     frequency: 10kHz

switch:
  - platform: template
    name: "Garage Sensor Heater Switch"
    restore_mode: disabled
    lambda: |-
      return id(garage_sensor).is_heater_enabled();
    turn_on_action:
      - lambda: |-
            id(garage_sensor).set_heater_level(4);
            id(garage_sensor).set_heater(true);
    turn_off_action:
      - lambda: |-
            id(garage_sensor).set_heater_level(0);
            id(garage_sensor).set_heater(false);

sensor:
  - platform: htu21d
    i2c_id: bus_garage
    id: garage_sensor
    temperature:
      name: "Garage Temperature"
      id: garage_temp
    humidity:
      name: "Garage Rel Humidity"
      id: garage_rel_hum
    heater:
      name: "Garage Sensor Heater"   
      id: garage_heater
    update_interval: 60s

# Enable Home Assistant API
api:
  encryption:
    key: "XXXXX"

ota:
  password: "XXXXX"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

Anything in the logs that might be useful for us?

Linking .pioenvs\esp32-garage-hum\firmware.elf
Retrieving maximum program size .pioenvs\esp32-garage-hum\firmware.elf
Checking size .pioenvs\esp32-garage-hum\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  12.3% (used 40312 bytes from 327680 bytes)
Flash: [=====     ]  48.3% (used 885541 bytes from 1835008 bytes)
Building .pioenvs\esp32-garage-hum\firmware.bin
esptool.py v4.4
Creating esp32 image...
Merged 25 ELF sections
Successfully created esp32 image.
esp32_create_combined_bin([".pioenvs\esp32-garage-hum\firmware.bin"], [".pioenvs\esp32-garage-hum\firmware.elf"])
esptool.py v4.6.2
Wrote 0xe99b0 bytes to file C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum\.pioenvs\esp32-garage-hum/firmware-factory.bin, ready to flash to offset 0
x0
======================== [SUCCESS] Took 101.95 seconds ========================
INFO Successfully compiled program.
Found multiple options for uploading, please choose one:
  [1] COM4 (Silicon Labs CP210x USB to UART Bridge (COM4))
  [2] Over The Air (esp32-garage-hum.local)
(number): 1
esptool.py v4.6.2
Serial port COM4
Connecting....
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme
None
Crystal is 40MHz
MAC: c8:c9:a3:ca:91:00
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00010000 to 0x000e9fff...
Flash will be erased from 0x00001000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Compressed 891312 bytes to 587854...
Wrote 891312 bytes (587854 compressed) at 0x00010000 in 13.7 seconds (effective519.0 kbit/s)...
Hash of data verified.
Compressed 17440 bytes to 12128...
Wrote 17440 bytes (12128 compressed) at 0x00001000 in 0.6 seconds (effective 234.3 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 144...
Wrote 3072 bytes (144 compressed) at 0x00008000 in 0.1 seconds (effective 296.0kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.2 seconds (effective 420.1 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
INFO Successfully uploaded program.
INFO Starting log output from COM4 with baud rate 115200
[19:54:01]ts Jun [I][logger:268]: Log initialized
[19:54:01][C][ota:473]: There have been 0 suspected unsuccessful boot attempts.
[19:54:01][D][esp32.preferences:114]: Saving 1 preferences to flash...
[19:54:01][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[19:54:01][I][app:029]: Running through setup()...
[19:54:01][I][i2c.arduino:183]: Performing I2C bus recovery
[19:54:01][C][htu21d:021]: Setting up HTU21D...
[19:54:01][C][wifi:038]: Setting up WiFi...
[19:54:01][C][wifi:051]: Starting WiFi...
[19:54:01][C][wifi:052]:   Local MAC: C8:C9:A3:CA:91:00
[19:54:01][D][wifi:428]: Starting scan...
[19:54:01][D][htu21d:072]: Got Temperature=23.5°C Humidity=82.4% Heater Level=0
[19:54:01][D][sensor:094]: 'Garage Temperature': Sending state 23.49592 °C with1 decimals of accuracy
[19:54:01][D][sensor:094]: 'Garage Rel Humidity': Sending state 82.44757 % with1 decimals of accuracy
[19:54:01][D][sensor:094]: 'Garage Sensor Heater': Sending state 82.44757  with1 decimals of accuracy
[19:54:01][W][component:204]: Component htu21d.sensor took a long time for an operation (0.15 s).
[19:54:01][W][component:205]: Components should block for at most 20-30ms.
[19:54:01][D][switch:055]: 'Garage Sensor Heater Switch': Sending state OFF
[19:54:07][D][wifi:443]: Found networks:
 XXXXXXXXXXXXXXXXXXXXXXXXXXXX Nippey snipped here XXXXXXXXXXXXXXXXXXXXXXXXXX 
[19:54:09][C][wifi:397]:   DNS2: 0.0.0.0
[19:54:09][C][logger:357]: Logger:
[19:54:09][C][logger:358]:   Level: DEBUG
[19:54:09][C][logger:359]:   Log Baud Rate: 115200
[19:54:09][C][logger:361]:   Hardware UART: UART0
[19:54:09][C][i2c.arduino:053]: I2C Bus:
[19:54:09][C][i2c.arduino:054]:   SDA Pin: GPIO16
[19:54:09][C][i2c.arduino:055]:   SCL Pin: GPIO17
[19:54:09][C][i2c.arduino:056]:   Frequency: 10000 Hz
[19:54:09][C][i2c.arduino:059]:   Recovery: bus successfully recovered
[19:54:09][I][i2c.arduino:069]: Results from i2c bus scan:
[19:54:09][I][i2c.arduino:075]: Found i2c device at address 0x40
[19:54:09][C][template.switch:068]: Template Switch 'Garage Sensor Heater Switch'
[19:54:09][C][template.switch:091]:   Restore Mode: disabled
[19:54:09][C][template.switch:057]:   Optimistic: NO
[19:54:09][C][htu21d:032]: HTU21D:
[19:54:09][C][htu21d:033]:   Address: 0x40
[19:54:09][C][htu21d:037]:   Update Interval: 60.0s
[19:54:09][C][htu21d:038]:   Temperature 'Garage Temperature'
[19:54:09][C][htu21d:038]:     Device Class: 'temperature'
[19:54:09][C][htu21d:038]:     State Class: 'measurement'
[19:54:09][C][htu21d:038]:     Unit of Measurement: '°C'
[19:54:09][C][htu21d:038]:     Accuracy Decimals: 1
[19:54:09][C][htu21d:039]:   Humidity 'Garage Rel Humidity'
[19:54:09][C][htu21d:039]:     Device Class: 'humidity'
[19:54:09][C][htu21d:039]:     State Class: 'measurement'
[19:54:09][C][htu21d:039]:     Unit of Measurement: '%'
[19:54:09][C][htu21d:039]:     Accuracy Decimals: 1
[19:54:09][C][mdns:115]: mDNS:
[19:54:09][C][mdns:116]:   Hostname: esp32-garage-hum
[19:54:09][C][ota:097]: Over-The-Air Updates:
[19:54:09][C][ota:098]:   Address: esp32-garage-hum.local:3232
[19:54:09][C][ota:101]:   Using Password.
[19:54:09][C][api:138]: API Server:
[19:54:09][C][api:139]:   Address: esp32-garage-hum.local:6053
[19:54:09][C][api:141]:   Using noise encryption: YES
[19:54:10][D][api:102]: Accepted 192.168.188.44
[19:54:10][D][api.connection:1031]: Home Assistant 2023.6.0 (192.168.188.44): Connected successfully
[19:54:26][D][switch:012]: 'Garage Sensor Heater Switch' Turning ON.
[19:54:26]Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
[19:54:26]
[19:54:26]Core  1 register dump:
[19:54:26]PC      : 0x401650f4  PS      : 0x00060d30  A0      : 0x800d7ef8  A1
    : 0x3ffb2490
WARNING Decoded 0x401650f4: esphome::i2c::I2CDevice::write_register(unsigned char, unsigned char const*, unsigned int, bool) at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/i2c/i2c.cpp:31
[19:54:26]A2      : 0x3ffb9900  A3      : 0x000000e6  A4      : 0x3ffb24df  A5    : 0x00000001
[19:54:26]A6      : 0x00000001  A7      : 0xff000000  A8      : 0x00000001  A9    : 0x3ffb2470
[19:54:26]A10     : 0x00000002  A11     : 0x00000040  A12     : 0x3ffb24df  A13    : 0x00000002
[19:54:26]A14     : 0x00000001  A15     : 0x3ffd1ac8  SAR     : 0x00000004  EXCCAUSE: 0x0000001c
[19:54:26]EXCVADDR: 0x00000002  LBEG    : 0x400895cc  LEND    : 0x400895e2  LCOUNT  : 0xffffffff
[19:54:26]
[19:54:26]
[19:54:26]Backtrace:0x401650f1:0x3ffb24900x400d7ef5:0x3ffb24d0 0x400df9fb:0x3ffb2500 0x400df9c9:0x3ffb2520 0x4016566b:0x3ffb2540 0x4016526d:0x3ffb2560 0x400dab15:0x3ffb2580 0x400da669:0x3ffb25a0 0x400d2e91:0x3ffb25c0 0x40164d05:0x3ffb25e0 0x400d6b6e:0x3ffb2600 0x400d3276:0x3ffb2690 0x400d7229:0x3ffb2720 0x4016542d:0x3ffb2790 0x401654ed:0x3ffb27b0 0x400dd84c:0x3ffb27d0 0x400dfad2:0x3ffb2800 0x400e7561:0x3ffb2820
WARNING Found stack trace! Trying to decode it
WARNING Decoded 0x401650f1: esphome::i2c::I2CDevice::write_register(unsigned char, unsigned char const*, unsigned int, bool) at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/i2c/i2c.cpp:28
WARNING Decoded 0x400d7ef5: esphome::htu21d::HTU21DComponent::set_heater(bool) at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/htu21d/htu21d.cpp:106
WARNING Decoded 0x400df9fb: std::_Function_handler<void (), setup()::{lambda()#3}>::_M_invoke(std::_Any_data const&) at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/esp32-garage-hum.yaml:39
 (inlined by) _M_invoke at c:\users\XXXXX\.platformio\packages\toolchain-xtensa-esp32@8.4.0+2021r2-patch5\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:297
WARNING Decoded 0x400df9c9: std::function<void ()>::operator()() const at c:\users\XXXXX\.platformio\packages\toolchain-xtensa-esp32@8.4.0+2021r2-patch5\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:687
 (inlined by) esphome::LambdaAction<>::play() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/core/base_automation.h:135
WARNING Decoded 0x4016566b: esphome::Action<>::play_complex() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/core/automation.h:125WARNING Decoded 0x4016526d: esphome::ActionList<>::play() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/core/automation.h:203
 (inlined by) esphome::Automation<>::trigger() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/core/automation.h:241
 (inlined by) esphome::Trigger<>::trigger() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/core/automation.h:98
WARNING Decoded 0x400dab15: esphome::template_::TemplateSwitch::write_state(bool) at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/template/switch/template_switch.cpp:30
WARNING Decoded 0x400da669: esphome::switch_::Switch::turn_on() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/switch/switch.cpp:13
WARNING Decoded 0x400d2e91: esphome::api::APIConnection::switch_command(esphome::api::SwitchCommandRequest const&) at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/api/api_connection.cpp:485
WARNING Decoded 0x40164d05: esphome::api::APIServerConnection::on_switch_command_request(esphome::api::SwitchCommandRequest const&) at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/api/api_pb2_service.cpp:1085
 (inlined by) esphome::api::APIServerConnection::on_switch_command_request(esphome::api::SwitchCommandRequest const&) at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/api/api_pb2_service.cpp:1076
WARNING Decoded 0x400d6b6e: esphome::api::APIServerConnectionBase::read_message(unsigned int, unsigned int, unsigned char*) at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/api/api_pb2_service.cpp:658
WARNING Decoded 0x400d3276: esphome::api::APIConnection::loop() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/api/api_connection.cpp:103
WARNING Decoded 0x400d7229: esphome::api::APIServer::loop() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/components/api/api_server.cpp:120 (discriminator 2)
WARNING Decoded 0x4016542d: esphome::Component::call_loop() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/core/component.cpp:76
WARNING Decoded 0x401654ed: esphome::Component::call() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/core/component.cpp:98
WARNING Decoded 0x400dd84c: esphome::Application::loop() at C:\Users\XXXXX\esphome\.esphome\build\esp32-garage-hum/src/esphome/core/application.cpp:74 (discr
[19:54:27]mode:DIO, clock div:2
[19:54:27]load:0x3fff0030,len:1184
[19:54:27]load:0x40078000,len:13132
[19:54:27]load:0x40080400,len:3036
[19:54:27]entry 0x400805e4
[19:54:27][I][logger:268]: Log initialized
[19:54:27][C][ota:473]: There have been 1 suspected unsuccessful boot attempts.
[19:54:27][D][esp32.preferences:114]: Saving 1 preferences to flash...
[19:54:27][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[19:54:27][I][app:029]: Running through setup()...
[19:54:27][I][i2c.arduino:183]: Performing I2C bus recovery
[19:54:27][C][htu21d:021]: Setting up HTU21D...
[19:54:27][C][wifi:038]: Setting up WiFi...
[19:54:27][C][wifi:051]: Starting WiFi...
[19:54:27][C][wifi:052]:   Local MAC: C8:C9:A3:CA:91:00
[19:54:27][D][wifi:428]: Starting scan...
[19:54:27][D][htu21d:072]: Got Temperature=23.5°C Humidity=82.4% Heater Level=0
[19:54:27][D][sensor:094]: 'Garage Temperature': Sending state 23.50665 °C with 1 decimals of accuracy
[19:54:27][D][sensor:094]: 'Garage Rel Humidity': Sending state 82.37128 % with 1 decimals of accuracy
[19:54:27][D][sensor:094]: 'Garage Sensor Heater': Sending state 82.37128  with 1 decimals of accuracy
[19:54:27][W][component:204]: Component htu21d.sensor took a long time for an operation (0.15 s).
[19:54:27][W][component:205]: Components should block for at most 20-30ms.
[19:54:27][D][switch:055]: 'Garage Sensor Heater Switch': Sending state OFF
[19:54:33][D][wifi:443]: Found networks:

Additional information

No response

Nippey commented 11 months ago

Discussion ongoing in discord, short status: htu21d contains this->bus_ from its parent class i2c. And this pointer to the i2c bus gets screwed-up when calling write_register from inside set_heater.

github-actions[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.