Sensor not available

Read up the change logs to get an idea and pay special attention to the breaking changes. In case you didn’t updated for a year you need to read all release notes for that time frame to know :brain:

The broken lines on graph when device went to sleep is a longstanding problem. I’m not sure how it worked for you before. Had you set the mqtt to be retained?
I’ve been using the different birth/Will topic solution for 2 1/2 years. Perhaps your device ran continuously for > 1 year. My device ran fine until 2 months ago until the box filled up with water and took out the battery charger. New charger and some sealant will hopefully see it through a few more years.

Had you set the mqtt to be retained?

You mean here: MQTT Client Component — ESPHome ?
No, not that I’m aware of.

Perhaps your device ran continuously for > 1 year.

kind of. The battery ran flat two times and I updated the device a few times in between.

I updated esphome regulary. I also read the changelog and especially the breaking changes. As far as In can remember there was nothing where I would say this broke the device.
So I guess I was just lucky for a year and then something else changed and broke it…
So far, it works with the different birth/will messages (but it worked also a few days before I changed it, so I still have no idea what’s going on :D)

This problem is back since the update to 2024.02.00 / 2024.02.01 yesterday evening:

I checked the changelog and cannot find anything that would explain this. I updated the config due to the bme280 change and flashed an update, but it is still broken.

Relevant config:

mqtt:
  broker: !secret mqtt_broker
  username: !secret mqtt_user
  password: !secret mqtt_pasword
  discovery: False
  discovery_retain: False
  birth_message:
    topic: $devicename/status
    payload: online
  will_message:
    topic: $devicename/statusdisabled
    payload: offline
  on_message:
    - topic: $devicename/ota_mode
      payload: 'ON'
      then:
        - deep_sleep.prevent: deep_sleep_1
        - mqtt.publish:
            topic: $devicename/ota_mode_status
            payload: "active"
    - topic: $devicename/sleep_mode
      payload: 'ON'
      then:
        - mqtt.publish:
            topic: $devicename/ota_mode_status
            payload: "disabled"
        - deep_sleep.enter: deep_sleep_1

sensor:
  - platform: bme280_i2c
    temperature:
      name: "${devicename}_temperature"
    pressure:
      name: "${devicename}_pressure"
    humidity:
      name: "${devicename}_humidity"
    address: 0x76

Would be nice to check ESPHome device logs, by using, f.e.

logger:
  - level: DEBUG

sure, here you go:

[10:29:48][I][logger:359]: Log initialized
[10:29:48][C][status_led:014]: Setting up Status LED...
[10:29:48][C][ota:483]: There have been 0 suspected unsuccessful boot attempts.
[10:29:48][D][esp32.preferences:114]: Saving 1 preferences to flash...
[10:29:48][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[10:29:48][I][app:029]: Running through setup()...
[10:29:48][I][i2c.arduino:183]: Performing I2C bus recovery
[10:29:48][D][text_sensor:064]: 'outdoor_version': Sending state '2024.2.1 Feb 29 2024, 10:28:42'
[10:29:48][C][bme280.sensor:091]: Setting up BME280...
[10:29:48][C][adc:047]: Setting up ADC 'outdoor_voltage'...
[10:29:48][C][adc:093]: ADC 'outdoor_voltage' setup finished!
[10:29:48][C][wifi:038]: Setting up WiFi...
[10:29:48][C][wifi:051]: Starting WiFi...
[10:29:48][C][wifi:052]:   Local MAC: 30:AE:A4:07:DA:A4
[10:29:48][I][wifi:304]: WiFi Connecting to '[redacted]'...
[10:29:48][D][sensor:094]: 'outdoor_battery': Sending state nan % with 1 decimals of accuracy
[10:29:48][D][sensor:094]: 'outdoor_voltage': Sending state 4.02439 V with 2 decimals of accuracy
[10:29:49][D][sensor:094]: 'outdoor_temperature': Sending state 22.09309 °C with 1 decimals of accuracy
[10:29:49][D][sensor:094]: 'outdoor_pressure': Sending state 1000.19525 hPa with 1 decimals of accuracy
[10:29:49][D][sensor:094]: 'outdoor_humidity': Sending state 56.56543 % with 1 decimals of accuracy
[10:29:50][D][sensor:094]: 'outdoor_battery': Sending state 91.00000 % with 1 decimals of accuracy
[10:29:50][D][sensor:094]: 'outdoor_voltage': Sending state 4.02032 V with 2 decimals of accuracy
[10:29:52][D][sensor:094]: 'outdoor_battery': Sending state 90.00000 % with 1 decimals of accuracy
[10:29:52][D][sensor:094]: 'outdoor_voltage': Sending state 4.01624 V with 2 decimals of accuracy
[10:29:53][I][wifi:591]: WiFi Connected!
[10:29:53][C][wifi:409]:   Local MAC: 30:AE:A4:07:DA:A4
[10:29:53][C][wifi:414]:   SSID: [redacted]
[10:29:53][C][wifi:415]:   IP Address: 172.20.1.12
[10:29:53][C][wifi:417]:   BSSID: [redacted]
[10:29:53][C][wifi:418]:   Hostname: 'outdoor'
[10:29:53][C][wifi:420]:   Signal strength: -44 dB ▂▄▆█
[10:29:53][C][wifi:424]:   Channel: 1
[10:29:53][C][wifi:425]:   Subnet: 255.255.0.0
[10:29:53][C][wifi:426]:   Gateway: 172.20.0.1
[10:29:53][C][wifi:427]:   DNS1: 0.0.0.0
[10:29:53][C][wifi:428]:   DNS2: 0.0.0.0
[10:29:53][D][wifi:742]: Saved fast_connect wifi settings
[10:29:53][C][ota:096]: Over-The-Air Updates:
[10:29:53][C][ota:097]:   Address: 172.20.1.12:3232
[10:29:53][C][ota:100]:   Using Password.
[10:29:53][C][ota:103]:   OTA version: 2.
[10:29:53][C][api:025]: Setting up Home Assistant API server...
[10:29:53][C][mqtt:037]: Setting up MQTT...
[10:29:53][I][mqtt:234]: Connecting to MQTT...
[10:29:53][I][mqtt:274]: MQTT Connected!
[10:29:53][C][deep_sleep:037]: Setting up Deep Sleep...
[10:29:53][I][deep_sleep:042]: Scheduling Deep Sleep to start in 10000 ms
[10:29:53][I][app:062]: setup() finished successfully!
[10:29:53][D][sensor:094]: 'outdoor_rssi': Sending state -43.00000 dBm with 0 decimals of accuracy
[10:29:53][D][text_sensor:064]: 'outdoor_bssid': Sending state '[redacted]'
[10:29:53][D][text_sensor:064]: 'outdoor_ip': Sending state '172.20.1.12'
[10:29:53][I][app:102]: ESPHome version 2024.2.1 compiled on Feb 29 2024, 10:28:42
[10:29:53][C][status_led:019]: Status LED:
[10:29:53][C][status_led:020]:   Pin: GPIO5
[10:29:53][C][wifi:577]: WiFi:
[10:29:53][C][wifi:409]:   Local MAC: 30:AE:A4:07:DA:A4
[10:29:53][C][wifi:414]:   SSID: [redacted]
[10:29:53][C][wifi:415]:   IP Address: 172.20.1.12
[10:29:53][C][wifi:417]:   BSSID: [redacted]
[10:29:53][C][wifi:418]:   Hostname: 'outdoor'
[10:29:53][C][wifi:420]:   Signal strength: -44 dB ▂▄▆█
[10:29:53][C][wifi:424]:   Channel: 1
[10:29:53][C][wifi:425]:   Subnet: 255.255.0.0
[10:29:53][C][wifi:426]:   Gateway: 172.20.0.1
[10:29:53][C][wifi:427]:   DNS1: 0.0.0.0
[10:29:53][C][wifi:428]:   DNS2: 0.0.0.0
[10:29:53][C][logger:447]: Logger:
[10:29:53][C][logger:448]:   Level: DEBUG
[10:29:53][C][logger:449]:   Log Baud Rate: 115200
[10:29:53][C][logger:451]:   Hardware UART: UART0
[10:29:53][C][i2c.arduino:053]: I2C Bus:
[10:29:53][C][i2c.arduino:054]:   SDA Pin: GPIO21
[10:29:53][C][i2c.arduino:055]:   SCL Pin: GPIO22
[10:29:53][C][i2c.arduino:056]:   Frequency: 10000 Hz
[10:29:53][C][i2c.arduino:059]:   Recovery: bus successfully recovered
[10:29:53][C][template.sensor:022]: Template Sensor 'outdoor_battery'
[10:29:53][C][template.sensor:022]:   Device Class: 'battery'
[10:29:53][C][template.sensor:022]:   State Class: 'measurement'
[10:29:53][C][template.sensor:022]:   Unit of Measurement: '%'
[10:29:53][C][template.sensor:022]:   Accuracy Decimals: 1
[10:29:53][C][template.sensor:023]:   Update Interval: 2.0s
[10:29:54][C][version.text_sensor:021]: Version Text Sensor 'outdoor_version'
[10:29:54][C][version.text_sensor:021]:   Icon: 'mdi:new-box'
[10:29:54][C][bme280_i2c.sensor:025]:   Address: 0x76
[10:29:54][C][bme280.sensor:182]: BME280:
[10:29:54][C][bme280.sensor:194]:   IIR Filter: OFF
[10:29:54][C][bme280.sensor:195]:   Update Interval: 60.0s
[10:29:54][C][bme280.sensor:197]:   Temperature 'outdoor_temperature'
[10:29:54][C][bme280.sensor:197]:     Device Class: 'temperature'
[10:29:54][C][bme280.sensor:197]:     State Class: 'measurement'
[10:29:54][C][bme280.sensor:197]:     Unit of Measurement: '°C'
[10:29:54][C][bme280.sensor:197]:     Accuracy Decimals: 1
[10:29:54][C][bme280.sensor:198]:     Oversampling: 16x
[10:29:54][C][bme280.sensor:199]:   Pressure 'outdoor_pressure'
[10:29:54][C][bme280.sensor:199]:     Device Class: 'pressure'
[10:29:54][C][bme280.sensor:199]:     State Class: 'measurement'
[10:29:54][C][bme280.sensor:199]:     Unit of Measurement: 'hPa'
[10:29:54][C][bme280.sensor:199]:     Accuracy Decimals: 1
[10:29:54][C][bme280.sensor:200]:     Oversampling: 16x
[10:29:54][C][bme280.sensor:201]:   Humidity 'outdoor_humidity'
[10:29:54][C][bme280.sensor:201]:     Device Class: 'humidity'
[10:29:54][C][bme280.sensor:201]:     State Class: 'measurement'
[10:29:54][C][bme280.sensor:201]:     Unit of Measurement: '%'
[10:29:54][C][bme280.sensor:201]:     Accuracy Decimals: 1
[10:29:54][C][bme280.sensor:202]:     Oversampling: 16x
[10:29:54][C][adc:097]: ADC Sensor 'outdoor_voltage'
[10:29:54][C][adc:097]:   Device Class: 'voltage'
[10:29:54][C][adc:097]:   State Class: 'measurement'
[10:29:54][C][adc:097]:   Unit of Measurement: 'V'
[10:29:54][C][adc:097]:   Accuracy Decimals: 2
[10:29:54][C][adc:107]:   Pin: GPIO34
[10:29:54][C][adc:122]:  Attenuation: 11db
[10:29:54][C][adc:142]:   Update Interval: 2.0s
[10:29:54][C][shutdown.switch:068]: Shutdown Switch 'outdoor_shutdown'
[10:29:54][C][shutdown.switch:070]:   Icon: 'mdi:power'
[10:29:54][C][shutdown.switch:091]:   Restore Mode: always OFF
[10:29:54][D][sensor:094]: 'outdoor_battery': Sending state 90.00000 % with 1 decimals of accuracy
[10:29:54][D][api:102]: Accepted 172.20.0.5
[10:29:54][W][component:214]: Component api took a long time for an operation (0.05 s).
[10:29:54][W][component:215]: Components should block for at most 20-30ms.
[10:29:54][C][restart:068]: Restart Switch 'outdoor_restart'
[10:29:54][C][restart:070]:   Icon: 'mdi:restart'
[10:29:54][C][restart:091]:   Restore Mode: always OFF
[10:29:54][C][mdns:115]: mDNS:
[10:29:54][C][mdns:116]:   Hostname: outdoor
[10:29:54][D][api.connection:1121]: Home Assistant 2024.2.5 (172.20.0.5): Connected successfully
[10:29:54][C][ota:096]: Over-The-Air Updates:
[10:29:54][C][ota:097]:   Address: 172.20.1.12:3232
[10:29:54][C][ota:100]:   Using Password.
[10:29:54][C][ota:103]:   OTA version: 2.
[10:29:54][C][api:139]: API Server:
[10:29:54][C][api:140]:   Address: 172.20.1.12:6053
[10:29:54][C][api:142]:   Using noise encryption: YES
[10:29:54][C][mqtt:133]: MQTT:
[10:29:54][C][mqtt:135]:   Server Address: 172.20.0.5:1883 (172.20.0.5)
[10:29:54][C][mqtt:136]:   Username: [redacted]
[10:29:54][C][mqtt:137]:   Client ID: [redacted]
[10:29:54][C][mqtt:142]:   Topic Prefix: 'outdoor'
[10:29:54][C][mqtt:144]:   Log Topic: 'outdoor/debug'
[10:29:54][D][sensor:094]: 'outdoor_voltage': Sending state 4.02032 V with 2 decimals of accuracy
[10:29:54][C][wifi_info:009]: WifiInfo IPAddress 'outdoor_ip'
[10:29:54][C][wifi_info:012]: WifiInfo BSSID 'outdoor_bssid'
[10:29:54][C][wifi_signal.sensor:009]: WiFi Signal 'outdoor_rssi'
[10:29:54][C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[10:29:54][C][wifi_signal.sensor:009]:   State Class: 'measurement'
[10:29:54][C][wifi_signal.sensor:009]:   Unit of Measurement: 'dBm'
[10:29:54][C][wifi_signal.sensor:009]:   Accuracy Decimals: 0
[10:29:54][C][mqtt:668]: MQTT Message Trigger:
[10:29:54][C][mqtt:669]:   Topic: 'outdoor/ota_mode'
[10:29:54][C][mqtt:670]:   QoS: 0
[10:29:54][C][mqtt.text_sensor:023]: MQTT Text Sensor 'outdoor_ip':
[10:29:54][C][mqtt.text_sensor:024]:   State Topic: 'outdoor/sensor/outdoor_ip/state'
[10:29:54][C][mqtt.text_sensor:023]: MQTT Text Sensor 'outdoor_bssid':
[10:29:54][C][mqtt.text_sensor:024]:   State Topic: 'outdoor/sensor/outdoor_bssid/state'
[10:29:54][C][mqtt.text_sensor:023]: MQTT Text Sensor 'outdoor_version':
[10:29:54][C][mqtt.text_sensor:024]:   State Topic: 'outdoor/sensor/outdoor_version/state'
[10:29:54][C][mqtt.sensor:028]: MQTT Sensor 'outdoor_rssi':
[10:29:54][C][mqtt.sensor:032]:   State Topic: 'outdoor/sensor/outdoor_rssi/state'
[10:29:54][C][mqtt.sensor:028]: MQTT Sensor 'outdoor_temperature':
[10:29:54][C][mqtt.sensor:032]:   State Topic: 'outdoor/sensor/outdoor_temperature/state'
[10:29:54][C][mqtt.sensor:028]: MQTT Sensor 'outdoor_pressure':
[10:29:54][C][mqtt.sensor:032]:   State Topic: 'outdoor/sensor/outdoor_pressure/state'
[10:29:54][C][mqtt.sensor:028]: MQTT Sensor 'outdoor_humidity':
[10:29:54][C][mqtt.sensor:032]:   State Topic: 'outdoor/sensor/outdoor_humidity/state'
[10:29:54][C][mqtt.sensor:028]: MQTT Sensor 'outdoor_voltage':
[10:29:54][C][mqtt.sensor:032]:   State Topic: 'outdoor/sensor/outdoor_voltage/state'
[10:29:54][C][mqtt.sensor:028]: MQTT Sensor 'outdoor_battery':
[10:29:54][C][mqtt.sensor:032]:   State Topic: 'outdoor/sensor/outdoor_battery/state'
[10:29:54][C][mqtt.switch:041]: MQTT Switch 'outdoor_shutdown': 
[10:29:54][C][mqtt.switch:042]:   State Topic: 'outdoor/switch/outdoor_shutdown/state'
[10:29:54][C][mqtt.switch:042]:   Command Topic: 'outdoor/switch/outdoor_shutdown/command'
[10:29:54][C][mqtt.switch:041]: MQTT Switch 'outdoor_restart': 
[10:29:54][C][mqtt.switch:042]:   State Topic: 'outdoor/switch/outdoor_restart/state'
[10:29:54][C][mqtt.switch:042]:   Command Topic: 'outdoor/switch/outdoor_restart/command'
[10:29:55][C][mqtt:668]: MQTT Message Trigger:
[10:29:55][C][mqtt:669]:   Topic: 'outdoor/sleep_mode'
[10:29:55][C][mqtt:670]:   QoS: 0
[10:29:55][C][deep_sleep:049]: Setting up Deep Sleep...
[10:29:55][C][deep_sleep:052]:   Sleep Duration: 900000 ms
[10:29:55][C][deep_sleep:055]:   Run Duration: 10000 ms
[10:29:56][D][sensor:094]: 'outdoor_battery': Sending state 90.00000 % with 1 decimals of accuracy
[10:29:56][D][sensor:094]: 'outdoor_voltage': Sending state 4.03663 V with 2 decimals of accuracy
[10:29:58][D][sensor:094]: 'outdoor_battery': Sending state 92.00000 % with 1 decimals of accuracy
[10:29:58][D][sensor:094]: 'outdoor_voltage': Sending state 4.03663 V with 2 decimals of accuracy
[10:30:00][D][sensor:094]: 'outdoor_battery': Sending state 92.00000 % with 1 decimals of accuracy
[10:30:00][D][sensor:094]: 'outdoor_voltage': Sending state 4.03255 V with 2 decimals of accuracy
[10:30:02][D][sensor:094]: 'outdoor_battery': Sending state 92.00000 % with 1 decimals of accuracy
[10:30:02][D][sensor:094]: 'outdoor_voltage': Sending state 4.02439 V with 2 decimals of accuracy
[10:30:03][I][deep_sleep:117]: Beginning Deep Sleep
[10:30:03][I][deep_sleep:119]: Sleeping for 900000000us
[10:30:03][D][esp32.preferences:114]: Saving 2 preferences to flash...
[10:30:03][D][esp32.preferences:143]: Saving 2 preferences to flash: 0 cached, 2 written, 0 failed

IMHO stopped logging too early - see no entries (except configuration) regarding BME sensor.
Collect log for longer period to have at least 2-3 successefull readings from BME.

hmm okay, so right now I have the following settings:

deep_sleep:
  id: deep_sleep_1
  run_duration: 10s
  sleep_duration: 15min

could it be that since 2024.2.0 10s of wake time are not enough? Is that a result of the change of the sensor?

I’ll change it to 30s and see how that goes…
I also added a update_interval: 2s to the BME, maybe that was something changed as well? Before that worked great but it seems to prevent multiple sensor updates now?

I see now several of

[11:53:30][D][sensor:094]: 'outdoor_battery': Sending state 96.00000 % with 1 decimals of accuracy
[11:53:30][D][sensor:094]: 'outdoor_voltage': Sending state 4.05497 V with 2 decimals of accuracy
[11:53:31][D][sensor:094]: 'outdoor_temperature': Sending state 27.64074 °C with 1 decimals of accuracy
[11:53:31][D][sensor:094]: 'outdoor_pressure': Sending state 999.16827 hPa with 1 decimals of accuracy
[11:53:31][D][sensor:094]: 'outdoor_humidity': Sending state 39.40723 % with 1 decimals of accuracy
[11:53:31][W][component:214]: Component bme280_base.sensor took a long time for an operation (0.05 s).
[11:53:31][W][component:215]: Components should block for at most 20-30ms.

but the behaviour that the sensor is not available when in deep sleep is the same.

Perhaps you just haven’t shown it , but it would be a quicker connect if you used a fixed ip address.

It is already on static IP - but could that actually be an issue? There are values transmitted via MQTT and I can see them in HA, however the device is marked as unavailable.

Check that dhcp hasnt handed that address out to another device or you haven’t assigned it twice.

it is not assigned twice. But again, how can this be a problem?
And it started to behave that way exactly after the update. I also updated HAOS and core though, but I also checked the changelogs for those and could not find anything that relates to that IMHO.

- platform: bme280_ic2

    address: 0x76

    internal: true

    update_interval: 2s

    temperature:

      name: "Temperature"

      id: bme280_temperature

   on_value:

      - mqtt.publish:

          topic: /sensors/whatever/bmetemperature

          payload: id(bme280_temperature).state

What about this for a workaround. You make the bmp sensor internal then only publish on_value to mqtt. You would have to create the sensor in mqtt on Ha. Ignore my indentation errors as im typing on my phone.

Consider trying this first.

Thanks for posting your configuration in the other thread (Battery powered: How to read sensors on boot, send them once, and immediately enter deep sleep? - #10 by Spiro) - mine does not look too different… Thus I do not understand what’s the problem.
I’ll adopt this early deep sleep and possibly also powering the bme via a gpio, that is a neat addition, thanks!

I just did but still the same…

I cannot get this to work either :confused:

The values are send correctly to mqtt but the device always appears as “not available” afterwards.

eh wait, this is weird! As i reverted the changes I made with the manual mqtt.publish, the temperature sensor came back (I tested it only for that entity).
Seems like re-installing the sensors in HA might resolve this issue? Is there a way to trigger this somehow without actually deleting the entities?

edit: okay, I think I got it. I used “Clean MQTT” on the device and reinstalled it.
It seems like all entities still got the historic data but are now longer unavailable!

indeed, but it works again since I ran the Clean MQTT :man_shrugging:

Well… 2024.3.1 and the problem is back yet again. :frowning:

image

you can cleary see when I installed the update…

This time Clean MQTT did not help at all, however it also prints no topics there… just “connected to MQTT broker” and thats it.

In the log I see now several warnings like these:

[06:36:28][W][wifi:152]: Warning set: unspecified
[06:36:50][W][mqtt:152]: Warning set: unspecified
[06:36:50][W][wifi:165]: Warning cleared
[06:36:50][W][api:152]: Warning set: unspecified
[06:36:51][W][mqtt:165]: Warning cleared
[06:36:53][W][api:165]: Warning cleared

What are these? Are these related to the problem?

EDIT: what however helps is to comment out all sensors in the yml, install it, then add everything back in and install it again. Now, the sensors are back and do not show unavailable.

Now I’m lost… I fixed the issue caused by the esphome update by flashing a firmware without sensors and re-flashing it with the sensors again.
However, now the sensor turned into unavailable state without any updates of hacore, esphome or anything else… What the heck?

There must be a reason for the sensor to turn unavailable, does anyone has an idea what is happening?

Installing home assistant OS 12.2 fixed it: the sensor is now available again.

I now really have no clue why it works again :confused: Maybe all it needed was a full reboot? (I restarted HA several times in between, which would not fix it…)