timrogers / litra-rs

💡 Control your Logitech Litra light from the command line
MIT License
35 stars 4 forks source link

Problems trying to automate the auto-toggle function #30

Closed kabe-inc closed 3 weeks ago

kabe-inc commented 8 months ago

First off, thanks very much for creating and maintaining this project. I was very pleased to see the recent appearance of the auto-toggle feature, but I am experiencing something teething problems when trying to automate it and am hoping you might be to enlighten(!) me.

The auto-toggle function seems to work perfectly when run manually in a terminal, but seeing as I don't want to have to do that at every startup I tried to create a systemd service instead, using the following config:

[Unit] Description=Logitech Litra Service After=network.target StartLimitIntervalSec=0

[Service] Type=simple Restart=always ExecStart=/usr/local/bin/litra auto-toggle WorkingDirectory=/usr/local/bin/ StandardOutput=inherit StandardError=inherit SyslogIdentifier=mybinaryprogram User=root Group=root

[Install] WantedBy=multi-user.target`

This method seems to work at first glance but I quickly noticed that the light is being auto-toggled on even when no camera device is active, like the service is picking up on a false positive activation event (or something similar).

Can you spot anything I'm doing wrong, or would you suggest another way to go about this?

Many thanks!

System: EndeavourOS Kernel: arch 6.6.18-1-lts Light: Litra Glow Camera: Logitech C920

timrogers commented 8 months ago

@Holzhaus I think you'll be in the best position to help with this ❤️

Holzhaus commented 8 months ago

You say it worked perfectly when running on the terminal. As which user did you run it? As root or as your regular user? If the latter is the case, try to replace the User=root in the systemd config with your username.

Currently, the auto-toggle command monitors all accesses to /dev/video* devices. My guess would be that your local user lacks permission to do that for some device files, but root has that permission, and that these files cause the false positives.

One easy fix could be to add a command line argument where you specify a video device. That way other video devices would be ignored. But I'm not sure if the video devices have a predictable order a cross restarts. Maybe some way to specify a video device by serial number or similar would be preferable.

kabe-inc commented 8 months ago

Thanks for the reply.

As which user did you run it? As root or as your regular user? If the latter is the case, try to replace the User=root in the systemd config with your username.

I ran it under my admin account, using sudo. I put the user as root in the config because running the command manually from the terminal under my user account without sudo gives a Permission denied error. I assume that this would also be the case if I amended the User=root in the config to User=myusername>?

One easy fix could be to add a command line argument where you specify a video device. That way other video devices would be ignored. But I'm not sure if the video devices have a predictable order a cross restarts. Maybe some way to specify a video device by serial number or similar would be preferable.

This sounds like a good idea to me. My latop has a built-in webcam (which I never use) in addition to the USB webcam, so being able to isolate specify the Logitech via a command would be a nifty feature.

Holzhaus commented 7 months ago

Please have a look at #39 and let me know if this works for your use-case. IBM not sure that the device paths are actually stable across restarts, this would also make sense to check.

To find the correct path you can use v4l-ctl --list-devices.

Holzhaus commented 7 months ago

Regarding the permission issue, check the README. If you install the udev rules you should be able to run litra as regular user:

https://github.com/timrogers/litra-rs?tab=readme-ov-file#configuring-udev-permissions-on-linux

kabe-inc commented 7 months ago

Adding the udev rules worked a treat, thanks.

So with the #39 build, I should add LITRA_VIDEO_DEVICE_PATH=/dev/video2 as an environment variable and then run auto-toggle with no arguments, correct? (FWIW, the device path seems stable for my machine at least.)

kabe-inc commented 7 months ago

As a follow-up, I've found that the test build works just the same as the latest release for my purposes.

I've actually found that running 'auto-toggle in the background via a startup bash script works better than running it as a systemd service, anyway, so that's what I'd recommend to anyone else trying to achieve the same thing.