Closed dof250 closed 3 years ago
Hey there @cgtobi, @jjlawren, mind taking a look at this issue as it has been labeled with an integration (sonos
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
sonos documentation sonos source (message by IssueLinks)
This should already be resolved in 2021.8.1+ (https://github.com/home-assistant/core/pull/53985). What specific version are you running?
That’s strange. I’m running 2021.8.8.
Do you have warnings/errors in your logs during the first ~1m after startup for the Sonos integration?
I'm getting one error after the restart I just did, but i don't think its relevant. See below: 2021-08-22 16:06:48 ERROR (MainThread) [homeassistant] Error doing job: Task was destroyed but it is pending! Below some debug logging. Maybe its usefull for you? https://pastebin.com/L04cSKdc
All looks normal at first glance. I see 5 speakers each in a group by themselves. Is this not what you're expecting or seeing reflected in the state attributes?
Sorry, tested it a little stupid. They where not grouped before Core restart. Dumb mistake from me. Now i've group "Badkamer" with "Kantoor" and did a Core restart. The group data is again lost with the restart. Below the logs: https://pastebin.com/XR7LQ6HE
I cannot reproduce that behavior. All groups remain in place after restarts.
Any chance you have automations that regroup speakers?
Nope, no automations are run on start. I can reproduce as follows.
So "Kantoor" shows just empty, while "Badkamer" shows only itself. When I remove them from the group and add them again its working as expected. and shows again: sonos_group:
I still can't reproduce when speakers are either idle or playing. Anything else that might be unique in your setup?
Not that I can think off. All my automations are in Node-Red so I tried to disable Node-Red completely and still gives me the same issue. I've restarted 8 times in a row now. Every other restart the data is there...
Doesn't make any sense...
I believe there's a race condition on startup if the coordinator is available and the grouped speakers are not when the groups are initially built. Will need to look more later.
@dof250 are you able to test a potential fix using a custom component? I still cannot reproduce the problem you're experiencing.
cd /config/custom_components
git clone --branch core-55008 https://github.com/jjlawren/sonos_custom_component.git sonos
Just tried this with below results after core restarts.
So it seems a bit better, but still some times it's not filled... Don't know if this makes any sense to you.
Can you please ensure the custom component is loading properly in the logs?
Do you see the "Regrouped
Below the latest logs, says it found a custom integration sonos. I do get a lot of the "Error doing job" errors now. Don't know if this has to do with the custom component?
2021-08-23 22:25:44 WARNING (SyncWorker_4) [homeassistant.loader] We found a custom integration sonos which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant 2021-08-23 22:25:44 WARNING (MainThread) [homeassistant.config] Key whitelist_external_dirs has been replaced with allowlist_external_dirs. Please update your config 2021-08-23 22:25:45 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140554601461552] Received invalid command: energy/info 2021-08-23 22:25:48 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Thuis' for forecast_solar integration not ready yet: Rate limit for API calls reached. (error None); Retrying in background 2021-08-23 22:25:48 ERROR (MainThread) [homeassistant] Error doing job: Unclosed client session 2021-08-23 22:25:48 ERROR (MainThread) [homeassistant] Error doing job: Unclosed connector 2021-08-23 22:25:50 WARNING (MainThread) [homeassistant.components.select] Platform netatmo not ready yet: None; Retrying in background in 30 seconds 2021-08-23 22:25:51 WARNING (MainThread) [homeassistant.components.esphome] Can't connect to ESPHome API for None (192.168.10.118): Error connecting to ('192.168.10.118', 6053): [Errno 113] Connect call failed ('192.168.10.118', 6053) 2021-08-23 22:25:52 WARNING (MainThread) [homeassistant.components.webhook] Received message for unregistered webhook 9b0e5682f2fe3159433c7612cb205b2afb8ed0146e6777ea8b0d707bf18e7eef from 192.168.1.40 2021-08-23 22:26:02 ERROR (SyncWorker_7) [homeassistant] Error doing job: Unclosed client session 2021-08-23 22:26:02 ERROR (SyncWorker_7) [homeassistant] Error doing job: Unclosed connector
Those errors are not related to using the custom component. Do you see the "Regrouped" debug messages after startup? Some were missing before.
I don't see any debug logging for the sonos integration anymore. Should I edit my logger config now it's using the custom component? Below is what's configured now.
logger: default: warning logs: homeassistant.components.sonos: debug pysonos: debug
Ah yes, you'll need to add custom_components.sonos: debug
I've created two logs. This is the one where group data is filled correctly: https://pastebin.com/DtzfNk0v
And this is the one where it's empty: https://pastebin.com/AcAN5T9T
While I think about this I added some more debug. You can update the custom component like this:
cd /config/custom_components/sonos
git pull
If you can reproduce the problem and share logs maybe something will jump out.
This is the working one: https://pastebin.com/c5qsjj5t
And this is the non working: https://pastebin.com/pmzZ9kF0
Okay, confirms the theory. Now just need to find a clean way to address it.
Pushed a potential fix, but I want to think about this a bit more even if it works.
Did a git pull and around 10 core restarts. Every time the group data is filled now so thats great! I do however see a difference in restarts. Whenever it does a "good" restart. ALL data is filled. So I also see current playing song, position etcetera. Sometimes that data is missing, but whenever thats the case it now does include the group data. So my particular issue is solved, but maybe its some usefull information to you. This is the log when that data is missing: https://pastebin.com/cF8SYCzt
Is the group data accurate, though? For example, the latest logs imply that Kantoor's group is updated properly to['media_player.badkamer', 'media_player.kantoor']
but Badkamer's group remains as ['media_player.badkamer']
.
I was able to reproduce the issue with more complex groups. The custom component now has a different approach which seems more reliable. Can you give it another shot?
Just tried again. Did 10 Core restarts and every time all data was filled correctly. Tried multiple group configurations and everything worked every time.
Submitted a fix to core, thanks for reporting and providing so much helpful context and information. 👍
The problem
Whenever i'm restarting Home Assistant Core the previous group data gets lost.
For me it's pretty easy to reproduce. Play sound in one room, then join another room. When looking at "data -> attributes -> sonos_group" it contains the speakers. Then restart Core and look at that data again. Now the sonos_group attribute is empty.
This messes up my automations with automatic grouping and leaving.
What is version of Home Assistant Core has the issue?
core-2021.8
What was the last working version of Home Assistant Core?
core-2021.7
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Sonos
Link to integration documentation on our website
https://www.home-assistant.io/integrations/sonos/
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response