HASS.Agent icon indicating copy to clipboard operation
HASS.Agent copied to clipboard

Bug: Local sensor stops updating when HA was restarted

Open Draghmar opened this issue 2 years ago • 4 comments

Describe the bug I'm using local sensor to track the state of the PC: LastSystemStateChange. I've noticed that when HA restarts for some reason (on update for example), that sensor becomes unknown and doesn't come back unless I click button store and activate sensors, which probably forces update at that moment. It looks like lost connection sets the unknown state but after HA gets back online, there is no sync of states happening.

To Reproduce Steps to reproduce the behavior:

  1. Set Local Sensor in HASS.Agent.
  2. Make sure that HA has proper value for that sensor.
  3. Restart HA.
  4. Check the state in HA and HASS.Agent - they should be different.

Expected behavior HASS.Agent should know if the connection to the HA was lost and after getting it back online it should update the sensors to make sure they are in sync.

Misc info (please complete the following information):

  • Windows build: Win10 Pro - 21H2, 19044.1865
  • Windows' UI language: PL
  • HASS.Agent version: 2022.12.0

Please check what's applicable (multiple answers possible):

  • [x] Installed via installer
  • [ ] Installed manually
  • [x] Problem occurs in HASS.Agent
  • [ ] Problem occurs in Satellite Service

Additional context Add any other context about the problem here.

Logs There are nothing important in the logs regarding this issue:

2022-08-05 08:41:45.092 +02:00 [INF] [SETTINGS] Config storage path: C:\Users\---\AppData\Roaming\LAB02 Research\HASS.Agent\config
2022-08-05 08:41:45.816 +02:00 [INF] [SETTINGS] Configuration loaded
2022-08-05 08:41:45.825 +02:00 [INF] [LOCALIZATION] Selected UI culture: [en] English
2022-08-05 08:41:46.921 +02:00 [INF] [SETTINGS_QUICKACTIONS] Config not found, no entities loaded
2022-08-05 08:41:47.082 +02:00 [INF] [SETTINGS_COMMANDS] Loaded 4 entities
2022-08-05 08:41:47.109 +02:00 [INF] [SETTINGS_SENSORS] Loaded 1 entities
2022-08-05 08:41:47.127 +02:00 [INF] [NOTIFIER] Disabled
2022-08-05 08:41:47.127 +02:00 [INF] [MEDIA] Disabled
2022-08-05 08:41:47.129 +02:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2022-08-05 08:41:47.339 +02:00 [INF] [MQTT] Identifying as device: EARTH
2022-08-05 08:41:47.437 +02:00 [INF] [SERVICE] Local install path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\
2022-08-05 08:41:47.446 +02:00 [INF] [LOCALAPI] Initializing ..
2022-08-05 08:41:47.447 +02:00 [INF] [MQTT] Connecting ..
2022-08-05 08:41:48.507 +02:00 [INF] [MQTT] Connected
2022-08-05 08:41:48.694 +02:00 [INF] [HASS_API] Home Assistant version: 2022.8.0
2022-08-05 08:41:49.130 +02:00 [INF] [HASS_API] System connected with ---
2022-08-05 08:41:49.540 +02:00 [INF] [MQTT] Initial registration completed
2022-08-05 08:41:51.473 +02:00 [INF] [LOCALAPI] listening on port 5115
2022-08-05 09:04:41.775 +02:00 [INF] [HASS_API] Home Assistant version: 2022.8.1
2022-08-05 09:04:41.776 +02:00 [INF] [HASS_API] Server recovered from failed state
2022-08-05 09:09:02.934 +02:00 [INF] [SETTINGS] Configuration stored

Draghmar avatar Aug 05 '22 07:08 Draghmar

Hey @Draghmar,

That's because its state doesn't change so hass.agent doesn't publish it. The underlying system is scheduled to be improved, but until then you can create a PublishAllSensors command to force resending all states. If you set it to trigger after a HA restart, you should be ok for now.

LAB02-Admin avatar Aug 08 '22 12:08 LAB02-Admin

Oh, ok. I thought HASS.Agent has some persistent connection and knows immediately that HA is gone. So basically I should create automation like this, right?

alias: Force HASS.Agent sensors update after HA restarts
id: 272d3766-7ef6-4150-a16c-17dfebd682be
trigger:
- platform: homeassistant
  event: start
action:
  - service: button.press
    target:
      entity_id: button.earth_publishallsensors

Where button.earth_publishallsensors was created by HASS.Agent from PublishAllSensorsCommand as a button.

Draghmar avatar Aug 08 '22 13:08 Draghmar

It actually does know that, and it should already resend the values, but it's unreliable at the moment as you noticed heh.

Yep exactly, maybe add a delay to make sure everything has started:

  - delay:
      minutes: 2

But that might not be necessary, needs testing.

LAB02-Admin avatar Aug 08 '22 13:08 LAB02-Admin

No problem, I can live with that, knowing now what to look at. ;)

I will leave it without delaying for now and see if that works - as far I know start trigger should happen after everything has...well, started. If not I will try to use some version of wait in condition to wait for MQTT to be available.

Draghmar avatar Aug 08 '22 14:08 Draghmar

I noticed the same issue with Satellite service sensors. Probably the same problem as with local sensors

ITensEI avatar Sep 26 '22 18:09 ITensEI

i think i have this issue with the satellite service. however it doesnt seem consistent. i wake laptop from sleep, seems fine, another time its just not connected (possibly from sleep and i didnt notice). restart service and its all good.

I dont think its an issue that its not updating the last value as its not changed (so still unknown). I think it just gets disconnected (or doesnt connect).

What's the configured retry to connect to mqtt if the device is offline / or just cant connect? maybe related to Bug: MQTT disconnects before sleep, grace period unreliable #85

rEs-84 avatar Oct 16 '22 18:10 rEs-84

I've merged all tickets related to this issue into a central pinned one: [#204]

Closing this one to keep it in one place.

LAB02-Admin avatar Nov 01 '22 12:11 LAB02-Admin