RPi Cam Web Interface

I’d like to put a request out there to see if someone could develop a third party add-on for RPi Web Cam Interface please? (should this be in feature requests forum?)

http://elinux.org/RPi-Cam-Web-Interface
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=63276&sid=c58e8cf8bde62fb4c13bfc377daf7333

It’s a free piece of software from Github that transforms a Raspberry Pi into an IP based security camera, which really is fantastic! The live video stream is very responsive and there’s many options to configure all aspects of the software.

I don’t know if this would be possible, but the ability to show multiple camera streams from the one webpage would be ideal, with an extra bonus being able to control some basic aspects such as motion on/off, etc.

Thanks!

Couldn’t you just connect to the camera with the Generic MJPEG component?

motion works and is supported by mjpeg. My config looks like this

this other app will probably work with mjpeg as said above

1 Like

Excellent, yes that works for me by using the following settings:

camera:
  platform: mjpeg
  mjpeg_url: http://<IP>/html/cam_pic.php
  name: testcam

Unfortunately this only works if I disable authentication. I can see that optional username and password can be specified, but I’ve tried entering my credentials with both basic and digest authentication without any luck.

My setup uses PHP forms login from here: https://github.com/fethica/PHP-Login which redirects authentication requests as seen here in the code for cam_pic.php:

<?php
session_start();
  if (!isset($_SESSION['username'])) {
    header("location:login/main_login.php");
  } else {

  header("Content-Type: image/jpeg");
   if (isset($_GET["pDelay"]))
   {
      $preview_delay = $_GET["pDelay"];
   } else {
      $preview_delay = 10000;
   }
   usleep($preview_delay);
   readfile("/dev/shm/mjpeg/cam.jpg");
}
?>

I guess the “Generic MJPEG IP Camera” plugin can’t cope with this redirect?

Alternatively, is there a way to embed HTML code as a module in HA ? For example, the following code can normally be used to embed a stream from RPi Cam into a webpage:

<!DOCTYPE html>
<html>
  <head>
    <title>RPi Cam Preview</title>
    <script src="script_min.js"></script>
  </head>
  <body onload="setTimeout('init();', 100);">
    <center>
      <div><img id="mjpeg_dest" /></div>
    </center>
 </body>
</html>

I’ve looked at iFrame but this defeats the ability to have the camera feed as a widget, plus it didn’t work with the PHP Login redirect.

Thanks.

1 Like

Not directly related to jarrah’s topic but … what framerates are you seeing using motion? I’ve never gotten anything “good enough” for me to be happy with. Usually around 5-15fps and I know the Pi2 can do better than that. raspivid can display 60fps very easily.

My guess too. Will it accept http://username:password@hostname_or_ip? Probably not by the looks of it.

The closest thing to that would be

or

The RPi Cam Web Interface has a great framerate if you go direct to its webpage, with virtually no lag. However when I fed this feed in via HA’s mjpeg container, it was running at around 1 frame every 5-10 seconds.

Thank you for the suggestions rpitera, I’ll have a look at the Creating Custom Panels option. (I snuck an edit in before your reply to say I tired iFrame with success if there’s no authentication, but it fails with my redirect still)

right now I am getting am set to 30 fps, i don’t really need anymore than that for a security camera. I did notice after the later versions seem to be harder on the pi, not sure if it’s config or not, but it’s running my pretty hot on my pi B,

I installed it on my new Pi3 and it was a horrible, not sure why though

also I am using a usb camera, not sure if raspivid supports usb

You might want to havea look into Motioneyeos the RPI3 release / image can be downloaded here

I realize this topic is old but I just installed RPi Cam Web on an extra Pi and was trying to figure out the same thing

Use this as the URL

http://IPADDR/html/cam_pic_new.php?

That will get you the direct stream.

Has anyone integrated the motion detection from RPi Cam Web with HA?

4 Likes

Yep, I know it’s old, but sharing that I did the same as @oakbrad and it worked like a charm. I just added a generic mjpeg camera, but pointing to the URL where RPi_Cam_Web_Interface serves just a plain stream. No latency, worked great.

In my config file:

camera:

It would be <your_IP>/html/cam_pic_new.php if you installed RPi_Cam_Web_Interface with the default settings, as @oakbrad pointed out.

As for interaction:

I think you could also interact with RPi_Cam_Web_Interface from home assistant by sending FIFO commands, but haven’t played with that, I just use their UI and also watch the stream in my hassio dashboard for convenience sake.

I tried MotionEyeOS but was annoyed by the latency

2 Likes

Hi,
I happened to create my own solution for RPi-Cam-Web-Interface and I believe this could be helpful to others.
I have created an agent for the raspberry pi that connects to an MQTT broker and allows to get camera status and send commands to the above mentioned FIFO file (https://gitlab.com/gbus/rpi-cam-mqtt). This works very well for me and I have decided to also provide integration for control and automation under HA as a new camera platform called rpicam (Pull request: https://github.com/home-assistant/home-assistant/pull/19936).

This means that if you set your RPi camera in HA you can do things like:

set exposure mode to night after sunset

or

shoot a 60 second video when entrance door PIR state becomes on

or

enable motion detection when nobody is home

Note that this platform is derived from the generic IP camera implementation (https://www.home-assistant.io/components/camera.generic/). The camera preview and the live view are displayed exactly the same in the HA interface, which wasn’t bad for me in terms of frame rate and performance.

I have also added some simple support for DIY pan/tilt, based on cheap servos and the Adafruit_PCA9685 servo controller. This would allow some extra automation features like:

point the camera to the entrance door 
and
shoot a 60 second video
when
entrance door PIR state becomes on

:wink:
If someone try, please let me know how it goes and if there are any difficulties with the settings.
One last note: until the PR gets accepted you need to manually add the rpicam.py in custom_components/camera directory of your HA config path and restart HA:

https://gitlab.com/gbus/ha-rpicam/

Cheers!

3 Likes

This is really great @gbus! I’ve so far done everything via bash scripts and ssh calls to the camera from HA, but this will be a much better solution! I will start working on converting to this platform.

Thank you very much for sharing!

On another note, last night I found a great way to view my cameras via a Lovelace custom card that someone developed. I’ve always wanted a single pane view via the desktop to save me having to visit each camera web interface in turn, and this ticks all the boxes!

You can set an update interval in seconds (min 0.5) for the thumbnails and another for the main video so that it doesn’t consume too many resources. It also has the ability to focus on a camera that detects motion, so I’m hoping we may be able to use your MQTT integration to send messages to a topic when motion is detected, which in turn would be monitored via an MQTT sensor in HA. Looking at Rpi-Cam-MQTT I don’t think it can do this yet(?), so it would be a great feature if not.

The surveillance-card was originally released 4 months ago which had a scrollable list of cameras down the left hand side, but someone has forked that with an improved version which shows camera thumbnails along the top that resize as more are added (see my screenshot above). The forked GitHub project can be found here: https://github.com/azgooon/surveillance-card (my preferred version).

In addition to the readme notes on that page, you’ll need to edit surveillance-card.js and remove the hat symbol (^) from this line:

} from 'https://unpkg.com/@polymer/lit-element@^0.5.2/lit-element.js?module';

So that it looks like this:

} from 'https://unpkg.com/@polymer/[email protected]/lit-element.js?module';

My yaml then looks like the following:

camera:
  - platform: mjpeg
    name: Cam1
    mjpeg_url: http://192.168.0.10/html/cam_pic_new.php?
    username: !secret cam_user
    password: !secret cam_pass
  - platform: mjpeg
    name: Cam2
    mjpeg_url: http://192.168.0.11/html/cam_pic_new.php?
    username: !secret cam_user
    password: !secret cam_pass
  - platform: mjpeg
    name: Cam3
    mjpeg_url: http://192.168.0.12/html/cam_pic_new.php?
    username: !secret cam_user
    password: !secret cam_pass
#etc

then in ui-lovelace.yaml I have:

resources:
  - url: /local/surveillance-card.js?v=1.1
    type: module

views:
  - title: Cameras
    icon: mdi:cctv
    path: camera
    panel: true
    cards:
      - type: custom:surveillance-card
        thumb_interval: 5
        update_interval: 1
        cameras:
          - entity: camera.cam1
          - entity: camera.cam2
          - entity: camera.cam3

Hope this helps others too!

1 Like

Hmm, thinking about this there’s no need to integrate detection of motion into Rpi-Cam-MQTT because I could just issue a “mosquitto_pub” command within /var/www/html/macros/motion_event.sh to a topic such as rpicam/<camera_name>/motion with a simple message name that can then be picked up by HA. I’ve run out of time this evening but will have a go at this tomorrow and report back my results.

Hi, thank you for your input. I will definitely look into the lovelace panel!
I believe you can already do automation based on motion detection because it is all available from the status topic.
I’ll explain myself better with an example. I have a camera called “front” and the status topic reports all the camera statuses you normally would read with your scripts from /dev/shm/mjpeg/status_mjpeg.txt.

Topic/message I see on my broker:

Status Off:

rpicam/front/status halted

Status On:

rpicam/front/status ready

Motion on:

rpicam/front/status md_ready

Motion detected (if you have set to take a video when motion is detected):

rpicam/front/status md_video

This messages are reported as state of the entity under HA and you can do something like:

automation:
    trigger:
    - entity_id: camera.front
      platform: state
      from: 'md_ready'
      to: 'md_video'
  action:
    service: light.turn_on
    data:
      entitiy_id: light.floodlight

This is not immediate looking at the code, but hopefully, improving the documentation, it will probably become more obvious the way this integration can be used in real scenarios.
Thanks again!
Cheers.

Ah yes I see what you mean, I’ve not really looked at the status file before as I’ve not needed it till now.

Unfortunately though after a bit of experimentation, the “monitor” Motion detect mode doesn’t update the status file because it doesn’t trigger a video or photo event. I use this feature to record video 24/7 in 30 min segments, then when motion is detected, it triggers the motion_event.sh macro which I use to do a bunch of stuff.

It may be worth me raising a feature request with the RPi Cam developer to see if he could populate the status file when in this mode, perhaps with something like motion_video, then back to video when done.

I have never really played with the monitoring mode, but I see why the status doesn’t change.
The fact that the camera status isn’t changing when motion is detected is in principle correct and that’s why the RPi-Cam-Web-Interface writes the events in a specific log file motionLog.txt, I believe that my agent should have an integration with that log file and publish the events on a dedicated topic. This would complete the capability of my agent to interface the rpi camera with the MQTT protocol.
I’ll think about it.
Thanks for the input!

1 Like

ah yes I see that motionLog.txt is updated when motion starts and stops, so sending MQTT messages for both would be great, thank you!

I can’t get this to work. (Does that ^ entry to delete still applies?)
My pi zero works is streaming fine at this address http://192.168.0.111/html/cam_pic_new.php?

I could even get the Hassio addon MotionEye to see it [\o/], but this lovelace.yaml is confusing for me (used to classic UI), so my configuration.yaml is OK.

CloudApp

Do I copy/paste you example for “views” as is, or do I have to insert parts from it in different places into
my lovelace yaml?

my lovelace yaml:

CloudApp

CloudApp

result:

CloudApp

any ideas?

ps.
I see “-badges” as a beginning not sure “-title: cameras” is ok to be on the same level.