core: Error handling WebRTC offer: Nest API error: Error from API: 500: INTERNAL: Internal error encountered.: Internal Server Error

The problem

As reported in https://github.com/home-assistant/core/issues/82528 Nest camera devices are still broken on Homeassistant using Firefox. Tested with both a Nest Video Doorbell (Battery) and a Nest Cam with floodlight (wired) I do not think it is a setup issue with my homeassistant instance, as other browsers display the streams fine, and I am less inclined to think it’s a Firefox issue considering that the camera streams display correctly at https://home.google.com

What version of Home Assistant Core has the issue?

core-2023.11.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Google Nest

Link to integration documentation on our website

https://www.home-assistant.io/integrations/nest

Diagnostics information

config_entry-nest-d853b7634c9fc3f40e86a489f8cd0bbf.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

I have debug logs containing the POST requests, but I am unsure what secrets are contained within those so will hold off posting those for now.

2023-11-13 15:59:19.350 ERROR (MainThread) [homeassistant.components.camera] Error handling WebRTC offer: Nest API error: Error from API: 500: INTERNAL: Internal error encountered.: Internal Server Error
2023-11-13 15:59:20.028 ERROR (MainThread) [homeassistant.components.camera] Error handling WebRTC offer: Nest API error: Error from API: 500: INTERNAL: Internal error encountered.: Internal Server Error

Additional information

Picture Entity Card is my primary method of displaying the feeds on dashboard, but the error also occurs when viewing the individual devices in the settings menu.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 23 (12 by maintainers)

Most upvoted comments

This is definitely still a problem.

There hasn’t been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Both pull requests have been raised. Hope to see it soon.

@allenporter After some time, I get it done. There are multiple problems in between. 1. Nest: 500: INTERNAL: Internal error The root cause is because firefox may provide ICE candidate with empty string in event.candidate.candidate instead of empty event.candidate object. image Ref: https://stackoverflow.com/questions/67993490/webrtc-empty-string-in-icecandidate I fixed this one by adding a conditional checking in the iceResolver within ha-web-rtc-player.ts _startWebRtc method

        if (event.candidate.candidate !== "") {
          candidates += `a=${event.candidate.candidate}\r\n`;
        }

However, it is not the end. Then, googleapi is able to provide answer sdp. and then there is error from Firefox

Answer tried to set recv when offer did not set send

2. Firefox: Answer tried to set recv when offer did not set send In both audio and video, recvonly is set in the request sdp. However, the answer sdp is having sendrecv which is incorrect. (it should be sendonly) It may be the googleapi bug, but in order to workaround, I have updated the code camera_traits.py generate_web_rtc_stream method

        obj._cmd = self.cmd
        obj.answer_sdp = obj.answer_sdp.replace("a=sendrecv", "a=sendonly")

It is still not the end, even the answer sdp was processed by Firefox, there is still the error in about:webrtc page e.g.

Error parsing attribute: candidate: 1 udp 2113939711 2001:4860:4864:4::119 19305 typ host generation 0

3. Firefox: Error parsing attribute after comparing the answer sdp from home.google.com which works fine in firefox I found that, the ice candidate attribute is missing the foundation field Ref: https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate/foundation

Google Home’s answer ice candidate:

a=candidate:12345010 1 udp 2113939711 2001:4860:4864:4::119 19305 typ host generation 0

Home Assistant’s answer ice candidate:

a=candidate: 1 udp 2113939711 2001:4860:4864:4::119 19305 typ host generation 0

Obviously, right after “candidate:” it is missing the foundation field Again, it may be the googleapi bug, but in order to workaround, I have updated the code camera_traits.py generate_web_rtc_stream method

import re
...
        obj._cmd = self.cmd
        obj.answer_sdp = obj.answer_sdp.replace("a=sendrecv", "a=sendonly")
        index = 1
        def incRet(i):
            i+=1
            return i
        if "mozilla" in offer_sdp:
          obj.answer_sdp = re.subn('candidate: ([0-9]+) ([a-z]+) ([0-9]+)', lambda m: 'candidate:'+str(incRet(index))+' '+m.group(1)+' '+m.group(2)+' '+m.group(3), obj.answer_sdp)
        return obj

P.S. after I added the foundation, then chrome will fail… I have no idea why, so, I just add the “mozilla” checking


Side track a bit I am using Docker to run the Home Assistant in Synology NAS. If we want to do some development work, but unable to setup devcontainer (like me using windows) then, it is quite easy to do some tricks to run the modified code.

  1. frontend you can build our frontend based on official development guide. But you don’t need to copy whole repo into the NAS or device who runs the docker. You can just copy frontend/hass_frontend into the config volume (which will be mounted to /config) So, you will be able to see /config/frontend/hass_frontend insides the HA container. Then, just update the configuration.yaml to
frontend:
  development_repo: /config/frontend/

  1. python scripts Like me, I have updated camera_traits.py I can copy it into the device who runs the docker. then create a direct mount point to replace it. my docker run command will be
docker run --restart always -d --name homeassistant -v /volume1/docker/volumes/docker_home_assistant:/config -v /volume1/docker/volumes/home_assistant_hotdeploy/camera_traits.py:/usr/local/lib/python3.12/site-packages/google_nest_sdm/camera_traits.py -e TZ=Australia/Melbourne --net=host  homeassistant/home-assistant:stable

@allenporter Please comment if these changes are valid If you or anyone could raise the pull requests for below, it would be great. camera_traits.py in https://github.com/allenporter/python-google-nest-sdm.git ha-web-rtc-player.ts in https://github.com/home-assistant/frontend.git

Thank you @jonnynch for your awesome contributions 👍🏼 very much appreciated, will work with you to get these merged and released for the next home assistant releases (maybe we can sneak into a patch)

I spent a week or two working on this when building the initial integration with WebRTC and wasn’t able to figure it out. I personally don’t use firefox, so I stopped spending time on it and it has not been a priority for me personally since then.

I am not sure what the issue is, and what part of the firefox SDP offer is causing a problem. I also reached out to the nest sdm folks and they didn’t have any new insights.

Contributions are welcome to fix this, but i currently am not prioritizing it in full disclosure given then time I already spent on it.