Restart Hyperion.NG on plug in the USB grabber

  • Maybe will be useful for someone:


    System: Hyperion.NG running on Raspberry Pi 3 b+, Raspbian OS, USB capture device
    Problem: if USB graber is plugged off and then again plugged in, then the hyperion does not get video signal and ambilight does not work.
    Solution Idea: restart aitomatically hyperion service if USB graber plugged in. Use udev for that...
    Solution implementation:
    1) Make new udev rule:
    1.1) Execute command:

    Code
    sudo nano /etc/udev/rules.d/99-USBVideo.rules


    1.2) In the nano editor insert the rule line like this (eventually you need to change the device name /dev/video0):

    Code
    ACTION=="add", SUBSYSTEMS=="usb", ENV{DEVNAME}=="/dev/video0", RUN+="/bin/sh -c 'sudo systemctl restart hyperiond@root.service'"


    1.3) Use Ctrl+X, Y, Enter to save and exit the editor
    2) Reload rules using command:

    Code
    sudo udevadm control --reload-rules && sudo udevadm trigger


    If something doies not work, an additional RUN can be added to the rule line to check if it is executed on plug:

    Code
    RUN+="/bin/sh -c 'echo $(date) $(env) >>/tmp/udev-debug.log'"


    In this case the whole rule is like this:

    Code
    ACTION=="add", SUBSYSTEMS=="usb", ENV{DEVNAME}=="/dev/video0", RUN+="/bin/sh -c 'sudo systemctl restart hyperiond@root.service'", RUN+="/bin/sh -c 'echo $(date) $(env) >>/tmp/udev-debug.log'"


    Each time the rule triggers, a new line will be added to the file /tmp/udev-debug.log. You can read this file to check if the rule has triggered.


    Hyperion can also be stopped if usb grabber is unplugged, it reduces prozessor load. For that add second line to the USB-video.rules file:

    Code
    ACTION=="remove", SUBSYSTEMS=="usb", ENV{DEVNAME}=="/dev/video0", RUN+="/bin/sh -c 'sudo systemctl stop hyperiond@root.service'"


    Note: this way hyperion deamon is started as root. You might need to configure hyperion again, if you have used and configured it as pi user before.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!