So how does camera.play_stream really work?

I can play a stream to my sony tv. It supports casting, so my question is, how can I do like showing int he .90 release notes/youtube video. For example someone shows up in my garage, play a stream while there is motion, and then return to what I was watching afterwards? Would it pause what I was watching?

I guess a better question is. Has anyone got a nice automation that actually streams a camera component during motion, pauses what you were doing and then returns to what you were doing after motion ends or a period of time? I have not played much with casting, so I dont know if that is just how its supposed to work, or will it be unique to every device. I’m sure I could send a pause command to my harmony based on the activity I was watching, then stream, then wait until no motion, then here’s where I get stuck, how do you cancel a stream and return? then unpause.

Thanks

3 Likes

the stream bit is just a service. If you can get it working then whatever happens around it is to some extent no relevant or even linked to the fact that you want to stream
You need a trigger (motion), then you need possibly a condition (maybe motion is longer than 1 sec to avoid false positives) then you need a list of actions depending on what you want to achieve.
On top of my head, you’ll need to find a way to retrieve (if even possible) what was happening on the TV prior to motion (what input was on, what was playing (e.g. which channel, or which device), based on this pause the relevant media or save its state (media link, media position, etc), send the stream to the TV until x sec after motion ends, then bring back whatever was playing based on what info you saved…

I get everything you said. Understand that you need a trigger. In the release they show this video

I get there is motion in the garare which I expect is the trigger. Maybe even a condition that the TV is on. and the action being the stream. My question was more about how to start end a stream. Or maybe its more of how to start any cast and then end that cast and return to where you were.

Most casts would not be used the same what you’d want to use a camera stream. At least not for me. A normal cast like casting a movie would likely last the entire length of a movie. I suspect that most people dont want to cast a video stream of their garage for hours after motion is detected. Or have to restart or rewind what they were watching. So I was more looking to see what others have done with thier automations using the new stream service.

using camera.play_stream
Check the Services icon in the dev tools (the icon that looks like a remote), it will show you what info you need to provide. I’ve not yet tried but I suspect something along the lines

- service: camera.play_stream
  data:
    entity_id: camera.living_room_camera
    media_player: media_player.living_room_tv
1 Like

We, lazy people, gonna wait a little more for someone with automation real example (not theoretical…). I had exact same thoughts as topicstarter. Hope time could heal.

TV seems to be useless case… better say, cheapest Chinese Android tablet (rooted? Tasker powered?) on wall or near front door could be best solution for :
Sound notification,
Screen power on,
Live stream,
Screen off, sleep.

3 Likes

I know how to cast. Sorry for any confusion. Again I was just looking for any examples of automations that started and ended a cast like the YouTube video that was spotlighted.

Maybe, you can find my example usefull.

Thanks, it has a good flow. I like the logic. It’s not quite what I was looking for. In hind sight, I feel like I should have started this off differently. I was really looking for people to share thier automations (if they had any yet) that were similiar to the youtube video in the .90 go live post. I should have just started with this basic automation.

- alias: 'Garage Stream with Motion'
  trigger:
  - platform: state
    entity_id: binary_sensor.garage_motion
    to: 'on'
  condition:
  - condition: state
    entity_id: input_select.house_mode
    state: Home
  action:
  - service: camera.play_stream
    data:
      entity_id: camera.garage_camera
      media_player: media_player.living_room_tv

This will stream to my tv with motion in the garage. What it wont do, and what I was hoping that people who have used casting and HA might have some insight on is how to end a stream. Since I have not messed with casting much, I dont know what the capabilites are. I do know how to send a pause to my AV unit via harmony, I do know how to send a play command to my tv via harmony, I know how to turn on/off input booleans if needed. But with this being so new, I was hoping not to have to reivent the wheel. I’ve seen other people who cast to kodi, or plex, etc. maybe switching between inputs, etc. Are there any lessons learned, things that are hard, things that are easy and just work, etc.

Thanks everyone so far.

1 Like

Ok, so if I understood correctly, you are looking for a way to pause the current stream you are playing, stream you camera for a defined time and then resume the previous stream you where playing right?

1 Like

In this example, he is not pausing / resuming the stream, he is playing a film on the Xbox, and just switching the TV Source from XBOX HDMI 2 to CromeCast HDMI 1. As soon as the CromeCast stop the streaming, the TV shitch back to HDMI 2 automatically. So there is not magic behind on that regard.

1 Like

Oh, nice. That was not clear to me, even rewatching the video, but it makes sense. Well, boo, that wont work for me and my TV. I have a sony TV with build in cast capabilities. So in my case, watching apple TV on HDMI 2, then cast takes over.

Thanks for the insight though, since I have not casted much, I’ve never thought about the actual process. Hmm, maybe I can switch back to HDMI 2 after a bit and it will replace the cast. Makes, sense.

Thanks, that is exactly what I was trying to work through in my head

Thanks again for the info, here’s a decent automation. It’s untested, but probably pretty close. So answering my own question. Hope someone else finds this useful

- alias: 'Garage Stream with Motion'
  trigger:
  - platform: state
    entity_id: binary_sensor.garage_motion
    to: 'on'
    for:
      minutes: 30
  condition:
  - condition: state
    entity_id: input_select.house_mode
    state: Home
  action:
  - service: remote.send_command
    data:
      entity_id: remote.basement_remote 
      command:
        - Pause
      device: 17712304
  - service: camera.play_stream
    data:
      entity_id: camera.garage_camera
      media_player: media_player.living_room_tv
  - delay:
      seconds: 30
  - service: media_player.select_source
    data:
      entity_id: media_player.living_room_tv
      source: 'HDMI 2'
  - service: remote.send_command
    data:
      entity_id: remote.basement_remote 
      command:
        - Play
      device: 17712304

Details: I have the sony TV custom component for setting the HDMI (I could prob use harmony for that too, just have not checked yet). Also I prob need to do a template for the device to cover different sources. But the concept should be the same

2 Likes

something I just cooked,so totally untested

- alias: 'Garage Stream with Motion'
  trigger:
  - platform: state
    entity_id: binary_sensor.garage_motion
    to: 'on'
  condition:
  - condition: state
    entity_id: input_select.house_mode
    state: Home
  action:
# save current TV state
  - service: input_text.set_value
    data_template:
      entity_id: input_text.tv_source
      value: "{{ state_attr('media_player.tv','source') }}"
  - service: input_text.set_value
    data_template:
      entity_id: input_text.tv_media_content_id
      value: "{{ state_attr('media_player.tv','media_content_id') }}"
  - service: input_text.set_value
    data_template:
      entity_id: input_text.tv_media_content_type
      value: "{{ state_attr('media_player.tv','media_content_id') }}"
  - service: input_text.set_value
    data_template:
      entity_id: input_text.tv_media_content_position
      value: "{{ state_attr('media_player.tv','media_position') }}"
# add more of these as needed based on your setup / what you're watching
  - service: camera.play_stream
    data:
      entity_id: camera.garage_camera
      media_player: media_player.tv
# Wait for end of motion or 30 sec, whichever comes first
  - wait_template: "{{ is_state('binary_sensor.garage_motion', 'off') }}"
    timeout: '00:00:30'
    continue_on_timeout: 'true'
# Restore TV State
  - service: media_player.select_source
    data_template:
      entity_id: media_player.tv
      source: '{{states("input_text.tv_source")}}
  - service: media_player.play_media
    data_template:
      entity_id: media_player.tv
      media_content_id: '{{states("input_text.tv_media_content_id")}}
      media_content_type: '{{states("input_text.tv_media_content_type")}}'
  - service: media_player.media_seek
    data_template:
      entity_id: media_player.tv
      seek_position: '{{states("input_text.media_position")}}
5 Likes

I have the sequence, now just need to either template this out or create some scripts,but the flow is
Trigger = motion
action
a template based on this

{{ states.remote.living_room_harmony_hub.attributes.current_activity }} 

The activities I use are “watch tivo”, “apple tv”, or “Watch Smart TV”

So based on the current harmony activity

  • Send the pause command to the correct device
  • Send the play stream command to the tv (cast device)
  • delay for X seconds or motion off (would use a wait for this)
  • Then send the input command to the appropriate input (HMDI2, HDMI3, or “home”)
  • then send the play command to the correct device

I don’t think I need any input texts but that is definitely a way to go depending on your AV setup, in my case the state of the harmony never changes, so it’s just a matter of pulling the attribute.

I’ve done some testing from the services menu and it all works. I just did not know much about the casting when I started, now I realize it’s really just an “input” on the TV. so it would not be any different if someone changed the input to HDMI1 when I was watching hdmi2.

Hi all,

I have multiple cast devices set up as below but the stream only plays on last 2 devices. Anyone has the similar setup and how to resolve this?

    - service: camera.play_stream
      data:
         entity_id: camera.front
         media_player: 
          - media_player.tv_living
          - media_player.tv_bedroom
          - media_player.mibox3

Could this be a limitation of the device running the HA?
How much does a stream take on a device like Rpi3?

I don’t know if there’s a limit of streams. I run hassio on a Intel NUC with Virtual Machine because it’s faster and more reliable than rpi3

Is there a limitation to which media players support a stream? There is no documentation of that. The only thing relevant is Paulus’ tweet that states, “Stream any camera on any device.” So should I be able to call camera.play_stream on any media player? Because I’ve tried both my fire tv and roku and neither seems to work.

I totally agree… there’s no documentation about the supported media_playeres. I hope that will work for at least kodi. in future relese? For the moment NONE of my media Players work. I don’t have android TV or Chromecast. I use Kodi

When you stream to a Chromecast by using the: camera.play_stream. When you want the stream to stop, should you then just turn off the chromecast or is there a command like stop_stream or so?