Turn camera component on/off

I use camera component with zoneminder.
When someone at home, the camera itself is physically off (smart switch stops providing its power) and I also turn off the ‘monitor’ in zoneminder using its API.
However, during this time, HA gets lots of errors:

2018-01-10 10:47:12 ERROR (MainThread) [homeassistant.components.camera.mjpeg] Error getting new camera image: RawResponseMessage(version=HttpVersion(major=1, minor=0), code=200, reason='OK', headers=<CIMultiDict('Server': 'ZoneMinder Video Server/1.30.4', 'Expires': 'Mon, 26 Jul 1997 05:00:00 GMT', 'Last-Modified': 'Wed, 10 Jan 2018 08:47:12 GMT', 'Cache-Control': 'no-store, no-cache, must-revalidate', 'Cache-Control': 'post-check=0, pre-check=0', 'Pragma': 'no-cache')>, raw_headers=((b'Server', b'ZoneMinder Video Server/1.30.4'), (b'Expires', b'Mon, 26 Jul 1997 05:00:00 GMT'), (b'Last-Modified', b'Wed, 10 Jan 2018 08:47:12 GMT'), (b'Cache-Control', b'no-store, no-cache, must-revalidate'), (b'Cache-Control', b'post-check=0, pre-check=0'), (b'Pragma', b'no-cache')), should_close=True, compression=None, upgrade=False, chunked=False)

The more annoying issue is when HA starts and the camera isn’t active, the camera won’t show on HA interface and even after I’ll turn in ON via zoneminder it won’t show on HA until I restart HA server.

do you need the camera to be physically off? Can’t you instead disable recording / motion detection related functions? That’s what I’ve done with my internal cameras…

I can, but as an extra safety measure, I prefer the power to be down when someone at home.
Anyway, I think it should be possible to turn off monitoring of zoneminder via HA and not just the modect functionality


Hey, had the same idea comming up my mind. I would appreciate a build in solution just to turn off the camera when I’m at home. But for now I created a command line switch for turning off ‘motion’

 -  platform: command_line
        command_on: 'ssh user@ip sudo service motion start'
        command_off: 'ssh user@ip sudo service motion stop'
        command_state: 'ssh user@ip7 systemctl is-active motion.service'
        friendly_name: Webcam On/Off

motion needs sudo but I wouldn’t recommend giving HA-User admin rights, so i decided to do it via ssh to the admin user on same raspberry.

Not the fairest solution, but fair enough.

did you ever get to the bottom of this issue ? - i’m getting the same error

Unfortunately I didn’t…

Hmmm… This throws a spanner in the works for my plan to just kill power to our living room camera when we are at home…

Yeah, that’s a very annoying issue here…

1 Like

sonoff inline? are you using PoE or regular power?

also couldnt you just change zoneminder from running to stopped ? played around with those modes when I transitioned from Arlo as was a similar method (before using the zoneminder switches).

Is there a way to add only specific cameras from zoneminder, not all of them?
One of my camera is not enabled all the time, and i want to get rid of those error messages from [homeassistant.components.camera.mjpeg].

Getting the following errors trying to turn a camera on/off

2019-01-11 09:30:08 ERROR (SyncWorker_7) [zoneminder.zm] JSON decode exception caught while attempting to decode "&lt;pre class="cake-error"&gt;&lt;a href="javascript:void(0);" onclick="document.getElementById('cakeErr5c38b680d4fa6-trace').style.display = (document.getElementById('cakeErr5c38b680d4fa6-trace').style.display == 'none' ? '' : 'none');"&gt;&lt;b&gt;Warning&lt;/b&gt; (2)&lt;/a&gt;: file_put_contents(/var/log/zmerror.log): failed to open stream: Permission denied [&lt;b&gt;CORE/Cake/Log/Engine/FileLog.php&lt;/b&gt;, line &lt;b&gt;142&lt;/b&gt;]&lt;div id="cakeErr5c38b680d4fa6-trace" class="cake-stack-trace" style="display: none;"&gt;&lt;a href="javascript:void(0);" onclick="document.getElementById('cakeErr5c38b680d4fa6-code').style.display = (document.getElementById('cakeErr5c38b680d4fa6-code').style.display == 'none' ? '' : 'none')"&gt;Code&lt;/a&gt; &lt;a href="javascript:void(0);" onclick="document.getElementById('cakeErr5c38b680d4fa6-context').style.display = (document.getElementById('cakeErr5c38b680d4fa6-context').style.display == 'none' ? '' : 'none')"&gt;Context&lt;/a&gt;&lt;pre id="cakeErr5c38b680d4fa6-code" class="cake-code-dump" style="display: none;"&gt;&lt;code&gt;&lt;span style="color: #000000"&gt;&lt;span style="color: #0000BB"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$pathname&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;=&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$this&lt;/span&gt;&lt;span style="color: #007700"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;_path&amp;nbsp;&lt;/span&gt;&lt;span style="color: #007700"&gt;.&amp;nbsp;&lt;/span&gt;&lt;span style="color: #0000BB"&gt;$filename&lt;/span&gt;&lt;span style="color: #007700"&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;

#2 /usr/share/zoneminder/www/api/app/Plugin/Crud/Lib/CrudControllerTrait.php(31): Controller-&amp;gt;invokeAction(Object(CakeRequest))

#5 /usr/share/zoneminder/www/api/app/webroot/index.php(107): Dispatcher-&amp;gt;dispatch(Object(CakeRequest), Object(CakeResponse))

#2 /usr/share/zoneminder/www/api/app/Plugin/Crud/Lib/CrudControllerTrait.php(31): Controller-&amp;gt;invokeAction(Object(CakeRequest))

#5 /usr/share/zoneminder/www/api/app/webroot/index.php(107): Dispatcher-&amp;gt;dispatch(Object(CakeRequest), Object(CakeResponse))

"#2 \/usr\/share\/zoneminder\/www\/api\/app\/Plugin\/Crud\/Lib\/CrudControllerTrait.php(31): Controller-&gt;invokeAction(Object(CakeRequest))",

"#5 \/usr\/share\/zoneminder\/www\/api\/app\/webroot\/index.php(107): Dispatcher-&gt;dispatch(Object(CakeRequest), Object(CakeResponse))",

File "/home/homeassistant/homeassistant/lib/python3.6/site-packages/zoneminder/zm.py", line 92, in _zm_request