Open coling opened 2 months ago
Hey there @home-assistant/cloud, mind taking a look at this issue as it has been labeled with an integration (google_assistant
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
google_assistant documentation google_assistant source (message by IssueLinks)
I'm really not a Python coder and nor do I understand any of the HA code or internal architecture but looking at the code here, I see EXECUTE command appears to be queued asynchronously in the hass bus and then the state of the entities in question are read in a few lines below. Could the problem be that the code is just not waiting for the async requests to complete (albeit with a timeout) before returning the response, thus the current state is being returned?
Execution actually occur here: https://github.com/home-assistant/core/blob/d530fd31b063c9b3784ac2378e9eb5848dd03b87/homeassistant/components/google_assistant/smart_home.py#L258
That is blocking. Your pontoon light might not block and update its state on turn on. What integration is providing that light?
So.. here is the smoking gun: https://github.com/home-assistant/core/blob/d530fd31b063c9b3784ac2378e9eb5848dd03b87/homeassistant/components/google_assistant/trait.py#L359
When we have state reporting turned on, we dont block on execution.
And here is the change that introduced the behavior: https://github.com/home-assistant/core/commit/814a742518e88609e318de7ad0fa378d085bfa73
Thanks so much for digging into it @elupus!
I've done a bit of poking and turned of the report_state in my config and sync'ed devices (confirming that willReportState:False is sent). I can see in my logs that I no longer call reportStateAndNotification but my response to the EXECUTE intent to turn the light on is still showing the incorrect state in it's response. This response is sent 4 hundredths of a second after the message, which is very fast to make the blocking call, but my initial logs do have the response 1 hundredth of a second later so it's technically 4x slower now 😆 - anyway can't really tell from the outside if that signifies a blocking call or not. I'll see if I can enable debug logging for my light and see if it shows up inbetween the request and response.
As per your original comment, this could be related to the specific integration (the pontoon lights are technically an ESPHome based Wifi plug socket) so will try with some other lights via Zigbee and see if I get the same behaviour.
Thanks again for the input so far.
Either way, the spec does I linked to suggest the call should be fulfilled before the response - not sure if state reporting should negate that (even if, in theory at least, state reporting should make automatic updates to states)
Managed to do a bit of testing. With some Zigbee lights, and report_state:False, Google Home app is now behaving as expected 👍🏼
Some virtual switch groups in HA don't work properly (as they should go off when all lights are off and on when any light is on but due to states not being pushed, they don't correctly reflect their state until a QUERY is issued and responded to) - but I guess that's expected with report_state:false. It's probably not a good idea to expose these groups to GH anyway - probably best to do the grouping in GH itself.
I'll double check if turning report_state:true back on again makes these now perfectly working Zigbee devices misbehave again due to the old state being sent (I guess it might be racey generally, but I'm sure I observed them misbehaving previously).
OK, I've turned report_state:true back on again and managed to break my Zigbee light state in the Google Home app.
It's odd however. Lot's of cycles and it seemed to behave initially, despite the same behaviour as the pontoon lights with the state response being initially incorrect (as expected due to the async handling). The odd thing is that, initially,despite the incorrect state, the Google Home UI does not flip back like it does with my ESPHome/pontoon lights. Because I have a virtual switch, the report state for that is also included if it changes state, and indeed I see the update in Google Home App's UI in response to that state being reported - the delay is sufficient that I know it takes a while for it all to propagate so the fact that it doesn't flip back like the ESPHome/pontoon lights is just really odd.
However, after playing for a while, and playing with the pontoon lights too, these lights started to behave the same way again. It's almost like the reportState is getting ignored. I honestly cannot explain it.
It would be nice to allow for sync responses separate from the report_state variable to allow further investigation. Perhaps a new config entry could be added to tweak that? Can default to the inverse of report_state?
I did a drive by patch to separate the blocking out from the report_state config.
I'm not a great python coder and I have no dev env to setup and build HA nor do I have an easy way to run that (run it via a docker container, so this very much is a drive by patch.
I've no idea if I've done the config handling correctly or if the default value handling is correct (monkey see, monkey do approach!), but if you think it's a good idea to allow this, it perhaps saves a bit of time implementing.
Happy to turn it into a pull request albeit unable to test.
I came to see if there was already a report as I am having the same trouble with state not being reported to Google Home. So if I turn on a switch on Google Home, then a little later turn it off in Home Assistant UI, the switch still shows as on in Google Home. I do of course have Enable State Reporting set to Enabled. This is all via standard UI, no custom coding.
So if I turn on a switch on Google Home, then a little later turn it off in Home Assistant UI, the switch still shows as on in Google Home. I do of course have Enable State Reporting set to Enabled.
If you close, then reopen Google Home (or switch tabs internally if on a phone - not sure how to do on a Hub), then this should trigger a QUERY and thus update the state. Do you see this same behaviour?
I have found that regardless of the state reporting calls being sent, that Google Home doesn't update it's UIs. Doubt this can be a Home Assistant problem, unless there are some nuances of the API that are incorrect, but it's still super frustrating.
(Just FYI, I've updated the title to avoid the use of the word "report" as this "reporting" state is technically a different operation to the bit I'm specifically questioning in this report)
So if I turn on a switch on Google Home, then a little later turn it off in Home Assistant UI, the switch still shows as on in Google Home. I do of course have Enable State Reporting set to Enabled.
If you close, then reopen Google Home (or switch tabs internally if on a phone - not sure how to do on a Hub), then this should trigger a QUERY and thus update the state. Do you see this same behaviour?
I have found that regardless of the state reporting calls being sent, that Google Home doesn't update it's UIs. Doubt this can be a Home Assistant problem, unless there are some nuances of the API that are incorrect, but it's still super frustrating.
Well this is weird. Been struggling with this for over a day, and just posting here appears to have fixed it. That and I just installed the latest update to HA Core... Hmmm Ok thanks, I hope it stays fixed.
Well this is weird. Been struggling with this for over a day, and just posting here appears to have fixed it. That and I just installed the latest update to HA Core... Hmmm Ok thanks, I hope it stays fixed.
When hammering Google Home App for my testing above with report_state: true, I did find, after a while, that it seemed to stop responding to the data in the reportStateAndNotification call. I was able to test this with a virtual light group which was synced to Google. It was correctly updated for a while, but eventually it just seemed to stop seeing the data. I know HA was still sending the API calls and I know from logs in GCP that there were not specific errors with those calls - sadly likely very hard to then debug as to why it never made it into updates as reflected in the Google Home App. So perhaps it'll work for a while for you but it might ultimately just stop too. Think that is a related, but separate, issue to this one tho'.
FWIW, I found time to be able to test this change and confirmed all permutations of configuration were behaving as expected. Pull request submitted.
The problem
I've integrated Google Assistant with my own Action/Project etc. including Local Fulfilment with report_state:true in my configuration.
According to the Homegraph docs, after an EXECUTE command to e.g. turn a light on:
Your fulfillment should process each command, transmit it to the corresponding device, and return the new state in the EXECUTE response.
According to my logs, the response appears to be supplying the current state, not the new state-post-execution/fulfillment.
The logs do show that subsequent HomeGraph updates via reportStateAndNotification API does update the state, but this doesn't appear to help the Google Home App on my phone.
The issue is as follows:
All in all this is really disconcerting.
I note that people on the Community have reported this kind of issue before, and suggested various workarounds such as an automation to trigger a sync. This doesn't seem to be the correct approach as the sync operation doesn't actually include the necessary state information. While experimenting with these solutions, I found it didn't help and only when a query came in and the appropriate response was given was there any update. I'm not sure why the resportStateAndNotification calls are not sufficient here - As far as I'm aware, there is no easy way to trigger a reportStateAndNotification update manually e.g. after a delay to see if this would help update the Google Home UI.
For some reason, all of my Local Fulfillment Requests come from my Google Hub rather than my phone, despite me interacting with the Google Home app on my phone. I'm not sure if this is relevant.
Anyway, log snippets below with annotations.
What version of Home Assistant Core has the issue?
core-2024.9.1
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Container
Integration causing the issue
Google Assistant
Link to integration documentation on our website
https://www.home-assistant.io/integrations/google_assistant/
Diagnostics information
No response
Example YAML snippet
Anything in the logs that might be useful for us?
Additional information
No response