Mqtt light going offline without reason

Thank you Petro for instant replay

what do you mean by a user? a role devices authenticated against when connecting to mqtt?
Then yes: all devices, HA and mqtt explorer uses the same login/pass in order to connect to mqtt (actually it’s HA user since I’m using Mosquito integration)

Should I use more mqtt connection roles?
If so I’m curious why. Are there any technical limitations?

Well, you run into issues if you use the same user to log into MQTT explorer and what HA uses to log into it as well. Make separate users. I vaguely remember having this problem years ago and that was the solution IIRC

1 Like

So i have a petro log in and a hass log in basically

petro → mqtt explorer
hass → well you know

1 Like

will try it definitively. thanks

1 Like

It seems it wasn’t the reason. And it getting to be more and more painful.
Today morning 4 Shelly sensors went unavailable.

When writting this post, one of them reappeared on its own. I confirmed with second one, that value in sensor can reappear if sensor sends new value to mqtt.

There is no exact information when exaclty those sensors got unavailable. I can quess it from graphs


You can see that the data ends at 8:11:46 with 22.41 temp. Don’t know however where this value came from. There is no such value in logs.

I could expect, that this is the point when device went unavailable (but still don’t understand value change at this point). Other devices looks the same. For some graph is interrupted in the middle of the line (without value change) others introduces inexisting reading breaking graph line at the same time. BTW all 4 sensors disappered at different times (8:11, 8:22, 9:20, 10:20)

Here is config of the entities

######
# KITCHEN SENSORS
# - temperature
# - humidity
# - battery
######
- platform: mqtt
  name: "Kitchen Temperature"
  state_topic: "shellies/temp-kitchen/sensor/temperature"
  json_attributes_topic: "shellies/temp-kitchen/sensor/temperature"
  unit_of_measurement: "°C"
  force_update: true
  device_class: temperature
  expire_after: 86400
- platform: mqtt
  name: "Kitchen Humidity"
  state_topic: "shellies/temp-kitchen/sensor/humidity"
  json_attributes_topic: "shellies/temp-kitchen/sensor/humidity"
  unit_of_measurement: "%"
  payload_available: "true"
  payload_not_available: "false"
  force_update: true
  device_class: humidity
  expire_after: 86400
- platform: mqtt
  name: "Kitchen bttry"
  state_topic: "shellies/temp-kitchen/sensor/battery"
  unit_of_measurement: "%"
  payload_available: "true"
  payload_not_available: "false"
  force_update: true
  device_class: battery
  expire_after: 86400

At this point it can be anything. broken expire_after? Currently set to 24h, but you can see that data is changing more often. Some mem leak (see unlogged temp change). Really have no idea.

Probably I’m will enable debug log for core. But not sure it will provide any help.

As mentioned already values get back with new data reported by sensors or by reloading of “manually configured mqtt entities”

Install MQTT Explorer and let it run. See if you have gaps there too.

Thanks, I had it running whole yesterday. It shows no anomalies for mentioned sensors.

Since back then I had mqtt logging set to debug, but recently I had to restart HA and forgot to change logging level again.
Today I’ve lost one sensor (out of three comming from single device).

As you can see only battery_mqtt (which is mqtt sensor) and battery (which is template sensor inheriting
from the first one) are unavailable.

How can I retrieve exact time of turning sensor unavailable? History doesn’t show that
What I know it happened about 5 hours ago. But when exactly?

I’m starting to think it’s some serious while hidden problem with HA stability.

I succeeded to debug mqtt.
Here is appearance of unavailable state recorded during today:
image
image

As you can see, sensor was in unavailable state between 15:19 and 16:54
Here is log from core (please don’t mind the typo)


You clearly see events at 14:49 and 16:54. The last one recovered the sensor from unavailable state). But there is nothing logged for this topic at 15:19 (the only messages around 15:19:55 are other mqtt ones related to zigbee2mqtt and octoprint, nothing system/core related)

The same case for another sensor, but different hours:
image
image


mqqt events at 8:28 and 16:39. Unavailable between 13:31 and 16:39

Interesting is, all values from single device are turn unavailable at the same time (no mqtt event logged for this). They however uses the same mqtt topic and the same expire_time. An issue with expiration evaluation potentially could be the reason (it would manifest by shooting down all 3 entities at the same time)
Here is configuration of set of them

######
# BARUS ROOM SENSORS
# - temperature
# - humidity
# - battery
######
- platform: mqtt
  name: "BarusRoom Temperature"
  state_topic: "shellies/temp-barusroom/sensor/temperature"
  json_attributes_topic: "shellies/temp-barusroom/sensor/temperature"
  unit_of_measurement: "°C"
  force_update: true
  device_class: temperature
  expire_after: 86400
- platform: mqtt
  name: "BarusRoom Humidity"
  state_topic: "shellies/temp-barusroom/sensor/humidity"
  json_attributes_topic: "shellies/temp-barusroom/sensor/humidity"
  unit_of_measurement: "%"
  payload_available: "true"
  payload_not_available: "false"
  force_update: true
  device_class: humidity
  expire_after: 86400
- platform: mqtt
  name: "BarusRoom bttry"
  state_topic: "shellies/temp-barusroom/sensor/battery"
  unit_of_measurement: "%"
  payload_available: "true"
  payload_not_available: "false"
  force_update: true
  device_class: battery
  expire_after: 86400

- platform: template
  sensors:
    barusroom_temp_battery:
      friendly_name: "BarusRoom Sensor Battery"
      device_class: battery
      unit_of_measurement: "%"
      value_template: "{{ states('sensor.barusroom_bttry') }}"

So… Something shuts down all those 4 sensors at the same time.
Different devices encounters the same issue at different time.
HA sensors recover when devices report next values to mqtt.

Any idea how to debug the reason why sensor turns into unavailable state?

Today, I noticed one of my AC powered switches disappear (BTW the one this thread has started with)

look at this:
History shows it turned unavailable yesterdayand remains till now.
But MQTT debug log shows events from today (even a few mins ago)


Since yesterday I have debug enabled for core too. The image above shows grep for entrance word. So no such line in core.debug

Any ideas WTF is going on? It’s not only about I lost entity. But it is not able to recover itself with data still comming from MQTT.
How can I debug this issue more? I suspect even with this evidence, there is no chance to get help from devs.

found reason of report above. But rootcause is still unknow:

You may see, online topic turned false.
Curious why… I suspect only the device writes there. but why the device would report offline while it’s online all the time?

Bug in Shelly

It’s about Shelly Motion (bit different HW). But it might originate from from the same logic implemented in the code base. So yes, it could be.
I already asked for that behavior on Shelly FB. Will see.

I have to check logs for battery powered devices (a few posts above). Going offline is something normal for them. It might be different case from Shelly2.5

Thank you for the feedback

Check your discovery configuration and remove the online/offline and see if the issue goes away

I’m not using discovery. Manually configured entities instead.
Yeah… idea of removing availability check came across my mind. Thanks

Manual configuration uses the same code as discovery. The yaml is just passed to the objects instead of the discovery info. So it’s a 1 to 1 comp in that regards

Yes. I assume that. Thank you.

So, looks like I’m facing two different issues. Still waiting on asnwer from Shelly about AC powered device.

But I just encountered again issue with battery powered devices. All my battery Shelly H&T turned unavailable recently.
Main differences between them and mentioned above AC powerd devices are:

  • those devices have no availability topic set
  • those devices has expiration timeout to 24h

What happened yesterday is, I restarted HA at 12:51, then was reloading manually configured mqtt entities multiple times during a day.

Here is what found in logs:

cat ./home-assistant.log | grep -E "temp-kitchen|kitchen_temperature" | grep -v table
2021-11-20 16:30:16 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to shellies/temp-kitchen/sensor/temperature, mid: 5779
2021-11-20 16:30:16 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/temperature (retained): b'22.20'
2021-11-20 16:30:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=None, new_state=<state sensor.kitchen_temperature=22.20; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-20T16:30:16.100838+01:00>>
2021-11-20 16:30:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=22.20; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-20T16:30:16.100838+01:00>, new_state=<state sensor.kitchen_temperature=22.20; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-20T16:30:16.134957+01:00>>
2021-11-20 16:30:16 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to shellies/temp-kitchen/sensor/humidity, mid: 5780
2021-11-20 16:30:16 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/humidity (retained): b'54.0'
2021-11-21 02:28:08 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/temperature: b'22.20'
2021-11-21 02:28:08 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=22.20; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-20T16:30:16.134957+01:00>, new_state=<state sensor.kitchen_temperature=22.20; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T02:28:08.155853+01:00>>

2021-11-21 02:28:08 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/humidity: b'52.5'
2021-11-21 02:28:08 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/battery: b'100'
2021-11-21 11:04:13 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=22.20; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T02:28:08.155853+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T11:04:13.148924+01:00>>
2021-11-21 12:51:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T11:04:13.148924+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T12:51:16.969906+01:00>>
2021-11-21 12:54:34 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T12:51:16.969906+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T12:54:34.166672+01:00>>
2021-11-21 14:07:50 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T12:54:34.166672+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:07:50.729207+01:00>>
2021-11-21 14:19:19 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/temperature: b'22.45'
2021-11-21 14:19:19 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:07:50.729207+01:00>, new_state=<state sensor.kitchen_temperature=22.45; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:19:19.935248+01:00>>
2021-11-21 14:19:19 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/humidity: b'54.5'
2021-11-21 14:19:19 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/battery: b'100'
2021-11-21 14:21:20 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=22.45; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:19:19.935248+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:21:20.422972+01:00>>
2021-11-21 14:25:08 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/temperature: b'22.83'
2021-11-21 14:25:08 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:21:20.422972+01:00>, new_state=<state sensor.kitchen_temperature=22.83; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:25:08.503409+01:00>>
2021-11-21 14:25:08 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/humidity: b'54.0'
2021-11-21 14:25:08 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-kitchen/sensor/battery: b'100'
2021-11-21 14:27:31 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=22.83; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:25:08.503409+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:27:31.002663+01:00>>
2021-11-21 14:33:31 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:27:31.002663+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:33:31.424737+01:00>>
2021-11-21 14:36:52 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:33:31.424737+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:36:52.829243+01:00>>
2021-11-21 14:39:58 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:36:52.829243+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:39:58.600221+01:00>>
2021-11-21 14:41:59 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:39:58.600221+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:41:59.945812+01:00>>
2021-11-21 14:49:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.kitchen_temperature, old_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:41:59.945812+01:00>, new_state=<state sensor.kitchen_temperature=unavailable; unit_of_measurement=°C, friendly_name=Kitchen Temperature, device_class=temperature @ 2021-11-21T14:49:01.481926+01:00>>

In short,
at 2:28 most recent temperature value has been received from mqtt and set in entity
at 11:04 for some reason this sensor has been refreshed with the same values
at 12:51 temperature sensor went unavailable,
at 14:19 temperature is set to valid value because is refreshed from mqtt
at 14:21 it turns unavailable again without reason
at 14:25 temperature is set to valid value because is refreshed from mqtt
at 14:27 it turns unavailable again without reason
Reason of next sensor updates are not known for me but are executed roughly every 3 minutes not changing the state.

Because I make a grep for mqtt topic but for temperature sensor name, there are no log lines shown for humidity and battery sensor of this device. But both are unavailable too.

Here is similar log for other sensor. The behavior and timing are the same:

2021-11-20 16:30:15 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to shellies/temp-pcroom/sensor/humidity, mid: 5774
2021-11-20 16:30:15 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=25.50; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-20T16:30:15.919348+01:00>, new_state=<state sensor.pcroom_temperature=25.50; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-20T16:30:15.924397+01:00>>
2021-11-20 16:30:15 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-pcroom/sensor/humidity (retained): b'50.0'
2021-11-20 18:53:15 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-pcroom/sensor/temperature: b'24.50'
2021-11-20 18:53:15 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=25.50; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-20T16:30:15.924397+01:00>, new_state=<state sensor.pcroom_temperature=24.50; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-20T18:53:15.162819+01:00>>
2021-11-20 18:53:15 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-pcroom/sensor/humidity: b'50.0'
2021-11-20 18:53:15 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-pcroom/sensor/battery: b'100'
2021-11-21 03:57:42 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-pcroom/sensor/temperature: b'23.50'
2021-11-21 03:57:42 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=24.50; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-20T18:53:15.162819+01:00>, new_state=<state sensor.pcroom_temperature=23.50; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T03:57:42.206813+01:00>>
2021-11-21 03:57:42 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-pcroom/sensor/humidity: b'49.5'
2021-11-21 03:57:42 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-pcroom/sensor/battery: b'100'
2021-11-21 11:20:29 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-pcroom/sensor/temperature: b'24.50'
2021-11-21 11:20:29 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=23.50; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T03:57:42.206813+01:00>, new_state=<state sensor.pcroom_temperature=24.50; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T11:20:29.190627+01:00>>
2021-11-21 11:20:29 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-pcroom/sensor/humidity: b'50.0'
2021-11-21 11:20:29 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on shellies/temp-pcroom/sensor/battery: b'100'
2021-11-21 11:41:07 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=24.50; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T11:20:29.190627+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T11:41:07.293522+01:00>>
2021-11-21 12:51:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T11:41:07.293522+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T12:51:16.779165+01:00>>
2021-11-21 13:47:07 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T12:51:16.779165+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T13:47:07.439301+01:00>>
2021-11-21 14:07:50 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T13:47:07.439301+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:07:50.398601+01:00>>
2021-11-21 14:21:20 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:07:50.398601+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:21:20.243528+01:00>>
2021-11-21 14:27:30 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:21:20.243528+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:27:30.825043+01:00>>
2021-11-21 14:33:31 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:27:30.825043+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:33:31.245656+01:00>>
2021-11-21 14:35:34 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:33:31.245656+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:35:34.314269+01:00>>
2021-11-21 14:39:58 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:35:34.314269+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:39:58.214383+01:00>>
2021-11-21 14:41:59 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:39:58.214383+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:41:59.662461+01:00>>
2021-11-21 14:49:01 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.pcroom_temperature, old_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:41:59.662461+01:00>, new_state=<state sensor.pcroom_temperature=unavailable; unit_of_measurement=°C, friendly_name=PCroom Temperature, device_class=temperature @ 2021-11-21T14:49:01.204123+01:00>>

And here are configuration of the sensor:

######
# KITCHEN SENSORS
# - temperature
# - humidity
# - battery
######
- platform: mqtt
  name: "Kitchen Temperature"
  state_topic: "shellies/temp-kitchen/sensor/temperature"
  json_attributes_topic: "shellies/temp-kitchen/sensor/temperature"
  unit_of_measurement: "°C"
  force_update: true
  device_class: temperature
  expire_after: 86400
- platform: mqtt
  name: "Kitchen Humidity"
  state_topic: "shellies/temp-kitchen/sensor/humidity"
  json_attributes_topic: "shellies/temp-kitchen/sensor/humidity"
  unit_of_measurement: "%"
  payload_available: "true"
  payload_not_available: "false"
  force_update: true
  device_class: humidity
  expire_after: 86400
- platform: mqtt
  name: "Kitchen bttry"
  state_topic: "shellies/temp-kitchen/sensor/battery"
  unit_of_measurement: "%"
  payload_available: "true"
  payload_not_available: "false"
  force_update: true
  device_class: battery
  expire_after: 86400

- platform: template
  sensors:
    kitchen_temp_battery:
      friendly_name: "Kitchen Sensor Battery"
      device_class: battery
      unit_of_measurement: "%"
      value_template: "{{ states('sensor.kitchen_bttry') }}"

(just noticed payload_available/payload_not_available set for 2 of those sensors. but it should make no difference since topic is not defined. Also temperature sensor has no those settings but fails too)

Just thinking if it has something to do with HA restart (see the same time, but one day later, one day = 24h) and possibly with subsequent mqtt entities reloading.

I have other battery powered shelly sensors (DW) but those have no expiration set. And they remain available.

Do you think it’s enough to raise issue on GitHub?

I reported expiration issue to github. Due to no any response, I decided to remove expiration from entities. Tbh not having this feature is less problematic than loosing sensors every few days.

Anyway what is more important I found that after removing expiration lines from entity configs and reloading manually configured mqtt entities, next day I lost those entities again.
It confirms that something is really screwed around this.
Then I restarted HA and since this time no more issues.

Maybe worth to say again that I’m talking about battery powered devices (see config in prev posts) so there is no way they turn unavailable. Also in order to make sure there are no invalid data causing this issue I created test sensors based on the same mqtt topics with use of NR. So I’m pretty sure there is an issue in HA core.

BTW, can you help somehow with pushing this git issue forward? 3 weeks without any reaction. Not sure if it’s expected in case of such a crucial component like mqtt.

Issues like this could take months to identify before a fix can be applied. The fact that you can’t identify it yourself and you have the issue shows that anyone else without the issue is going to have even more difficulty identifying the problem. Best advice I can give is to be patient and keep the issue alive by responding in it.