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

https://test.pushpinder.dev/webrtc/embed?url={{ link_id }}&mse=false works better for me

This works great but it seems the pipup server in my shield TV stops running after a while. If I rerun the adb commands it becomes accessible again. Does anyone else with a shield experiences behavior and if so how do I fix it?

I get the same with a few apps. They just crash their video, some only for ads. Great that others hace same issue. The notification always works for me though, but crashing video playing is a no go for WAF.

Didn’t find any mse/webrtc way of making that stop. Eveb just having a html5 video autoplay in pipup actually shows the issue though. So now I’m looking for a new more powerful TV than the MiTV 4S 55 I have which is quite terrible.

So for whom does this work great? And os this possible on Tizen or WebOS if I should just switch platform? A bit tired of the slow AndroidTV.

Here are a few things I’ve learned since my last post.

  1. On any Android box that has been restarted (or after a power outage), I needed to manually run the PiPUp app once before it started working.
  2. On multiple android boxes including a good expensive one I was able to get video working with nothing at the end of the url (e.g. no mse=false or webrtc=false). In this case the video will play fairly reliably (after a 2 second delay) but will stop any other video that was playing. In my case I’m using Tivimate to watch TV and only one of Tivimate OR PiPUp can play video at one time.
  3. I recently acquired a few Amazon Fire TV Stick devices and one Fire Cube. For some reason these work better. Tivimate and PiPUp can play video at the same time reliably. However, my current use case is our EZVIZ DB1 Front Video Doorbell and the delay doesn’t satisfy my WAF so I went back to a still picture when I detect motion which is much faster.

Hopefully my experience will help one of you.

BTW - I purchased the Fire Stick 4K Max devices and then loaded Google, Tivimate, PiPUp and other software I use on my previous Android boxes and these devices are way faster and rock solid. The Fire Cube is even faster and has full Alexa if you want full integration of your TV and other Home Assistant functions through the TV without pressing any button.

I do this:

          - service: androidtv.adb_command                                                                      
            data:                                                                                     
              entity_id: media_player.living_room_shield                   
              command: ps -ef | grep -v grep | grep pipup || am start nl.rogro82.pipup/.MainActivity
          - service: rest_command.pipup_video                                                                   
            data:                                                                                        
              title: Garage {{ states('cover.xxxx') }}                                           
              message: ''                                                                                       
              titleColor: red                                                                         
              position: 2                                               
              width: 420                                                                                     
              height: 280                                                                               
              ip: x.x.x.x                                                      
              url: '{{ lasturl }}'            

Simply checks and starts it before I push the notification.

1 Like

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