Skip to content

Instantly share code, notes, and snippets.

@enegaard
Last active April 13, 2024 11:24
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save enegaard/a57af286205914bd912270c89650fb1b to your computer and use it in GitHub Desktop.
Save enegaard/a57af286205914bd912270c89650fb1b to your computer and use it in GitHub Desktop.
Getting the Raspberry Pi Camera to Work on HASSOS

Getting the Raspberry Pi Camera to Work on HASSOS

Enabling the Raspberry Pi camera on HASSOS installations is unfortunately not as simple as connecting the camera and configuring Home Assistant as described at https://www.home-assistant.io/integrations/rpi_camera.

For the camera to work at all, an alternate firmware needs to be loaded when the Raspberry Pi boots. On Raspberry Pi OS (and many others), the alternate firmware is included with the OS installation image, and switching to the alternate firmware is accomplished by running raspi-config and selecting "Enable Camera" from the menu. HASSOS does not include either the alternate firmware or the raspi-config program, so all of the steps need to be done manually.

The steps below attempt to describe the steps that need to be performed. They have worked for me on a Raspberry Pi 3B+ running HASSOS 4.11 through 4.15. If you have a different setup your mileage may vary (but hopefully you'll get enough hints from the below to get it working).

As of HASSOS 6.0, as mentioned in the closing notes of home-assistant/operating-system#947 on June 17th 2021, the alternate firmware files are automatically included in the builds. Therefore much of this guide is obsolete - only the last two sections need to be followed (enable the camera in config.txt and reboot).

Shortly after HASSOS 6.0 was released, some code change between Home Assistant Core 2021.7.4 and Home Assistant Core 2021.8.1 broke the camera support on HASSOS platforms. A fix was applied and core versions 2021.11.3 and later work once again, so avoid core versions 2021.8.0 through 2021.11.2 to retain a working rpi_camera.

The high-level overview of what needs to be done is:

  • Find the alternate firmware files compatible with the version of HASSOS that you are running or are going to be running after the next reboot.
  • Place the firmware files on a machine that your HASSOS box has scp/sftp access to.
  • Copy the firmware files to the HASSOS addon_core_ssh container.
  • Copy the firmware files to the HASSOS /mnt/boot partition.
  • Edit the HASSOS /mnt/boot/config.txt file to enable the alternate firmware and make other camera related changes.
  • Reboot HASSOS, then configure the camera as documented elsewhere.

Find the correct start_x.elf and fixup_x.dat firmware files

(skip this step on HASSOS 6.0 and later)

Find your HASSOS version if you don't already know it. There are many ways to do this, like looking at the host system information information in the Home Assistant client you use. Another way is to run the following from an SSH connection to Home Assistant:

ha info | grep hassos:

E.g. 4.13

Go to https://github.com/home-assistant/operating-system/blob/HASSOS-VERSION/buildroot/package/rpi-firmware/rpi-firmware.mk

(NOTE: replace HASSOS-VERSION with your version of HASSOS, e.g. https://github.com/home-assistant/operating-system/blob/4.13/buildroot/package/rpi-firmware/rpi-firmware.mk)

The firmware hash is the value of the make variable RPI_FIRMWARE_VERSION

In this example, the firmware hash is: 7caead9416f64b2d33361c703fb243b8e157eba4

Go to https://github.com/raspberrypi/firmware/commit/FIRMWARE-HASH

E.g. https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4

And download the start_x.elf and fixup_x.dat files from there. If start_x.elf and fixup_x.dat are NOT in that commit, click on "Browse Files (at this point in history)", navigate to boot/, and download the firmware files from there.

Save both firmware files on a system that your HASSOS box will be able to access with scp or sftp.

Operating System Firmware Hash Firmware Link
4.13 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
4.14 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
4.15 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
4.16 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
4.17 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
4.18 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
4.19 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
4.20 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
5.0 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
5.1 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
5.2 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
5.3 7caead9416f64b2d33361c703fb243b8e157eba4 https://github.com/raspberrypi/firmware/commit/7caead9416f64b2d33361c703fb243b8e157eba4
5.4 2b41f509710d99758a5b8efa88d95dd0e9169c0a https://github.com/raspberrypi/firmware/commit/2b41f509710d99758a5b8efa88d95dd0e9169c0a
5.5 2ba11f2a07760588546821aed578010252c9ecb3 https://github.com/raspberrypi/firmware/commit/2ba11f2a07760588546821aed578010252c9ecb3
5.6 2ba11f2a07760588546821aed578010252c9ecb3 https://github.com/raspberrypi/firmware/commit/2ba11f2a07760588546821aed578010252c9ecb3
5.7 2ba11f2a07760588546821aed578010252c9ecb3 https://github.com/raspberrypi/firmware/commit/2ba11f2a07760588546821aed578010252c9ecb3
5.8 2ba11f2a07760588546821aed578010252c9ecb3 https://github.com/raspberrypi/firmware/commit/2ba11f2a07760588546821aed578010252c9ecb3
5.9 2ba11f2a07760588546821aed578010252c9ecb3 https://github.com/raspberrypi/firmware/commit/2ba11f2a07760588546821aed578010252c9ecb3
5.10 2ba11f2a07760588546821aed578010252c9ecb3 https://github.com/raspberrypi/firmware/commit/2ba11f2a07760588546821aed578010252c9ecb3
5.11 2ba11f2a07760588546821aed578010252c9ecb3 https://github.com/raspberrypi/firmware/commit/2ba11f2a07760588546821aed578010252c9ecb3
5.12 0d458874a89921fbe460e422b239695e1e101e2b https://github.com/raspberrypi/firmware/commit/0d458874a89921fbe460e422b239695e1e101e2b
5.13 0d458874a89921fbe460e422b239695e1e101e2b https://github.com/raspberrypi/firmware/commit/0d458874a89921fbe460e422b239695e1e101e2b

Copy the firmware files to the HASSOS host

(skip this step on HASSOS 6.0 and later)

This is a two-step process, since the HASSOS host does not have any support for copying remote files directly to the host. Therefore the concept is to copy the firmware files to a container that does have support for remote file transfer, then copy those files to the host using the docker cp command.

Enable camera in config.txt

Connect to the HASSOS host on port 22222, and edit (with "vi") the /mnt/boot/config.txt file as follows.

The camera needs more GPU memory than the default setting provides. Increase the GPU memory to 128 MB where possible by adding the following lines. See https://www.raspberrypi.org/documentation/raspbian/applications/camera.md and https://www.raspberrypi.org/documentation/configuration/config-txt/memory.md for reference.

gpu_mem=128
gpu_mem_256=64
gpu_mem_512=128
gpu_mem_1024=128

Enable the alternate firmware:

# Setting start_x to 1 does exactly the same
# thing as the following 2 lines that are commented
# out, but with reduced risk for errors due to typos
start_x=1
#start_file=start_x.elf
#fixup_file=fixup_x.dat
# The next line is optional, if you don't want the
# red LED on the camera to light while the camera
# is active
disable_camera_led=1

Reboot the HASSOS host and start using the camera

After all of the steps above have been completed, reboot the HASSOS host and continue configuring the camera as documented in https://www.home-assistant.io/integrations/rpi_camera.

@Mettyl
Copy link

Mettyl commented Apr 8, 2022

Hi, thanks for sharing this, but I can't get it to work on 2022.03.5. Was anyone more successful than me, or is it still working for you according to the suggested steps?

@enegaard
Copy link
Author

enegaard commented Apr 9, 2022

@Mettyl - I'm currently on HASSOS 7.5 and Core 2022.3.5, and the camera is still working for me. Are you upgrading from a previously working config, or is it a new install? Rpi3 or rpi4?

@nepozs
Copy link

nepozs commented Apr 11, 2022

@Mettyl
Solution still works.
HAOS begining from version 6.0 does NOT need copying files (they just exists in standard installation).

On new installation only config.txt need editing.

@Mettyl
Copy link

Mettyl commented Apr 11, 2022

It's a new install on Rpi4, and I've finally got it working. I did what I should have done first, switched to Rpi OS to test the camera itself, and although the LED was on, there was probably some connection issue and reconnecting the camera solved it.
Back on HASSOS, editing the config.txt was enough to make it work, with both rpi_camera integration and motionEye.
Thanks for your help!

@berkerel
Copy link

berkerel commented Apr 29, 2022

Is it still working on 7.6 version (RPi3)? I do not have any file under /mnt/boot
When I create config.txt by myself it do not work, camera is not available.

@nepozs
Copy link

nepozs commented Apr 29, 2022

I do not have any file under /mnt/boot

Impossible. Maybe you don't have root privileges.
Shut down HAOS and use card in your usual PC (if it is Windows there is only one partition visible - only boot partition), and edit file.
(If under Windows use Notepad++ https://notepad-plus-plus.org/downloads/ or VSC - it's important to use an editor capable of editing Linux text files - EOL is different!)

I'm on HAOS 8.0.rc3 and still works (it is RPi4 but it doesn't matter, because all models RPi must use this partition)
Screenshot 2022-04-29 at 15-54-47 Poziomo – Home Assistant
hassos-boot_2022-04-29_16-01

@berkerel
Copy link

Impossible. Maybe you don't have root privileges.

Wow. Thanks for fast response. Indeed. Your solution worked, I have added required entries to config.txt, added entry to application.yml but camera is still not available in HAOS.

Do you have any idea what might be wrong? In logbook I see only shutingdown, starting,restarting entries.

image

@nepozs
Copy link

nepozs commented May 1, 2022

https://www.home-assistant.io/integrations/rpi_camera/
Most important thing:
"This integration is only available on Home Assistant Core installation types. Unfortunately, it cannot be used with Home Assistant OS, Supervised or Container. "
So you must use motionEye addon, not native "RPi camera" integration.

BTW
What is the file application.yml for?

@berkerel
Copy link

berkerel commented May 5, 2022

Yes, you are right. RPI camera do not work. I thought that this thread is about runing native RPi camera on HAOS systems - tweeking, modifying it that way that it would work even when there is no official support. Anyway it worked with motionEye so thumbs up. Thanks for help ;)

PS. Sorry, I meant configuration.yaml

@Playwave
Copy link

This method works on Home Assistant OS 9.4 (2022.12.6)
Cam perfect works through MotionEye.

@derpdounat
Copy link

This method works on Home Assistant OS 9.4 (2022.12.6) Cam perfect works through MotionEye.

Hey do u mind helping me , i kind of am still failing to get it to work

@Playwave
Copy link

This method works on Home Assistant OS 9.4 (2022.12.6) Cam perfect works through MotionEye.

Hey do u mind helping me , i kind of am still failing to get it to work

This post above gives the complete answer. https://gist.github.com/enegaard/a57af286205914bd912270c89650fb1b?permalink_comment_id=4149320#gistcomment-4149320
I added these commands in config file of hassos-boot drive
https://gist.github.com/enegaard/a57af286205914bd912270c89650fb1b#enable-camera-in-configtxt
Then Turn on Raspberry.
Now cam must work, but you cant use it by Raspberry Pi Camera Integration.
Install MotionEye (Settings -> Addons)
Run and add new camera. (use Camera Type - Local V4L2 Camera, codec for example - codec bcm2835-codec-decode)
This allow you to use camera.
You can add stream in dashboard by Picture Card eg, just add streaming URL (in MotionEye settings of cam)

@rubinho101
Copy link

rubinho101 commented Jan 6, 2023

This method works on Home Assistant OS 9.4 (2022.12.6) Cam perfect works through MotionEye.

Hey do u mind helping me , i kind of am still failing to get it to work

This post above gives the complete answer. https://gist.github.com/enegaard/a57af286205914bd912270c89650fb1b?permalink_comment_id=4149320#gistcomment-4149320 I added these commands in config file of hassos-boot drive https://gist.github.com/enegaard/a57af286205914bd912270c89650fb1b#enable-camera-in-configtxt Then Turn on Raspberry. Now cam must work, but you cant use it by Raspberry Pi Camera Integration. Install MotionEye (Settings -> Addons) Run and add new camera. (use Camera Type - Local V4L2 Camera, codec for example - codec bcm2835-codec-decode) This allow you to use camera. You can add stream in dashboard by Picture Card eg, just add streaming URL (in MotionEye settings of cam)

@Playwave Can you share the commands which you added to the config file again? The post you are referring to has been deleted.

In general: I got HA OS 9.4 running on my Rpi4 and I attached a Raspberry Pi Camera Module 2 NoIR which I tested before. So I made the changes to config.txt as suggested start_x=1 + the memory allocation. In addition I installed motionEye. But adding the camera does not work out. Any advice? Do I need to copy the firmware files as well?

EDIT: So I finally got it working, here are my steps:

  1. manually changed the property in etc/motioneye/camera-1.conf from videodevice /dev/video10 to video0
  2. increased the memory to 256
  3. added the following to CONFIG.txt and restarted the Rpi. This would not let the Rpi HAOS 9.4 boot properly
start_file=start_x.elf
fixup_file=fixup_x.dat
  1. undid step 3) and added again start_x=1 and reboot
  2. motionEye finally streams the camera via V4L2 and I can add it to my dashboard

@spitfire
Copy link

spitfire commented Jan 7, 2023

This method works on Home Assistant OS 9.4 (2022.12.6) Cam perfect works through MotionEye.

Hey do u mind helping me , i kind of am still failing to get it to work

This post above gives the complete answer. https://gist.github.com/enegaard/a57af286205914bd912270c89650fb1b?permalink_comment_id=4149320#gistcomment-4149320 I added these commands in config file of hassos-boot drive https://gist.github.com/enegaard/a57af286205914bd912270c89650fb1b#enable-camera-in-configtxt Then Turn on Raspberry. Now cam must work, but you cant use it by Raspberry Pi Camera Integration. Install MotionEye (Settings -> Addons) Run and add new camera. (use Camera Type - Local V4L2 Camera, codec for example - codec bcm2835-codec-decode) This allow you to use camera. You can add stream in dashboard by Picture Card eg, just add streaming URL (in MotionEye settings of cam)

@Playwave Can you share the commands which you added to the config file again? The post you are referring to has been deleted.

In general: I got HA OS 9.4 running on my Rpi4 and I attached a Raspberry Pi Camera Module 2 NoIR which I tested before. So I made the changes to config.txt as suggested start_x=1 + the memory allocation. In addition I installed motionEye. But adding the camera does not work out. Any advice? Do I need to copy the firmware files as well?

EDIT: So I finally got it working, here are my steps:

  1. manually changed the property in etc/motioneye/camera-1.conf from videodevice /dev/video10 to video0
  2. increased the memory to 256
  3. added the following to CONFIG.txt and restarted the Rpi. This would not let the Rpi HAOS 9.4 boot properly
start_file=start_x.elf
fixup_file=fixup_x.dat
  1. undid step 3) and added again start_x=1 and reboot
  2. motionEye finally streams the camera via V4L2 and I can add it to my dashboard

How do I even get to those files from the HAOS?
then I try to mount the boot volume from ssh I'm getting

mount /dev/mmcblk0p1 /media/
mount: mounting /dev/mmcblk0p1 on /media/ failed: Permission denied 

@nepozs
Copy link

nepozs commented Jan 7, 2023

@spitfire
Just don't try to mount - you can shutdown HAOS and edit files on TF card or ssd(@usb enclosure etc.) using any different computer and OS.
Last years HAOS have changed a lot, so maybe editing files on boot partition isn't possible anymore.
BTW

/dev/mmcblk0p1

Is it RPi?

If it is CM4 it should be possible that way:
https://www.raspberrypi.com/documentation/computers/compute-module.html

@spitfire
Copy link

spitfire commented Jan 7, 2023

@spitfire Just don't try to mount - you can shutdown HAOS and edit files on TF card or ssd(@usb enclosure etc.) using any different computer and OS. Last years HAOS have changed a lot, so maybe editing files on boot partition isn't possible anymore. BTW

/dev/mmcblk0p1

Is it RPi?

If it is CM4 it should be possible that way: https://www.raspberrypi.com/documentation/computers/compute-module.html

Yes, RPi4, running 64-bit HAOS 9.4.
Tried adding "start_x=1" to the [all] section of config.txt (got the microsd card out of pi and opened it on my PC) then rebooted.
Still can't see the camera.
I wasn't able to get to the etc/motioneye/camera-1.conf file too.

@nepozs
Copy link

nepozs commented Jan 7, 2023

Yes, RPi4, running 64-bit HAOS 9.4

so I'm pretty sure you do not have partition mmcblk0p1
edit: running HAOS from TF card is really not recommended (as TF / SD cards have a short lifespan), so I thought it is CM4 (there are versions with eMMC onboard).

When you edit config.txt its autogenerated part should stay untouched.

Working config.txt for RPi4

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# HAOS - don't change it!
disable_splash=1
kernel=u-boot.bin

# uncomment for aarch64 bit support
arm_64bit=1

# uncomment to enable primary UART console
#enable_uart=1

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

# Uncomment to disable continous SD-card poll (for USB SSD)
#dtparam=sd_poll_once=on

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Uncomment this to enable GPIO support for RPI-RF-MOD/HM-MOD-RPI-PCB
#enable_uart=1
#dtparam=i2c_arm=on
#dtoverlay=miniuart-bt
#dtoverlay=rpi-rf-mod

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

[all]
#dtoverlay=vc4-fkms-v3d
#max_framebuffers=2

gpu_mem=128
gpu_mem_256=64
gpu_mem_512=128
gpu_mem_1024=128

# Setting start_x to 1 does exactly the same
# thing as the following 2 lines that are commented
# out, but with reduced risk for errors due to typos
start_x=1
#start_file=start_x.elf
#fixup_file=fixup_x.dat
# The next line is optional, if you don't want the
# red LED on the camera to light while the camera
# is active
disable_camera_led=1

BTW Do you remember about motionEye Addon?
Native rpi_camera platform have NOT been working for years using HAOS (it only works in Debian/Raspbian Container (Docker) installations)

I'm not able to show motionEye configuration, but you shouldn't edit a file, try to configure camera from motionEye GUI.
In comments above there are lots of unnecessary steps, only 3 steps are really required

  1. edit config.txt on boot partition (to enable camera hardware support and allocate memory to GPU, some lines are only for compatibility this configuration with older models of RPi, RPi4 should use 128MB)
  2. install Addon motionEye (because native rpi_camera does not work)
  3. configure motionEye from its GUI (it is last step, NOT the first, motionEye could not work properly without camera hardware)

It could depend on camera chipset but for me (OV5647) it was third position from the end of list
RPI_MMAL_2023-01-08_03-39


"Normal" ssh connection in HAOS is without root privileges to host (it is only "fake-root" - it is just inside container), so if you need ssh connection to the host with real root, you have to prepare separate ssh configuration
https://developers.home-assistant.io/docs/operating-system/debugging/#ssh-access-to-the-host

There is also alternate way to do something on the host as real root - using local console (keyboard + monitor) and CLI where you can login as root - in CLI just type login (without user nor pass).

@rubinho101
Copy link

rubinho101 commented Jan 10, 2023

How do I even get to those files from the HAOS? then I try to mount the boot volume from ssh I'm getting

mount /dev/mmcblk0p1 /media/
mount: mounting /dev/mmcblk0p1 on /media/ failed: Permission denied 

I am using SSH and vi to make the file changes remotely via terminal, but its more convenient to simply put the SD card/drive into your PC and make the changes locally.

I wasn't able to get to the etc/motioneye/camera-1.conf file too.

Did you add the motionEye add-on to your HAOS and added a camera? then you can make the change to the videodevice property.
My motionEye settings:
Bildschirmfoto 2023-01-10 um 11 02 22

@rubinho101
Copy link

I'm not able to show motionEye configuration, but you shouldn't edit a file, try to configure camera from motionEye GUI. In comments above there are lots of unnecessary steps, only 3 steps are really required

At least in my case I had to modify the videodevice property to reflect the correct camera-number to make it work...

@nepozs
Copy link

nepozs commented Jan 11, 2023

At least in my case I had to modify the videodevice property to reflect the correct camera-number to make it work...

I can't say: "editing this file is never needed", maybe in some circumstances really is.

BUT

I've configured many motionEye installations, using different hardware (RPi's 0W2, 3B, 3B+, 4B with different CSI cameras: OmniVision OVxxxx or Sony IMXxxx), different OSes and always proper device was on the list, if camera was properly initialized before (config.txt).
(I'm not sure if it always was something like 'mmal-service', maybe in some configurations it was something like 'bcm-some-number-something', but always list contains unwanted devices with indistinguishable names, so trial and error method is necessary).

@generalbytes
Copy link

Hi,
I just want to share what helped in my case to get RaspberryPi camera working with motioneye:
RaspBerryPI 3 B+
Home Assistant 2023.4.6
Supervisor 2023.04.0
Operating System 10.0
motioneye version: 0.19.1

  1. Install motioneye.
  2. Shutdown HA
  3. Take out SDcard mount it on separate computer.
  4. Modify config.txt by adding:
    gpu_mem=128
    gpu_mem_256=64
    gpu_mem_512=128
    gpu_mem_1024=128
    start_x=1
  5. Insert SDcard back to RPi and start motioneye.
  6. Cameras can be now created. Create V4L2 Camera. Unfortunately motioneye creates /dev/video10 by default. We need to change that to /dev/video0
  7. Shutdown HA
  8. Take out SDcard mount it on separate computer.
  9. Modify etc/motioneye/camera-1.conf from videodevice /dev/video10 to video0
  10. Insert SDcard back to RPi
  11. Start RPi
  12. Camera in motioneye should be now working.

@Dris101
Copy link

Dris101 commented Jun 13, 2023

@generalbytes Thanks for the info on the config.txt setup. Very helpful and worked for me.
@nepozs That was my experience as well. There was an option for me (PI3 with camera module) I think near or at the bottom of the list which worked for me and set /dev/video0 by default without me having to edit camera-1.conf

@csprocket777
Copy link

I'm struggling to install motion-eye on Alpine linux. Does this indicate that my installation method doesn't match the requirements?

@Aljumaili85
Copy link

Hi @nepozs
I Couldn't manage to make it work.
Im using
Home Assistant OS: 11.2
Home Assistant Core: 2023.11.3
on Raspberry Pi 4
I followed the setps to enable the camera from the config.txt but nothing changed motioneye coudnt find it, then some guys @generalbytes
mention to edit the camera config file "camera-1.conf" but unfortunately I am using the Motioneye addon so I cant even find where the camera config file is located. any help will be appreciated. Thanks

@nepozs
Copy link

nepozs commented Dec 5, 2023

Hello @Aljumaili85 , I simply can't support this anymore because I don't use RPi in a real HAOS installation and I have to run test at an additional installation to see if this sollution still works. So in fact I don't know if it still works now (today).

If I will do that, I will only post one piece of information: whether it still works on current versions of HA and HAOS or not (as I only will turn on that RPi with cam and update all software needed).

There may be some tricks you need to do at the MotionEye level, but all the ones that were required to run at the time I described them worked, but read this:
https://gist.github.com/enegaard/a57af286205914bd912270c89650fb1b?permalink_comment_id=4432829#gistcomment-4432829
I've never edited MotionEye files "by hand".


Update (You are really lucky, as I'm home now and I could run that old Raspberry installation and as I haven't used ssd drive for other purpose till now)
Motion_Eye_2023-12-05_13-23

Versions
Home Assistant (core) 2023.8.1
Supervisor 2023.11.6
Operating System (HAOS 64bit for RPi4) 10.3
GUI: 20230802.0 - latest (really latest for combination above :P )
motionEye (addon): 0.19.1

I will try to update now

Edit 2
Still works after Update HAOS to 10.5

Edit 3 (some hours later…)
After update all other addons and custom components (not related to camera at all, but I want them to be actual, because this test installation is really complicated and I want to be working as good as possible after next HA and HAOS updates) still works.
Lots of custom components updated, I have to modify configuration.yaml to have "healthy" configuration (disabled 2 custom components, TBD why I had to do it ).

Edit 4
Updating to HAOS 11.2
after OS update Motion Eye does not want to autostart (maybe I'm too quick? TBD), but after manual start addon still works OK

Edit 5 (some hours later…)
Updating to HA core 2023.11.3 … after all updates - everything related to CSI camera and MotionEye addon still works
motion_eye_works_2023-12-05_17-53
motion_eye_works_2_2023-12-05_17-53

Edit 6
Current configurations:
Settings -> System -> Repairs -> "hamburger" menu -> System information -> (popup) System information -> COPY
(and paste clipboard content as is)

System Information

version core-2023.11.3
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.11.6
os_name Linux
os_version 6.1.58-haos-raspi
arch aarch64
timezone Europe/Warsaw
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 5000
Installed Version 1.33.0
Stage running
Available Repositories 1418
Downloaded Repositories 59
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
GIOŚ
can_reach_server ok
Home Assistant Supervisor
host_os Home Assistant OS 11.2
update_channel stable
supervisor_version supervisor-2023.11.6
agent_version 1.6.0
docker_version 24.0.7
disk_total 234.0 GB
disk_used 40.0 GB
healthy true
supported true
board rpi4-64
supervisor_api ok
version_api ok
installed_addons Mosquitto broker (6.4.0), File editor (5.7.0), Samba share (12.2.0), Terminal & SSH (9.8.1), Emulated HUE (0.3.0), ZeroTier One (0.17.3), Z-Wave JS (0.4.1), Studio Code Server (5.14.2), VLC (0.2.0), Glances (0.20.0), Local VLC (18), HDD Tools (1.1.0), Tailscale (0.13.1), Advanced SSH & Web Terminal (16.0.2), Zigbee2MQTT (1.34.0-1), Grafana (9.1.1), eWeLink Smart Home (1.4.3), ESPHome (2023.11.6), Simple Scheduler (2.11), LFTP Mirror (1.0.3), Node-RED (16.0.2), Scrutiny (Full Access) (v0.7.2-3), Zigbee2MQTT (1.34.0-1), Zigbee2MQTT (1.34.0-1), Nextcloud (27.1.4-5), Whoogle Search (0.8.4-3), Run On Startup.d (0.11a), Matter Server (4.10.2), motionEye (0.19.1), Piper (1.4.0)
Dashboards
dashboards 2
resources 33
views 17
mode storage
Recorder
oldest_recorder_run 13 lipca 2023 10:54
current_recorder_run 5 grudnia 2023 16:59
estimated_db_size 469.62 MiB
database_engine sqlite
database_version 3.41.2

my latest config.txt (file on the boot partition), slighly modified because I've used the same ssd with specific board for CM4 (it is installation really for experiments), but I've deleted all unnecessary settings for RPi4B
if your file is somehow different I want see it

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# HAOS - don't change it!
disable_splash=1
kernel=u-boot.bin

# uncomment for aarch64 bit support
arm_64bit=1

# uncomment to enable primary UART console
#enable_uart=1

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

# Uncomment to disable continous SD-card poll (for USB SSD)
#dtparam=sd_poll_once=on

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Uncomment this to enable GPIO support for RPI-RF-MOD/HM-MOD-RPI-PCB
#enable_uart=1
#dtparam=i2c_arm=on
#dtoverlay=miniuart-bt
#dtoverlay=rpi-rf-mod

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
########################################################################
# disable = comment out audio for MirkoPC board only (zakomentowac dla MirkoPC)
dtparam=audio=on

[all]
#dtoverlay=vc4-fkms-v3d
#max_framebuffers=2

gpu_mem=128
gpu_mem_256=64
gpu_mem_512=128
gpu_mem_1024=128

# Setting start_x to 1 does exactly the same
# thing as the following 2 lines that are commented
# out, but with reduced risk for errors due to typos
start_x=1
#start_file=start_x.elf
#fixup_file=fixup_x.dat
# The next line is optional, if you don't want the
# red LED on the camera to light while the camera
# is active
disable_camera_led=1

@nepozs
Copy link

nepozs commented Dec 5, 2023

PS Everything works for me, so I will definitely end supporting this tutorial forever for people writing "help, I have did everything and it do not work" if they do not provide really precise description of steps, configuration and files contents.

Hardware configuration also must be tested before (I use OV5647 camera based, for models with different image sensors configuration in MotionEye may be different)
Suggested environment to test - MotionEyeOS (it is old project, but camera should work - if camera does not work in dedicated OS, it probably won't work using HAOS)
https://github.com/motioneye-project/motioneyeos
but OFC camera could be tested using RPiOS.

PPS Do not try to do it using Cloudflared tunnel, it just do not work (video streaming is forbidden), so if you need remote access use ZeroTier One or Tailscale (both work), but I suggest running locally and try to use remote access only if camera is fully functional.

@Aljumaili85
Copy link

@nepozs , it was really nice of you , Thank you very much.

@Aljumaili85
Copy link

Aljumaili85 commented Dec 7, 2023

Update:
Finally I managed to make it works, I had doubts that there was a camera hardware issue so I recover an old raspbian image where everything was working fine.
anyway I just wanted to show the last lines of the config file, which it might be helpful for someone else.
Last lines of the config.txt (on the boot partition) looks like this :

[pi4]
#Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

[all]
#dtoverlay=vc4-fkms-v3d
start_x=1
gpu_mem=128

@nepozs
Copy link

nepozs commented Dec 7, 2023

In reality only important lines really necessary for working camera

[all]
start_x=1
gpu_mem=128

all others are for different purposes or backward compatibility with old models of RPi
(but there is no sense to run HAOS on models older than RPi4B )

BUT never delete existing lines even if commented out

@jose1711
Copy link

Thank you for this tutorial. Sadly I did not get far trying to make my ov5647 camera work with Raspberry Pi 5. HA OS: 12.1, HA core 2024.4.0. Using Advanced SSH & Web terminal to interact with the HA OS directly over SSH session.

motionEye lists the following devices (multiple instances): pispbe, rp1-cfe, rpivid. None of the entries however seems to work.

Things tried so far

Based on the latest comments I put (appended) the following into config.txt:

[all]
start_x=1
gpu_mem=128

I haven't spotted any change though once booted with these options.

Test in Raspbian (making sure this is not a hw issue)

The camera is properly detected in Raspbian:

root@raspberrypi:/# libcamera-hello --list-cameras
Available cameras
-----------------
0 : ov5647 [2592x1944 10-bit GBRG] (/base/axi/pcie@120000/rp1/i2c@88000/ov5647@36)
    Modes: 'SGBRG10_CSI2P' : 640x480 [58.92 fps - (16, 0)/2560x1920 crop]
                             1296x972 [43.25 fps - (0, 0)/2592x1944 crop]
                             1920x1080 [30.62 fps - (348, 434)/1928x1080 crop]
                             2592x1944 [15.63 fps - (0, 0)/2592x1944 crop]

Attempt to get the same output in HA OS

I am trying to use an equivalent in HA OS, but did not find libcamera-hello, seems like cam (added to HA OS via apk add libcamera-tools) serves as an equivalent. The output is empty.

$ cam -l
[0:11:40.515516942] [485]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0
Available cameras:
$

When switched inside motionEye container I see the following v4l2-ctl devices:

$ v4l2-ctl  --list-devices
pispbe (platform:1000880000.pisp_be):
	/dev/video20
	/dev/video21
	/dev/video22
	/dev/video23
	/dev/video24
	/dev/video25
	/dev/video26
	/dev/video27
	/dev/video28
	/dev/video29
	/dev/video30
	/dev/video31
	/dev/video32
	/dev/video33
	/dev/video34
	/dev/video35
	/dev/video36
	/dev/video37
	/dev/media1
	/dev/media3

rp1-cfe (platform:1f00110000.csi):
	/dev/video0
	/dev/video1
	/dev/video2
	/dev/video3
	/dev/video4
	/dev/video5
	/dev/video6
	/dev/video7
	/dev/media0

rpivid (platform:rpivid):
	/dev/video19
	/dev/media2

Iterating across the whole list and retrieving their controls:

$ for i in /dev/video* /dev/media*; do echo $i; v4l2-ctl -ld $i; done
/dev/video0
/dev/video1
/dev/video19

Stateless Codec Controls

    hevc_sequence_parameter_set 0x00a40a90 (hevc-sps): value=unsupported payload type flags=has-payload
     hevc_picture_parameter_set 0x00a40a91 (hevc-sps): value=unsupported payload type flags=has-payload
              slice_param_array 0x00a40a92 (hevc-slice-params): elems=1 dims=[4096] flags=has-payload, dynamic-array
            hevc_scaling_matrix 0x00a40a93 (hevc-scaling-matrix): value=unsupported payload type flags=has-payload
         hevc_decode_parameters 0x00a40a94 (hevc-decode-params): value=unsupported payload type flags=has-payload
               hevc_decode_mode 0x00a40a95 (menu)   : min=0 max=0 default=0 value=0 (Slice-Based)
                hevc_start_code 0x00a40a96 (menu)   : min=0 max=1 default=0 value=0 (No Start Code)
/dev/video2
/dev/video20
/dev/video21
/dev/video22
/dev/video23
/dev/video24
/dev/video25
/dev/video26
/dev/video27
/dev/video28
/dev/video29
/dev/video3
/dev/video30
/dev/video31
/dev/video32
/dev/video33
/dev/video34
/dev/video35
/dev/video36
/dev/video37
/dev/video4
/dev/video5
/dev/video6
/dev/video7
/dev/media0
Unable to detect what device /dev/media0 is, exiting.
/dev/media1
Unable to detect what device /dev/media1 is, exiting.
/dev/media2
Unable to detect what device /dev/media2 is, exiting.
/dev/media3
Unable to detect what device /dev/media3 is, exiting.

Could someone please confirm that cam ran inside ssh session works for him/her and/or provide any clues (not sure if anyone has tested with Rpi 5 yet). Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment