-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LEDs in /sys/class/leds
not usable due to Supervisor's read-only mount; related to GPIO: true
#4560
Comments
I'm confused, you are asking for a way to change the LEDs from an addon. Addons only exist in a supervisor install. So a supervisor install is required regardless of how the solution is implemented here... Regardless our preferred approach here is to have OS Agent publish a Dbus interface for supported boards with options for that board. Rather then having addon developers modify the host OS directly. This doesn't add any extra dependency though because like I said, addons do not exist in an HA install if there is no supervisor. Also the main goal here is to add options to HA frontend to allow users to set features of their board (like LEDs). The frontend can only talk to HA and Supervisor APIs so we must expose these features that way. I wasn't aware of a use case where addon developers wanted to modify LEDs until now but if so the APIs are available for them too. Be aware though that currently changes to the LEDs require a reboot to take effect. |
The goal is for "something" in HA to render an config/options UI that when used adjusts the LEDs on a RPi. This "something" would also expose a set of services that allow any other something in HA to call them to programatically adjust same LEDs. My experience to date is HAos. Addons are the "something" that I have so far learned that allow me to write code, that touches hardware, that can render a UI, and expose services. @mdegat01 the I've briefly reviewed the "green" and "yellow" board code that works with dbus. That is the 3rd verbose approach I listed. I didn't notice that it needed a reboot. No one likes rebooting. Isn't that one of Linux' glorious benefits? 😉 |
HAOS has supervisor. The only two types of installs with addons are an HAOS install and a Supervised install. Both of which include supervisor. |
Great. Then option 1 works. To add the two LED class folders to the |
What is your intention? Do you plan to control the LED through automations? The preferred way for boards is through OS Agent. Yes it adds some boiler plate code in OS Agent and Supervisor, but it makes a clear abstraction. That way, since the OS Agent is part of the OS, if the sysfs paths change (e.g. due to kernel/device tree changes from the Raspberry Pi), we can simply adjust the LED paths in the OS Agent. |
I view this issue (perhaps I should re-title it) as a GPIO permission inquiry. There are some GPIOs that the existing Supervisor codebase does not include in their RW mount for I learned that the RPi LEDs are all controlled by the primary GPIOs or the VPU GPIO extender. Given that, I consider You write I don't see any value in the OS agent approach.
Reminder on my addon's intention. But this discussion is really about missing GPIOs...
|
Just to be clear, the LED features in OS agent and supervisor had nothing to do with addons. Addons controlling LEDs wasn't even a considered use case tbh. That's why I said earlier, this was the first I heard of it. The purpose of the feature was to get this screen working in the HA frontend: The frontend runs on the client. It cannot mount things into a container from the host to modify them. The only way the frontend can enact change is via an API. So supervisor having APIs to set board features is required. As you noted, addons don't have this limitation, they can mount things into their container and change them. And already have some access to
I was half wrong on this. Apparently for green we do not require a reboot. Yellow still does but that will be corrected soon. The consequence however is that these values are not persisted on the host. Supervisor will save the latest values it has seen via its API and resubmit them every time it restarts. This approach likely means modifying the host directly will not work very well as supervisor will undo your changes each restart. So if we want to support this approach, supervisor also needs a way to know what happened on host without its involvement so it can update its cached settings. Or we need to make these changes persistent on the host again so supervisor does not have to cache settings. Again though to be clear, addon support is not the primary use case. The primary use case is the UI I screenshoted above. If we have to choose between making it easy and simple for addons to set LEDs and making it easy and simple to set values of LEDs in the UI, we are choosing the latter. |
Again this is about use of GPIOs from AddOns that are not yet included with My references to yellow and green are only to caution that their approach does not appear sustainable. This option#3 having the amount of (rpiBoards * 400 changes) over (rpiBroads * 16) files is extreme. Perhaps you misunderstand...I have no ask for anything with Agent, Yellow, or Green. Option#1 is only an add of 47 characters to line 409 in OP. That is multiple magnitudes less code and inter-component/file complexity -- resulting in easier to understand, test, and maintain. It keeps in alignment the feature of enabling an AddOn to access gpios AddOns controlling hardware are very common. I reference one in the OP. Another is Deconz that needs gpio, usb, and rawio https://github.com/home-assistant/addons/blob/cd11be29f99ad544b76679b09a33cdf86291bbe2/deconz/config.yaml. The nature of a new feature/progress...is that someone before had not heard or thought of it. Nothing unusual about that. My addon that needs this GPIO aka LED access will not do anything on yellow or green boards. It will not read or write to them or conflict. I explicitly list only valid machines (in the config.yaml) and further check for valid machines and paths within the addon code itself. The addon will only be enabled -and- actually run on a subset of RPis (with more RPi to come later with testing). Home assistant AddOns persist their own state automatically. I use standard AddOn features...there is no need for Supervisor to be involved in these settings. Therefore, the concern of your last two paragraphs is not relevant. I can imagine an Option#4: It would be a one-line method to add needed RW mounts for GPIOs for a given board to the Supervisor codebase. Look at the following code...it defines in a central place needed mounts... supervisor/supervisor/docker/const.py Lines 73 to 91 in e1232bc
That constants file is a central place where mounts are described. Those constants are then used in the code from the OP. supervisor/supervisor/docker/addon.py Lines 451 to 453 in e1232bc
As I review this code as I type, I believe the GPIO code in that same file has a hack in it. The conversations I write above led to commit 9eee8ea hardcoding the path here instead of using the constant file. If this issue causes the code to be touched, I recommend fixing this -- move the hardcoded GPIO paths on line 409 to the central supervisor/supervisor/docker/addon.py Lines 407 to 419 in e1232bc
Next, where do the GPIO paths for boards go? that I encourage yellow and green to be interactive. That's good news to read 🎺 though doesn't help RPi customers. https://analytics.home-assistant.io/ shows that RPi 4 is the # 1 hardware platform (not vm) and HaOS the # 1 install method. Adding the needed GPIO aka LED permissions for the number 1 on number 1 can enable them to easily create solutions (like my LED addon). |
We do not use RPI as a multi-propose board nor support all ways you can use an RPI. It is just like green and yellow, and we offer our way of running an RPI. |
@pvizeli thanks for perspective. I agree using standards is a good approach when balanced with needs. Are there non-NabuCasa APIs available that can easily expose LED control when Haos is used? Methods for non-NabuCasa platforms/boards (Rpi, orange, odroid, xyzabc)? The standard up to kernel 6.6rc2 for controlling LEDs continues to be https://docs.kernel.org/leds/leds-class.html. I see no writing in the 6.6 docs suggesting deprecation or that new LED APIs are coming. There is a read-the-brightness I probed gpiochipXXX using
|
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. |
#keepalive |
First off, a bit background on the OS Agent implementation: We've added a board specific D-Bus API mainly to expose firmware/bootloader functionality. One of the primary idea was to abstract board configuration such as overlays to be loaded on Raspberry Pi (typically controlled via But I fully agree with your observations: The implementation ended up quite clunky, especially on Yellow. The reboot requirement was mostly because we used the overlay capability to store the LED state. Using overlays make sense for other hardware configuration, but not so much for LED. The board implementation of Green already departed from that approach, writing to sysfs directly. The state is stored in Supervisor. At that point the question why we need to go through D-Bus to "just" write a file is legitimate.
While it looks like we would limit this to Nabu Casa hardware, that is not the intention. We are an open source project, any similar implementation for other boards are welcome (after all, the initial design had very much Raspberry Pi in mind). There is always value in abstraction. But also cost. It is a tradeoff. We've decided to continue the approach to give add-ons direct access to hardware where we have a good abstraction from the kernel. And the LED subsystem qualifies for that.
You seem to use GPIO and LED somewhat interchangeable in your comments. In #4560 (comment) you say your issue is about missing GPIOs, whereas #4560 (comment) emphasize on missing In any case, I agree with your findings that However, we definitely should not conflate this user space API with the |
Got it. I'm following your train of thought. While I would like to support random LED manipulation apis so to support those that don't use Traveling this week, can better engage next week. |
Describe the issue you are experiencing
My addon to control RPi power and activity LEDS needs write access to
/sys/class/leds
. https://docs.kernel.org/leds/leds-class.html. HassOS + Supervisor mounts it read-only. No perm setting, e.g.full_access: true
can enable this. This issue is the mount as read-only. Therefore, it is not possible to control these LEDs from an addon. 😞This issue is more about permission policies/feature. Refer to the sister issue of GPIO support
gpio: true
in #201 (comment).On RPi+kernels I've tested...individual LEDs in
/sys/class/leds
are symlinks to../../devices/platform/leds
aka/sys/devices/platform/leds
. The technical solution is a rw mount of/sys/class/leds
and/sys/devices/platform/leds
like was done for GPIO in the sister issue and implemented heresupervisor/supervisor/docker/addon.py
Line 409 in 2605f85
A fixes can be trivial. It is a philosophy choice...
leds: true
could be created which is likely a copy/paste of much of the GPIO code.What type of installation are you running?
Home Assistant OS
Which operating system are you running on?
Home Assistant Operating System
Steps to reproduce the issue
Repro
config.yaml
. Any combination will repro the issue. For exampleecho "none" > /sys/class/leds/PWR/trigger
Result
Addon fails with error in logs
If you add in your
run.sh
a line withmount
, then the log will also show all mounts within that container. And you will see the cause of the error is due to the RO mount of /sys.Expected
No error.
Anything in the Supervisor logs that might be useful for us?
System Health information
System Information
Home Assistant Cloud
Home Assistant Supervisor
Dashboards
Recorder
Supervisor diagnostics
config_entry-hassio-2cb0d81ab06d8ffebfd5deffc58e5aaa.json.txt
Additional information
No response
The text was updated successfully, but these errors were encountered: