core icon indicating copy to clipboard operation
core copied to clipboard

possibility to turn on/off gpio when specific zone is playing.

Open p4co86 opened this issue 9 months ago • 26 comments

Hi, is it possible to implement an option to switch on a specific gpio when some zones are playing?

Iam using two KAB9 and it is possible to switch it to mute or standby via relays. An option to delay the output of the zones would be also nice.

It is very helpful for minimizing power,

p4co86 avatar Feb 18 '26 18:02 p4co86

What output are you running? Depending on the output, it might already be available client side. I assume the gpios are also client side?

For example sendspin has hooks for stream start and stream end which allow you to run your own script.

I believe this is also possible with squeezelite, but I am not sure how this works. @mr-manuel might be able to tell you more about it.

Right now lox-Audioserver has this delay, but it is only for alerts. This should be moved to a per zone one time delay when the zone is off. I will look into this.

rudyberends avatar Feb 18 '26 19:02 rudyberends

i use squeezelite as output. My Hardware is a RPI4. Thanks

i used the MS4H in the past. Its the old custom Musicserver for loxone by Dieter Schmidberger. There was a powermanger installed with wich you could mute the amps.

https://music-server.net/help/MusikServer4Lox.html?Powermanager1.html

p4co86 avatar Feb 18 '26 19:02 p4co86

Through the command line options of the Squeezelite player you can make yourself a script: https://github.com/ralph-irving/squeezelite/blob/6d571de8fa6dfff23a5a0cbb2c81b402d2c30c31/main.c#L64-L150

Relevant for you:

-S <Power Script>    Absolute path to script to launch on power commands from LMS

Here a sample from ChatGPT: https://chatgpt.com/share/69969707-24ac-8000-bf18-714796eaefa1

mr-manuel avatar Feb 19 '26 04:02 mr-manuel

I have built a configuration interface to map amps to speakers & zones aswell as a very simple "powermanager" replacement: It watches alsa streams and switches on amps via crelay.

If anyone is interested I am happy to share it.

tobsch avatar Feb 19 '26 21:02 tobsch

hi, i havent find the time to test the squeezelite solution. Wow, that sounds awesome, yes it would be nice you share it with us.

I will test it asap.

p4co86 avatar Feb 20 '26 05:02 p4co86

@p4co86 here you go: https://github.com/tobsch/snappy It's not super self explaining as I purely wrote it for myself initially. But give me feedback, please!

tobsch avatar Feb 21 '26 21:02 tobsch

Hi, thanks, i have solved it with the Multiio Plugin for Loxberry. Here you can turn on GPIO and use the Aufioplayerstate for switching. I have used a Delay for switching off. Worked very well.

p4co86 avatar Feb 22 '26 16:02 p4co86

Hi, thanks, i have solved it with the Multiio Plugin for Loxberry. Here you can turn on GPIO and use the Aufioplayerstate for switching. I have used a Delay for switching off. Worked very well.

Will that be enough for you, or do we still need to look for a native powermanagment implementation?

rudyberends avatar Feb 22 '26 16:02 rudyberends

A native solution would be nicer to have all in one, no dependience and so on, but for the first it is ok for me.

p4co86 avatar Feb 22 '26 16:02 p4co86

A native solution would be nicer to have all in one, no dependience and so on, but for the first it is ok for me.

Power management will be in the next beta. Switching will be experimental and ay require some feedback.

https://github.com/lox-audioserver/lox-audioserver/issues/184#issuecomment-3968966279

rudyberends avatar Feb 26 '26 21:02 rudyberends

That looks fantastic! Could you tell us when the next beta version will be released so we can test it?

p4co86 avatar Feb 27 '26 12:02 p4co86

Thank you for the new Beta8. i tested the power manager. Iam Using an RPI4 and tried to switch gpio 22 letting everithing on default in the powermanager page and used sysfs. Put GPIO is not switching.

EDIT: I asked chatgpt, i have an offset of 512, so switching GPIO22 means 534. echo 1 > /sys/class/gpio/gpio534/value this command is switching GPIO 22. But with the same settings in the audioserver it doesent work. Any Ideas?

The Audioserver is installed in loxberry wich os is dietpi.

For improvement, it would be also nice to switch a second gpio for the powerunit.

For future things i will use an odroid n2+ would this also work for it?

p4co86 avatar Mar 01 '26 18:03 p4co86

The basic powermanagement code is in there. It now has a power state and an on and off timeout for setting this state. The on timeout will be used as a delay to start the audio on the zone. Off timeout can be used to trigger a power off.

For the switching I would like to get some feedback on how to implement this, as I don't use this myself.

rudyberends avatar Mar 02 '26 17:03 rudyberends

Hi and thanks again, as i described in my post before. the GPIO und CRelay does not work for me. I have deleted all my containers and config and started from scatch.

For the CRelay ihave checked it and it is listet as /dev/hidraw1 but that also des not work for me. Maybe it has someting to do with privileges. I use this one https://www.amazon.de/dp/B07L12DXWB?ref_=ppx_hzsearch_conn_dt_b_fed_asin_title_1 i have used it in combination with MS4H and the powermanager. As described above it would be also nice to group some zones so that you can switch nother gpio for the PSU.

Thanks

p4co86 avatar Mar 02 '26 17:03 p4co86

Did it work with MS4H and the powermanager?

rudyberends avatar Mar 02 '26 18:03 rudyberends

Yes it does with crelay, i have not seted it up. I remember the write the serial number in a settings field. I try to get some more infos later and then i will post it.

p4co86 avatar Mar 02 '26 18:03 p4co86

As described here: https://music-server.net/help/Powermanager1.html

With Crelay a serial number pops up, you have to write it in the settingsfield and choose relay 1 up to 8 and it was switching.

This command works, gpio 22 is switching: echo 1 > /sys/class/gpio/gpio534/value

its an offset of 512, i dont remember, there was a command wich shows gpiochip512, the i asked chatgpt thats how i came to gpio534. But trying it with the powermanager here it does not work either with gpio 22 or 534. as driver i tried sysfs and gpioset. both dont work

here is the log for sysfs:

lox-audioserver-logs-2026-03-02T19-21-25-703Z.txt

and here with gpioset:

lox-audioserver-logs-2026-03-02T19-23-54-589Z.txt

here for crelay:

lox-audioserver-logs-2026-03-02T19-26-04-082Z.txt

p4co86 avatar Mar 02 '26 19:03 p4co86

with privileged: true in the docker-compose.yml gpiochip0 and offset 22 i can switch gpio22 an my rpi4. thanks!

will test it in the evening with odroid n2+ and crelay on both hardwares.

would it be possible to group zones to switch another gpio to switch off the powerunit.

p4co86 avatar Mar 07 '26 08:03 p4co86

Hi, CRelay is also working, tested on Odroid N2+. I have now switched to an odroid n2+ where the gpio does not work. When i configer it, my Odroid stops working, is not reachable wie web interface or ping, then i have to restart it and undo it.

The command "gpiodetect" gives me "command not found", i have then installed gpiod via "apt install gpiod", after that "gpiodetect" worked. Haven`t found the time to test it again after the installation.

p4co86 avatar Mar 09 '26 08:03 p4co86

with ghcr.io/lox-audioserver/lox-audioserver:testing-20260309083339 i have tested the groups. I have noticed two thinks:

Take a look at the Switching method......... Image

p4co86 avatar Mar 09 '26 13:03 p4co86