Switch for turning on-off a camera stream, is it possible?

I wish to turn off some camera stream with a switch/automation. Is this possible somehow?

You could turn off the media_player it is displaying on.
Or change its input/channel (if it’s a TV)?

Well I was thinking of turning on-off the stream on lovelace/hass

Not sure, but i think this could work with the browser-commander.


Try it with the more-info command.

If you just want to hide the stream from your frontend you could also use this:

I did something like that some time ago
 connect the camera to a smart plug and turn it off. No stream :-), no network traffic and privacy back.

1 Like

Most of my cameras are POE or USB, so can’t use this method.

But maybe blocking the camera IP from sending “packets”?

Maybe some curl command to the router?

hm
 maybe you could turn the switch port down, maybe even with snmp.

What type of cameras are you using? There are camera.turn_on and camera.turn_off services available, but not all camera platforms support them.

1 Like

Hikvision and Keekoon

Sorry, probably should have asked what HA camera platform(s) are you using with those cameras?

EDIT: Just did a quick search, and as best I can tell, only the amcrest, demo, logi_circle & nest camera platforms support these services.

Depending on the camera capabilities, you may be able to control them with command_line switch.

I use multiple Icamera1000s re-purposed from a security system and control the motion detection event trigger with command_line switches. Similar capabilities exist to control most aspects of the camera.

I can turn motion detection on/off via a switch and also use automation to enable/disable motion detection and notifications.

example

switch:
  - platform: command_line
    switches:
      camera_motion:
        command_on: "/usr/bin/curl --basic --user username:password GET 'http://camera_ip/adm/set_group.cgi?group=EVENT&event_trigger=1'"
        command_off: "/usr/bin/curl --basic --user username:password GET 'http://camera_ip/adm/set_group.cgi?group=EVENT&event_trigger=0'"
        command_state: "/usr/bin/curl --basic --user username:password GET 'http://camera_ip/adm/get_group.cgi?group=EVENT' | grep -s 'event_trigger=' | cut -c 15"
        value_template: "{{ value == '1' }}"
        friendly_name: Camera Motion


If you can find documentation for your cameras’ API and they provide an interface for control of power or stream, it’s a matter of correctly formatting the curl statements in the command_line switch configuration.

1 Like

4 generic and 2 ffmpeg, all hikvision
2 generic, keekoon
1 local_file (a USB webcam)

yes something like that would be perfect, will look in it in other forums, thanks

http://descargas.hommaxsistemas.com//3.%20CCTV%20y%20SISTEMAS%20IP/02.INTEGRACION%20SDK-CGI-ONVIF-RTSP/HIKVISION/CGI/HIKVISION%20CGI%20IPMD%20V1.5.9.pdf

How about using a state-switch and an input_boolean?

E.g. make an input_boolean named input_boolean.camera
Create a switch in lovelace that you want to turn on/off (use the input_boolean you just created as the entity for it)
In lovelace create a state-switch card (it is a custom card by the great Thomas Loven), then again choose the input_boolean as the entity for the state-switch.
Then when configuring the state-switch you put a picture-entity without streaming under the ‘off’ state (or whatever card you prefer to show when the switch is ‘off’, it can be none as well) and a picture-entity with streaming under the ‘on’ state.

That is probably how I’d do it (but I wasn’t exactly sure if this was what you meant). From what I understand you want to have a separate switch to turn on/off videostreaming. This can do exactly that. The card under the ‘off’ state can be anything you want (if you prefer to not have the camera image at all), you could change the card with anything (even stacks) or just leave it empty if you do not want to show a card at all. I think leaving out the specific state entirely in the state-switch configuration should already do the trick. Don’t add anything to a state if you want nothing to show, if you add code it will give an error that the state/card is undefined (or something like that).

Thanks I guess if I don’t find API, can’t block it from router somehow, my other option is yours. But would prefer to block the stream more higher level

I think I found

Line Crossing:
Create a xml file in the curl folder called lineCrossing_off.xml with the following in the body (amend the id to the camera’s):

<b><LineDetection>
<id>1</id>
<enabled>false</enabled>
</LineDetection></b>

Amend and run the following:

**curl -T lineCrossing_off.xml http://admin:[email protected]/ISAPI/Smart/LineDetection/1**

Motion Detection:

As before, create a xml file in the curl folder called motionDetection_off.xml

<b><MotionDetection xmlns="http://www.hikvision.com/ver20/XMLSchema" version="2.0">
<enabled>false</enabled>
<MotionDetectionLayout version="2.0">
</MotionDetectionLayout>
</MotionDetection></b>

Amend and run the following:

**curl -T motionDetection_off.xml http://admin:[email protected]/ISAPI/System/Video/inputs/channels/1/motionDetection**

Missing Camera ON OFF, though

You can stream cameras through motioneye.

Within motioneye it would be possible to ON/OFF individual streams using HA Command Line Switch component

Motioneye also gives additional flexibility re: camera streaming and image capture

I found in anothjer forum, its this

    command_on: "/usr/bin/curl -T enable_RTSP.xml http://admin:[email protected]/ISAPI/Security/adminAccesses"
    command_off: "/usr/bin/curl -T disableRTSP.xml http://admin:[email protected]/ISAPI/Security/adminAccesses"



<AdminAccessProtocolList xmlns="http://www.hikvision.com/ver20/XMLSchema" version="2.0">
<AdminAccessProtocol version="2.0">
<AdminAccessProtocol version="2.0">
<id>4</id>
<enabled>false</enabled>
<protocol>RTSP</protocol>
<portNo>554</portNo>
</AdminAccessProtocol>
</AdminAccessProtocol>
</AdminAccessProtocolList>

but I have HASSIO, need to find a way of puting thoise files .xml somewhere 
 but where??