Custom Component: Unifi Protect

Had a question about the media player functionality. If I use the HA UI to send a TTS from the entity page, it seems to work properly (an mp3 file of the text is generated and stored in my /tts folder, and the doorbell plays the file). If I use a service call in an automation though, the file does not seem to play. I’m calling “play media”, setting the content ID to “http://MY-HA-ADDRESS/local/doorbell.mp3” and setting the content type to “audio/mp3”. Is there something else I need to be doing to get it to play? Or possibly are there some format requirements that i’m not seeing?

The content URL must be accessible from Home Assistant itself. The ffmpeg command to stream the audio runs directly inside of the HA Core docker container. So, if the file is on disk, you can just use /config/www/doorbell.mp3 or whatever the path to the file is. Using a URL might cause issues if the networking routing is off.

Also, if you have not seen the patch notes yet for 0.11.1, please make sure you are running 0.11.1 and reboot your camera after upgrading.

I am using the docker container and just tried changing the path to “/config/www/doorbell.mp3” (I opened a console session into the container to verify that the file was accessible at that location). However, that didn’t seem to work either. I appreciate the help though!

Here’s the YAML for that line:

service: media_player.play_media
data:
  media_content_id: /config/www/doorbell.mp3
  media_content_type: audio/mp3
target:
  entity_id: media_player.front_door_speaker

NOTE: I also tried using /tts/NAME_OF_RECENT_TTS_FILE.mp3 since i know those files played properly, but that also failed to play when calling the service. Do i need to call one of the media player turn-on services or anything else first?

EDIT2: Just to confirm, i am running the latest (0.11.1) and have restarted the camera. TTS commands sent through the home-assistant UI do play, just not the media_player.play_media service

EDIT3: I think I got it! The media content type needs to be set to “music”

Ah yeah. media_content_type is not a mimetype. Event though that is what it may seem like.

Ah, I believe I had to set it to that for the google-cast devices to pick it up, however after testing, it seems like “music” works just fine for both. However, the google-cast needs the URL, not the local path. So, i switched the path to be the URL, the type to be “music” and combined both calls into one (so it lists both the doorbell and the google cast group as the targets) and everything is working now, thanks!!!

Some updates:

Release 0.11.1

  • As an amendment to the deprecations from 0.11.0, the last_tripped_time is no longer deprecated as last_changed is not a full replacement (#411)
  • FIX: Bumps version of pyunifiprotect to 1.3.4. This will fix talkback for all cameras that was not working as expected. If you previously tried to use the media player to play audio through your camera (like with TTS), you will need to reboot your camera to “fix” it so it will work again.

Blueprint Updates

  • Fixes some bugs (channel/tag name being generated wrong, triggering on unavailable).
  • Adds TTS actions to Doorbell Notification
  • Adds Telegram notification targets (thanks @mjdyson)
  • Adds Dynamic Doorbell blueprint
2 Likes

With the new version I can no longer see my G3 Flex cameras in HA, the G4 Bullets are working just fine and it all happened when I upgraded this component. I have the same settings for RTSP so not sure what could be wrong. Did anyone else experience the same?

Please open an issue on Github and attach anything you might see in the HA Logfile

You may also want to check to make sure the camera entities you were using did not get disabled. I tried my best to make sure the same ones stayed enable for 0.10 → 0.11, but it seems like another user has a similar issue. The camera entity they were using in 0.10 did not quite get migrated perfectly and it was disabled in 0.11.

If this does not solve your issue, then yeah, please make a Github issue if you can.

image

My G3 Flex is still working fine.

The ‘Medium’ is active. The ‘Medium Insecure’ was/is disabled.
As I was writing this, I noticed 0.11.2 was available and upgraded. Still working fine.

Thank you all for the response regarding my G3’s. They are displayed as “Unavailable”. The log mentions nothing about my G3’s so maybe there isn’t an issue with code itself but with something I have done (wouldn’t be the first time :smiley: )…

I have to dig deeper to figure out what is going on but just wanted to through some hooks out in case someone else experience the same. Can I reset/restart the integration to these specific cameras somehow?

One of my G3 cameras (Otillgänglig = Unavailable):

Medium stream is ok, is it not?
High quality is not available, but that might be normal on this model.

I find that any streams that are enabled in the Protect App will show up in the HA integration (although they are initially disabled in the HA integration)

So is the doorbell not considered a camera that supports “talkback”?
I’ve tried paying an audio file to it.

(Node-Red)

image

{
    "media_content_id": "https://externalurl.com/local/media/dingfriesaredone.mp3",
    "media_content_type": "music"
}

I’ve tried sending TTS to it through a service all and through the lovelace interface .

(Node-Red)
image

{
    "message": "testing"
}

Any tricks? Or will this not work with the doorbell?
Thanks for the hard work.

ok the doorbell might have needed to be rebooted.
I couldn’t hear any audio from the camera.
Now I think I got it working.

Can someone smarter than me help me understand sensor.<camera>_detected_object?

I want to translate “vehicle” to a Swedish word but what confuses me is how to do that.

service: notify.johans_mobil
data:
  message: {{ state_attr("sensor.g4_framsidan_detected_object",
    "event_object")|replace("vehicle", "Bil") | capitalize}} på framsidan
  data:
    image: /media/local/cameras/G4-Framsidan/{{ time_stamp }}.png
    clickAction: app://com.ubnt.unifi.protect
    ttl: 0
    priority: high
    group: aktivitet_framsidan

What confuses me is that sensor.<camera>_detected_object is not listed here under Developer Tools:

Hi @Lunkobelix
The object detected is not an attribute, but the state of the sensor, so you should use states("sensor.g4_framsidan_detected_object") instead. But please note, the state will reset to none after a short while without detection.

1 Like

Thanks a lot! Worked fine :slight_smile:

Are the states, “none”, “person” and “vehicle”? Is there anyone like “Not identified” or similar?

These are currently the 3 different states. If Ubiquiti adds more classifications, these will be added also.

1 Like

Some more info about my G3’s that isn’t showing the stream anymore, maybe it can help someone to give me an idea what has happened:

  • Stream is working in the Unifi app
  • The motion sensor is reporting back motion information to Home Assistant. I can see history of when motion occured.
  • I can toggle things like status light, overlay information, privacy mode, microphone level
  • I can not toggle things like IR active, record always, record motion, high FPS

So it looks like it is the stream that is not working, most of the other functions are working. I have enabled all three RTSP quality options (changed that now from only having medium enabled). Removing and reinstalling the integration is my last option but I guess that will cause quite some work since so I would like to avoid it.

Any ideas?

Edit: Turns out that RTSP stream with low quality had to be enabled in the Protect camera settings. Working fine now.