A short guide for setting up TV PiP notifications (with PiPup)

Links from go2rtc do not work correctly. there is 401: Unauthorized messgae. Maybe you know how avoid it?

Does anyone else get warning and errors generate when running the script to generate the link ID to create the URL fir displaying the camera feed? Although my camera feed pops up on my android tv, I notice that when my automation runs the script, the following are logged:

Logger: homeassistant.core
Source: core.py:1253
First occurred: 11:35:57 (2 occurrences)
Last logged: 11:36:25

Error running job: <Job listen * HassJobType.Callback functools.partial(<function _forward_events_unconditional at 0x7f12838b62a0>, <bound method WebSocketHandler._send_message of <WebSocketHandler closing=False authenticated=True description=Supervisor from 172.30.32.2 (HomeAssistantSupervisor/2024.02.0 aiohttp/3.9.3 Python/3.12)>>, 86)>
OverflowError: int too big to convert

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1253, in async_fire
    job.target(event)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 132, in _forward_events_unconditional
    send_message(messages.cached_event_message(msg_id, event))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/messages.py", line 122, in cached_event_message
    _partial_cached_event_message(event)[:-1],
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/messages.py", line 138, in _partial_cached_event_message
    _message_to_json_bytes_or_none({"type": "event", "event": event.json_fragment})
                                                              ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/backports/functools.py", line 70, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 1136, in json_fragment
    return json_fragment(json_bytes(self._as_dict))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Integer exceeds 64-bit range
Logger: homeassistant.components.recorder.table_managers.event_data
Source: components/recorder/table_managers/event_data.py:42
Integration: Recorder (documentation, issues)
First occurred: 11:35:57 (2 occurrences)
Last logged: 11:36:25

Event is not JSON serializable: <Event call_service[L]: domain=webrtc, service=create_link, service_data=link_id=6787777203816264975872725917469303880736, entity=camera.front_doorbell_sub, open_limit=1, time_to_live=120>: Integer exceeds 64-bit range
Event is not JSON serializable: <Event call_service[L]: domain=webrtc, service=create_link, service_data=link_id=6120108750403071545556268576633341270480, entity=camera.front_doorbell_sub, open_limit=1, time_to_live=120>: Integer exceeds 64-bit range

How can a smaller integer value within the 64-bit range be created instead of the current integers?

I raised the above with the WEBRTC dev and the link id variable needed to be changed from:

link_id: '{% for _ in range(40) %}{{ range(10)|random }}{% endfor %}'

to

link_id: "0{% for _ in range(39) %}{{ range(10)|random }}{% endfor %}"

and this prevents the above error. @seanblanchfield It might be worth updating this code in your guide at some point if you do any additional updates in future - thanks for your immensely helpful guide by the way! Also thanks @pacjo for this guide too!

I followed the guide, everything was working for 2 days, now it’s not working anymore.

When I check my script I see a error. It looks like that the pip app is starting in the background and is not reachable. Any ideas?

I had something similar the other day, and it turned out my firestick that I use for this had crashed and wasn’t responding. I unplugged it, then restarted it, and the script worked fine again. Maybe check your android device is fully functioning, or give it a reboot and then try running the script manually and see what happens?

I run this on 2 Sony Bravia TV’s , everything works fine on the TV. I think the PIP app is not starting in the background all the time!? And because off that it’s not reachable.

As soon as a open de PIP app manual, then it’s all working again.

You can try run pip apk by command, for start via Home Assistant’s ADB integration

Yaml code:

service: androidtv.adb_command
data:
command: >-
ps -ef | grep -v grep | grep pipup || am start nl.rogro82.pipup/.MainActivity
target:
device_id: you device id

Original Source

I’m wanting to use this as a free baby monitor for the wife and I to have as an option. How do I get a toggle effect to work, I know I can set duration to 0 but how do I remove it from the screen ideally with the same zwave button

I’ve made an integration that adds some services that should make it easier to use PipUp from HA: GitHub - dannytrigo/ha-pipup: Home Assistant integration for calling PipUp

Add the repository as a custom repository in HACS, restart, then add the integration, and you should get a new service to display the notifications, without messing with rest commands/templates in your configuration.yaml.

At the moment it depends on the androidtv (ADB) integration, and it takes the media player from that as input.

2 Likes

for me on hisense google tv I used
adb install app-debug.apk
instead of
adb sideload app-debug.apk

2 Likes

When the stream starts on the television, the sound is muted.
Is there a way to enable the playback of sound? Or start the video popup unmuted?

You can try

metadata: {}
data:
  command: >-
    adb shell media volume --show --stream 3 --set 65 
target:
  entity_id: media_player.android_tv_192_168_0_186
action: androidtv.adb_command

This is script for set volume to your desire.
So you can try to add to your pip script. Just edit your entitity.

Where do I put the code, my scripts is as following:

pipup_url_on_tv:

Use with Webrtc camera as described here:

Cast or share camera stream · AlexxIT/WebRTC Wiki · GitHub

url: http://192.168.2.181:7979/notify
content_type: ‘application/json’
verify_ssl: false
method: ‘post’
timeout: 65
payload: >
{
“duration”: {{ duration | default(130) }},
“position”: {{ position | default(0) }},
“title”: “{{ title | default(‘’) }}”,
“titleColor”: “{{ titleColor | default(‘#50BFF2’) }}”,
“titleSize”: {{ titleSize | default(12) }},
“message”: “{{ message }}”,
“messageColor”: “{{ messageColor | default(‘#fbf5f5’) }}”,
“messageSize”: {{ messageSize | default(14) }},
“backgroundColor”: “{{ backgroundColor | default(‘#0f0e0e’) }}”,
“media”: {
“web”: {
“uri”: “{{ url }}”,
“width”: {{ width | default(640) }},
“height”: {{ height | default(480) }}
}
}

Before or after you call your script. Put both in one automation or script as another action.

It sets the volume but still no sound, could it be another stream then 3? Or what does that argument stream do?

just try , it’s for setting soud stream (alarm , media , call ) different number different stream

I setup this a few days ago, What I do is to send an empty notification with 1 sec. It replaces the old one and closes.

I try this a few days ago, and now It will play on top of Netlix, but regardless of the sound of the stream being muted or not, or even if the stream has no sound track, It would mute Netflix forever, the only way is to go back to Home and reopen it.
I think it has to do with the way the android WebView handles the sound focus, but I couldn’t

I can’t get video feed to show up. The pop-up shows up but I just get a “webpage not available” background where the video should be. The url in the yaml below is the webrtc link from the go2rtc dashboard for the selected camera

action: rest_command.pipup_url_on_tv
data: 
  title: test
  message: test
  position: 0
  url: http://192.168.0.244:8123/api/hassio_ingress/bR3KwJm6Vd7M9VS9wpZerveaD4vytvIo/stream.html?src=camera.backyard_sub&mode=webrtc

the pipup_url_on_tv command is from @seanblanchfield tutorial.

pipup_url_on_tv:
  # Use with Webrtc camera as described here:
  # https://github.com/AlexxIT/WebRTC/wiki/Cast-or-share-camera-stream#html-page
  url: http://192.168.0.157:7979/notify
  content_type: 'application/json'
  verify_ssl: false
  method: 'post'
  timeout: 20
  payload: >
    {
      "duration": {{ duration | default(20) }},
      "position": {{ position | default(0) }},
      "title": "{{ title | default('') }}",
      "titleColor": "{{ titleColor | default('#50BFF2') }}",
      "titleSize": {{ titleSize | default(10) }},
      "message": "{{ message }}",
      "messageColor": "{{ messageColor | default('#fbf5f5') }}",
      "messageSize": {{ messageSize | default(14) }},
      "backgroundColor": "{{ backgroundColor | default('#0f0e0e') }}",
      "media": { 
        "web": {
          "uri": "{{ url }}", 
          "width": {{ width | default(640) }},
          "height": {{ height | default(480) }}
        }
      }
    }

I simply want to display a PIP video feed and don’t quite understand why it needs to first go through the webrtc create link service or how to do that part.

Does anyone have any advice for getting the camera stream to load even quicker? My automation is working but it’s taking 3-4 seconds to load my doorbell live feed each time. I’m already running the sub stream. rtsp://username:[email protected]:554/h264Preview_01_sub.

Also, I have redundancy with my camera and would like to only keep the lightest option. I’m running HA OS and I have a reolink doorbell. I currently have my doorbell live stream accessible through the Reolink integration, Frigate, and the generic camera I just created following Danny’s guide.. If I’m already using Frigate, do I still need the go2rtc add-on?

Here is my script currently.

  alias: Display Doorbell PIP Popup on TV
  mode: single
  variables:
    link_id: '{% for _ in range(40) %}{{ range(10)|random }}{% endfor %}'
  sequence:
  - service: webrtc.create_link
    data:
      link_id: '{{ link_id }}'
      entity: camera.doorbell
      open_limit: 1
      time_to_live: 60
  - service: rest_command.pipup_url_on_tv
    data:
      title: Door
      message: Someone is at the front door
      width: 640
      height: 480
      url: http://192.168.20.137:8123/webrtc/embed?url={{ link_id }}  #HA IP Address