WebRTC icon indicating copy to clipboard operation
WebRTC copied to clipboard

Is there a way to not have WebRTC in the home assistant web dashboard permanently block the machine sleeping / screen turning off?

Open AdrianGarside opened this issue 1 year ago • 8 comments

However, that permanently blocks my machine sleeping or the screen turning off when I view the dashboard, even if I then navigate away. I have to ctrl-F5 to release the lock:

'powercfg /requests' shows:

EXECUTION: [PROCESS] \Device\HarddiskVolume3\Program Files (x86)\Microsoft\Edge\Application\msedge.exe WebRTC has active PeerConnections

I have background: true set to get the much more responsive display and to mitigate reliability issues with the Bambu Lab X1 RTSP feed but removing that doesn't appear to change the behavior.

Repro:

  1. View WebRTC in HA dashboard in Edge
  2. Run (elevated) 'powercfg /requests' to see the lock taken.
  3. Navigate way
  4. Run (elevated) 'powercfg /requests' to see the lock is still taken.
  5. F5 to refresh the web page.
  6. Now the lock is gone.

AdrianGarside avatar Nov 26 '23 19:11 AdrianGarside

Background video preventing PC from sleeping. You already have answered on your question.

AlexxIT avatar Nov 26 '23 19:11 AlexxIT

Turning it off didn't change the behavior. Edit - retested that and it did actually fix it - just not always immediately.

But given I like to sit with my web dashboard showing I'm still interested if there's a way to have WebRTC never block the machine sleeping. Otherwise I'll have to remember to navigate away every time I leave my PC.

AdrianGarside avatar Nov 26 '23 19:11 AdrianGarside

Rendering via WebRTC also adds audio even though the source rstp feed doesn't have that:

[DRIVER] Realtek High Definition Audio (HDAUDIO\FUNC_01&VEN_10EC&DEV_0B00&SUBSYS_1458A0CF&REV_1000\5&307ed9b2&0&0001) An audio stream is currently in use.

Looks like 'media: video' might have helped with that.

AdrianGarside avatar Nov 26 '23 19:11 AdrianGarside

If I'm reading the docs right, 'EXECUTION' just means the process won't be suspend - not clear if it blocks sleep.

But audio playback definitely does. With audio disabled the listed blocker changed to: DISPLAY: [PROCESS] \Device\HarddiskVolume3\Program Files (x86)\Microsoft\Edge\Application\msedge.exe Video Wake Lock

'powercfg /requestsoverride PROCESS msedge.exe DISPLAY'

permanently blocks edge from preventing the display turning off/machine sleeping. Which is overkill but given I've had embedded web page ads cause the same problem I'm actually ok with this...

So fingers crossed 'EXECUTION' which seemingly can't be specified successfully as a requestoverride doesn't block display/sleep.

Edit: Spoke too soon - the DISPLAY block on Edge doesn't seem to work. It's still listed as a request and I think that means it's still blocking. Will have to wait until my machine should have turned off it's display to see.

AdrianGarside avatar Nov 26 '23 20:11 AdrianGarside

'powercfg /requestsoverride PROCESS msedge.exe DISPLAY EXECUTION' was needed and worked. DISPLAY to allow the screen to turn off. EXECUTION to allow the machine to go to sleep. Possibly this will break some pages that expect to be able to do work while in the background to refresh content though :(

I don't know if the video playback tech in the browser used here lets you turn off the blocks for screen turn off / machine sleep? If not, this is probably the best I can get.

AdrianGarside avatar Nov 28 '23 20:11 AdrianGarside

I know it's not the best solution, but MSE mode allows sleep, so I suggest you this configuration:

background: false
muted: true
mode: mse,hls,mjpeg
media: video,audio

Suxsem avatar Dec 18 '23 09:12 Suxsem

I definitely need the background: true. It's the main thing mitigating the fact that Bambu Printer's stream is buggy. Only the first connection is (mostly) reliable. If that drops later the reconnect will almost certainly fail. So by keeping that initial connection permanently live regardless of being viewed it makes the stream mostly reliable. For the most part it now only stops working when I restart my production home assistant instance (which restarts webrtc/go2rtc) - I have to restart the printer after to get a working video stream again.

AdrianGarside avatar Jan 07 '24 19:01 AdrianGarside

I just reconfigured to have go2rtc running in it's own docker so that I can restart my home assistant without breaking the video stream. But I haven't been able to work out from the documentation:

  • How do I stop webrtc spinning up its embedded go2rtc instance in the unlikely case that the home assistant docker starts up before/faster than the go2rtc one? I just started the go2rtc docker first and that's now running and has taken over the ports. Is it sufficient that I specified a server in the webrtc custom card?
  • Is there a way to configure go2rtc itself to keep the connection to the Bambu stream alive even with no clients? Or do I need to ensure at least one of my production/test home assistant instances has viewed the feed (via go2rtc) in order for the background:true setting to keep the go2rtc connection and proxy feed live?

AdrianGarside avatar Jan 07 '24 21:01 AdrianGarside