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

Yes, I used that exact command.
After running the command it does not give any sort of feedback. No success message or anything. Is that normal?

Here are the steps I followed…

1: Downloaded APK from HERE
2: Ran the following commands

./adb connect 192.XX.XX.XX
./adb install app-debug.pkg

3: Checked to make sure app installed and it did. Opened app and can see the PIPup logo with a message saying the server address.
4: Ran the following commands:

./adb shell pm list packages
./adb shell appops set nl.rogro82.pipup SYSTEM_ALERT_WINDOW allow

5: Hopped on to my Linux system and created post.json using the exact code in your write-up
6: ran the curl command, and receive the following response:

curl -d "@post.json" -H "Content-Type: application/json" -X POST http://192.XX.XX.XX:7979/notify

PopupProps(duration=30, position=BottomLeft, 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=480root

NOTE: Nothing pops up on my device.

7: Pasted the 2 REST commands, changed to the proper IP address and rebooted HA. pipup_image_on_tv and pipup_url_on_tv are now both showing as services.
8: Run this command from dev tools

service: rest_command.pipup_image_on_tv
data:
  title: hey
  message: I can see you
  titleColor: red
  position: 3
  url: >-
    https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png

And this is what I get in the logs

2022-04-25 20:18:45 WARNING (MainThread) [homeassistant.components.rest_command] Error. Url: http://192.XX.XX.XX:7979/notify. Status code 400. Payload: b'{\n  "duration": 20,\n  "position": 3,\n  "title": "hey",\n  "titleColor": "red",\n  "titleSize": 10,\n  "message": "I can see you",\n  "messageColor": "#fbf5f5",\n  "messageSize": 14,\n  "backgroundColor": "#0f0e0e",\n  "media": { \n    "image": {\n      "uri": "https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png",\n      "width": 640,\n      "height": 480\n    }\n  }\n}'

I’ve done tried this on 3 devices and same results on all of them. Is there something I’ve missed?

1 Like

@MRobi I uninstalled the APK and reinstalled following the steps you described exactly. After this, the video popup worked as expected, but I noticed that the HA service call for pipup_image_on_tv did not, and I had the same error as you in my logs. I copied the JSON from that log line into a new post.json file and retried with cURL. When I did this, PiPUp gave me an informative error (which was unfortunately not logged by HA when it sent the command… perhaps it would have been if debug level logging was enabled in HA):

invalid request: Unrecognized field "height" (class nl.rogro82.pipup.PopupProps$Media$Image), not marked as ignorable (2 known properties: "uri", "width"])

I now see in the original PiPUp docs that “height” is indeed not a valid field.

The solution is to modify the REST command you have in Home Assistant to take it out. The pipup_image_on_tv should now read:

pipup_image_on_tv:
  # Use Pipup to display notifications on Android TV devices.
  url: http://ANDROID_TV_IP_ADDRESS: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": { 
        "image": {
          "uri": "{{ url }}",
          "width": {{ width | default(640) }}
        }
      }
    }

After making this change, I can confirm that your service call is working for me.
IMG_20220426_114841

I note from your post that you are still using the Window’s Powershell curl command with arguments that look like they are for the unix/linux/macOS original version of cURL. As mentioned in previous posts, this is probably a problem in its own right. If you want to use the Windows Powershell version of curl you’ll either need to figure out the appropriate arguments that it expects, or switch to a port of the unix version. If you can get curl working, then you should be able to debug any subsequent issues the same way I did above.

I have also updated my blog post to correct the error. I hope this fixes the issue for you!

In step 5 I switched from windows to a linux VM to create the post.json and run the curl command. Initially it was doing nothing. I cleared data/cache on the PIPup app and ran it again and I’m getting the PIPup window through the curl command now. Progress!

So PIPup is working on the box, the curl command is working, I just need to get the HA portion working.

I copied the new pipup_image_on_tv from above, changed the IP to the correct one, rebooted HA and ran

service: rest_command.pipup_image_on_tv
data:
  title: hey
  message: I can see you
  titleColor: red
  position: 2
  url: >-
    https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png

But I’m still getting this 400 error in logs and no popup

2022-04-26 09:28:14 WARNING (MainThread) [homeassistant.components.rest_command] Error. Url: http://192.XX.XX.XX:7979/notify. Status code 400. Payload: b'{\n  "duration": 20,\n  "position": 2,\n  "title": "hey",\n  "titleColor": "red",\n  "titleSize": 10,\n  "message": "I can see you",\n  "messageColor": "#fbf5f5",\n  "messageSize": 14,\n  "backgroundColor": "#0f0e0e",\n  "media": { \n    "image": {\n      "uri": "https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png",\n      "width": 640\n    }\n  }'

Here is my full rest command

rest_command:
  pipup_image_on_tv:
    # Use Pipup to display notifications on Android TV devices.
    url: http://192.XX.XX.XX: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": { 
          "image": {
            "uri": "{{ url }}",
            "width": {{ width | default(640) }}
          }
        }
  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.XX.XX.XX: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) }}
          }
        }
      }

Here is the service called from dev tools (also tried through nodered, same result)

service: rest_command.pipup_image_on_tv
data:
  title: hey
  message: I can see you
  titleColor: red
  position: 0
  url: https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png

And here is the log message:

2022-04-26 09:47:43 WARNING (MainThread) [homeassistant.components.rest_command] Error. Url: http://192.XX.XX.XX:7979/notify. Status code 400. Payload: b'{\n  "duration": 20,\n  "position": 0,\n  "title": "hey",\n  "titleColor": "#50BFF2",\n  "titleSize": 10,\n  "message": "I can see you",\n  "messageColor": "#fbf5f5",\n  "messageSize": 14,\n  "backgroundColor": "#0f0e0e",\n  "media": { \n    "image": {\n      "uri": "https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png",\n      "width": 640\n    }\n  }'

If I copy the info from the error into a new post.json file layed out the proper way, I get the popup through a curl command. So I’m not seeing anything wrong with the syntax.

Your command works for me via both HA and cURL. I don’t know why it isn’t working from HA for you. Perhaps debug-level logging in HA will gives you a useful error string from PiPUp to help you figure it out. This forum post has good info on increasing the log level for rest commands.

@seanblanchfield I did the same procedure as @MRobi but didn’t tried to post to the tv due to the lack of knowledge, but when I try:

service: rest_command.pipup_image_on_tv
data:
  title: hey
  message: I can see you
  titleColor: red
  position: 0
  url: https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png

I get:

 Logger: homeassistant.components.rest_command
Source: components/rest_command/__init__.py:148
Integration: RESTful Command (documentation, issues)
First occurred: 15:39:48 (1 occurrences)
Last logged: 15:39:48
Client error. Url: http://192.168.50.140:7979/notify. Error: Cannot connect to host 192.168.50.140:7979 ssl:default [Connect call failed ('192.168.50.140', 7979)]

no popup, any idea why this behaviour?

Either you don’t have the PiPUp app running on your TV or you’ve got the IP address wrong or have some other issue with your network that’s preventing communication (and I can’t help debug with the latter).

It shows as installed on the tv but I can only see in the file explorer and it doesn’t really open when I click on it, is it supposed to? I’ll try to troubleshoot the network settings. Thanks :+1:

EDIT: I did run the test curl command and got:

C:\Users\Bernardo\Downloads\platform-tools>curl -d "@post.json" -H "Content-Type: application/json" -X POST https://192.168.50.140:7979/notify
curl: (7) Failed to connect to 192.168.50.140 port 7979 after 2054 ms: Connection refused

Just getting back to this now. Here’s the debug logs from the rest command. I’m not seeing any clues

2022-04-29 17:48:43 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140224807462032] Received {'type': 'execute_script', 'sequence': [{'service': 'rest_command.pipup_image_on_tv', 'data': {'title': 'hey', 'message': 'I can see you', 'titleColor': 'red', 'position': 0, 'url': 'https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png'}}], 'id': 60}
2022-04-29 17:48:44 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=rest_command, service=pipup_image_on_tv, service_data=title=hey, message=I can see you, titleColor=red, position=0, url=https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png>
2022-04-29 17:48:44 WARNING (MainThread) [homeassistant.components.rest_command] Error. Url: http://192.XX.XX.XX:7979/notify. Status code 400. Payload: b'{\n  "duration": 20,\n  "position": 0,\n  "title": "hey",\n  "titleColor": "red",\n  "titleSize": 10,\n  "message": "I can see you",\n  "messageColor": "#fbf5f5",\n  "messageSize": 14,\n  "backgroundColor": "#0f0e0e",\n  "media": { \n    "image": {\n      "uri": "https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png",\n      "width": 640\n    }\n  }'

EDIT: welllllll I’m an idiot! LOL I got looking real close at the rest command and I figured out my issue… I was missing the last } on the pipup_image_on_tv command :see_no_evil:

So now that I’ve got the rest command working, I can move on to testing the video streams lol

Can confirm, it still doesn’t work on Firestick even without the height parameter.

Not about to get an Nvidia Shield just for this, but it looks like there’s still a roundabout way to do this on Firestick. Need to use TinyCam or some other app that can play RTSP streams and also allows for starting up in Picture in Picture mode through ADB Intent commands.

VLC doesn’t seem to have an command to open in PiP mode. I was able to launch VLC through ADB with the camera stream, but it opens fullscreen. TinyCam might work, but it seems a little involved for me and I can’t commit more time to it.

Might give it a try in the future though.

@seanblanchfield

Thanks for the guide, and I am trying to use this method with the Fire TV Stick 4K but have run into some issues:

  1. I have installed the app-debug.apk on Fire TV Stick 4K
  2. Ran “adb shell appops set nl.rogro82.pipup SYSTEM_ALERT_WINDOW allow”
  3. Opened PiPup on Fire TV Stick and left at spash screen showing:
"The server is running on 192.168.1.67:7979"
  1. Curl command attempted on windows, with just an echo of json script and nothing happening on FTV, so I switched directly to HA → developer tools → services and sent command below…
  2. RESTful Command: pipup_image_on_tv with command:
    service: rest_command.pipup_image_on_tv
data:
title: hey
message: I can see you
titleColor: red
position: 0
url: https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/cfcc3137009463.5731d08bd66a1.png
  1. Nothing shows on Fire TV Screen but log shows this error (similar to @renk1’s post above):
Logger: homeassistant.components.rest_command
Source: components/rest_command/__init__.py:148
Integration: RESTful Command ([documentation](https://www.home-assistant.io/integrations/rest_command), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+rest_command%22))
First occurred: 12:22:43 (1 occurrences)
Last logged: 12:22:43

Client error. Url: http://192.168.1.67:7979/notify. Error: Cannot connect to host 192.168.1.67:7979 ssl:default [Connect call failed ('192.168.1.67', 7979)]
  1. Trying to navigate directly to “http://192.168.1.67:7979/notify” with browser from host PC (running HAOS VM) shows:

invalid request: invalid method

which shows that the PiPup web server is running on 192.168.1.67:7979 on the Fire Stick

  1. Retried service command several times, but nothing shows up in log, rebooted haos and still no new error logs.

It would be really useful to get this working on a Fire TV Stick for doorbell video PiP notifications.

Any ideas on what could be causing this RESTful error shown in step 6 and why I’m not seeing any new error logs every time I send a service command via dev tools?

The JSON in the last line of your debug log is missing a closing curly brace. This must missing where you have your REST command defined, and would explain getting a 400 (Bad Request) error from the PiPUp app. (BTW, I quickly found this error by copying the JSON out into a code editor and formatting it. This makes syntax errors obvious. You can do it yourself using VS Code, sublime or any other good code editor).

I don’t have a Fire Stick, so I can’t recreate this. It seems that the PiPUp app is up and running however, evidenced by you getting an “invalid method” error when you try to access it from your web browser. That error just means that it wants a POST request, not a GET request (which your web browser is sending it). The way to investigate this is to use cURL. It’s best not to do this from windows. Can you SSH into HA and experiment with using cURL and ping from there? It might reveal something that is preventing your HA box from connecting to your Firestick. Perhaps you have a firewall rule that is blocking the connection, or perhaps your Firestick is on a different WiFi than your HA box.

First , I want to thank you for your detailed instructions. I was able to get all of this working very easily.

I have one small issue that I was hoping you could provide your insights on. I use Tivimate to watch IPTV. When I use the service to show an image, everything works fine and the TV channel I’m watching continues to play as expected. When I use the service to show a streaming video (doorbell camera), it works but stops the TV channel. It seems like the video player in Android is fighting to play both streams at the same time and cannot.

With more testing I’ve determined that sometimes it is the doorbell video that freezes and the Tivimate TV channel keeps playing.

I’ve also tried setting a different external player for Tivimate on the hunch that PIPUp is using the native player but that didn’t help either.

Do you have any suggestions? Do you know of a way to associate PIPUp with a different video player like VLC? This might avoid the conflict.

Thanks in advance for your help.

1 Like

I see the same behaviour. If youtube is open but no video is playing then the PIP notification plays the notification video correctly. However if a video is playing then the PIP notification does not play a video. Also I sometimes see the video in PIP stuttering.

I’ve had this happen. It magically vanished though too. :slight_smile:. It could have something to do with the stream you are sending. I found one of my cameras would play correctly but, for example, pause the video playing on the shield so I reverted that to an image instead.

In the URL generated in the notification script the webrtc param is set false. url: <PUBLIC_PATH>/webrtc/embed?url={{ link_id }}&webrtc=false
Could that be an issue?

It could be. That would use a different set of codecs.

Yeah, MSE maybe.

WebRTC in some cases may not work with remote access, then the video will play using MSE. As soon as WebRTC is able to connect - video will play through it, MSE will be stopped.