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?