[Integration] Android TV live cam video streams in a Picture in Picture triggered by motion detection. AKA video-doorbell

I believe this is because of the source you are trying to play. I had this with ONE of my devices and not the other 5 cameras i push.

I don’t think so because the same device works fine on Fire TV devices I mentioned. I’m assuming that the default video player for Tivimate and PiPUp are the same on my other Android boxes and cannot handle multiple videos concurrently. They are somehow different players (or a player that can handle multiple videos concurrently) on the Fire devices.

Thanks for this - a nice automated solution.

Maybe. I had only one source that stopped my playing video in kodi. I don’t use Tivimate. An easy way to test if its the source or the app is play a different source like:

rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4

Followed the write up by @seanblanchfield and suffered from stuttering streams with the webrtc link.

Updated the PipUp APK to allow HTTP requests (Releases · desertblade/PiPup · GitHub). This APK allows using Frigate’s local mpjeg streams and other API endpoints, which all load near instantly. This build does not include the WebView changes which is not needed if using Local Frigate streams.

If you have a IoT subnet be sure to create a rule that will allow the IoT device to communicate with Frigate.

Doorbell Notification Automation

- alias: Doorbell Person Alerts
  trigger:
    platform: mqtt
    topic: frigate/events
  condition:
    - "{{states('media_player.firetv_cube') != 'off'}}"
    - '{{ (as_timestamp(now()) - as_timestamp(states.automation.doorbell_person_alerts.attributes.last_triggered, 0 ) | int > 60)}}'
    - "{{ trigger.payload_json['after']['label'] == 'person' }}"
    - "{{ trigger.payload_json['after']['camera'] == 'doorbell' }}"
  action:
  # Make sure PipUp is running
    - service: androidtv.adb_command                                                                      
      data:                                                                                     
        entity_id: media_player.firetv_cube                   
        command: ps -ef | grep -v grep | grep pipup || am start nl.rogro82.pipup/.MainActivity
  # This will exit the screensaver
    - service: androidtv.adb_command
      data:
        entity_id: media_player.firetv_cube
        command: input keyevent KEYCODE_WAKEUP
    - service: rest_command.pipup_url_on_tv
      data:
        title: Front Door
        message: Live Stream of Doorbell
        width: 360
        height: 200
        url: 'http://192.168.X.XX:5000/api/doorbell'
5 Likes

Hi All,

I’m totally stumped with this. I’ve read through the whole thread and all the links and still can’t get this to work on my Shield TV. I’m getting nothing in my logs to show an error. One this I did have to change was:

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

to

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

As otherwise I was getting the following error:

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

I figured the link_id must be too long so change it and that error disappeared.

When I run the script I can go to the trace and find the generated link with the ID in it. I can copy and paste that into a browser and the video plays fine. I just have nothing showing on the Shield TV - and I have checked that PipUP is running.

I have tried the curl command from HA and that doesn’t give me the popup either. I just get everything printed on the command line:

PopupProps(duration=30, position=TopRight, backgroundColor=#ffffff, title=Your awesome title, titleSize=20.0, titleColor=#0066cc, message=What ever you want to say... do it here..., messageSize=14.0, messageColor=#000000, media=Image(uri=https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png, width=480))

Any tips on things to check?

I started getting this too. Which is weird since I’ve had this code running for a long time. Anyone know why?

And its even called out here:

Found out my issue: There are different versions of the apk available:
The original apk from Rogro82 - This one didn’t work for me.
The forked version by gmcmicken to support web-javascript - This is the one worked.
The forked version by desertblade to support http/Frigate - This one didn’t work for me.

I followed seanblanchfield excellent instructions & have gotten this to mostly work on my Sony XBR-65X930E TV. When the TV is playing from the cable box, it works as expected. However, if I’m playing a Playstation 4 game & the PIPUp activates, it causes the TV’s Android OS to reboot. I’m just wondering if anyone else has experienced this or better yet, a way to fix this? All video sources (cable, PS4 & a few others) go to a Yamaha AVR then, one HDMI cable from the AVR to the TV. As a work around, my automation currently doesn’t trigger if the PS4 is on. Thanks for any insight into this.

The version I made doesn’t have web/javascript. I struggled with getting the remote stream to work reliably.

I ended up using Frigates local MJPEG streams which loaded faster and had smoother playback than using the javascript WebRTC player.

You might be able to add a condition checking the state of the android box before calling the command.

Posted an updated APK and created a quick write up how I am using it.

1 Like

Thanks @DesertBlade. Your new APK (v1.1) works for me with JavaScript and WebRTC.

1 Like

Awesome to hear! Since my latest build I have not had an issue with the white video box loading. Hoping to spend some more time and see if there are any other tweaks to help with performance.

1 Like

Thank you. Your option is working. Everything that was before you didn’t work, but your version worked perfectly

1 Like

I have created detailed instructions on how to install and run PiPup, this can help those who do not understand how to do it.

2 Likes

I found out that with AgentDVR you can output a video stream to a PiPup. I added to this post how it can be done. AgentDVR is a smart server with built-in WebRTC. Video stream without delay

I’ve just followed Sean’s guide and managed to get pipup responding from a curl command.

When triggering the script I get an error page instead of the video feed: (net::ERR_CLEARTEXT_NOT_PERMITTED)

I’m trying to use a Nest Hello doorbell (An old wired RTSP device) which is added with the Nest integration:

rest_commands.yaml:

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.86.200: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) }}
        }
      }
    }

scipts.yaml

display_front_door_pip_popup_on_tv:
  alias: Display Driveway 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.front_door
      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.86.50:8123/webrtc/embed?url={{ link_id }}&webrtc=false

Any idea what I’ve done wrong?

what pipup apk are you using? typically pipup requires HTTPS ( [DesertBlade’s supposedly disables that but I haven’t tested personally). The error message though is telling you exactly that. I’m guessing you have the other pipup installed.

Make sure you installed this one:

EDIT: Just tested @DesertBlade’s apk and yes it works without https through go2rtc just fine. That helps so I don’t need to expose my cameras externally through a https address. Thanks.

1 Like

@calisro Is correct. I believe in Android 8 apps had to use HTTPS url calls. If the application needed regular HTTP traffic they had to set android:usesCleartextTraffic=“true” in the manifest.

Anything that is being accessed over the public internet should have a signed certificate and you should be using HTTPS. If everything is staying internal to your network your risk of exposure is low and setting up self-signed certificates locally is usually more hassle than its worth.

I didn’t realize Nest now has local streams. I helped built NST Manager for Smartthings years ago and the workaround then was to make your stream public.