Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Local sensor stops updating when HA was restarted #136

Closed
2 of 4 tasks
Draghmar opened this issue Aug 5, 2022 · 7 comments
Closed
2 of 4 tasks

Bug: Local sensor stops updating when HA was restarted #136

Draghmar opened this issue Aug 5, 2022 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@Draghmar
Copy link

Draghmar commented Aug 5, 2022

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):

  • Installed via installer
  • Installed manually
  • 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
@LAB02-Admin
Copy link
Member

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.

@Draghmar
Copy link
Author

Draghmar commented Aug 8, 2022

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.

@LAB02-Admin
Copy link
Member

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.

@Draghmar
Copy link
Author

Draghmar commented Aug 8, 2022

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.

@LAB02-Admin LAB02-Admin self-assigned this Aug 14, 2022
@LAB02-Admin LAB02-Admin added the bug Something isn't working label Aug 14, 2022
@ITensEI
Copy link

ITensEI commented Sep 26, 2022

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

@rEs-84
Copy link

rEs-84 commented Oct 16, 2022

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

@LAB02-Admin
Copy link
Member

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

Closing this one to keep it in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants