Autochange audio output

  • Hi everybody, I have some box with LibreELEC installed and in one of them I have paired a Bluetooth headset because during night hours I don't want to "wake up" my family due to TV audio. My question is simple: is there a way to auto change audio output when the Bluetooth headset connects to the box?

    My idea is to write a udev rule to execute a script that changes audio output when a Bluetooth (specific) device connects. But before proceeding I'm asking if there is a build-in function that I might have missed :) thank you

  • Thanks for your reply:) that plugin should be useful to effectively change audio output But in a keyboard click or with a pop-up and it sill requires user input (not so difficult I know but I would like to be all automatic): for sure I will use this plugin in a (possible) udev rule with his build-in function RunScript(). If no one has other ideas I will use udev+this plugin...
    Thank you for your reply

  • Any progress anthontex?

    Like this as script:

    ..but this is a copy/paste what i had found around the net. The addr is clear for me but what now?
    The best would be to switch here automatically between the "Audio Profile swicher" profiles (more saved options in the profile1.json like video resolution, etc)!

    Hope anybody here can light me up! :blush: :heart:

    Edited once, last by Cris_ ().

  • Any progress anthontex?
    Hope anybody here can light me up! :blush: :heart:

    yes, i have 2 solutions for this problem: 1 was the udev rule that changes audio output (when a specific device was connected) , it works but unfortunately my headset doesn't autoconnect always, and i had to open LibreELEC settings> connect and only then the audio output automatically changed. 2 was using a script (old idea from someone at kodi forums) and map that script to my remote controller (for example when i log press my home button the script is executed) this script not only switch audio output but also "ping" LibreELEC to connect to my headset, so it resolves both problems. I suggests you the second way, because there are some headsets that don't autoconnect automatically. If you need i can copy script and write the how to...

  • The best would be to switch here automatically between the "Audio Profile swicher" profiles (more saved options in the profile1.json like video resolution, etc)!

    Hope anybody here can light me up! :blush: :heart:

    I have something like that going on. It's based on this.
    My version of 99-btautoconnect.rules in storage/.config/udev.rules.d (trying a few BT receivers / headphones as you can see):

    1. ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="00:11:67:85:63:60", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/"
    2. ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="00:11:67:85:63:60", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/"
    3. ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="00:1F:81:08:25:AB", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/"
    4. ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="00:1F:81:08:25:AB", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/"
    5. ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="E8:28:AB:12:83:30", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/"
    6. ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="E8:28:AB:12:83:30", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/"
    7. ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="E8:28:AB:12:86:21", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/"
    8. ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="E8:28:AB:12:86:21", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/"
    9. ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="CD:63:90:94:A0:AA", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/"
    10. ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="CD:63:90:94:A0:AA", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/"

    So I'm using those to start one of two shell scripts...

    1. #!/bin/sh
    2. /usr/bin/kodi-send --action="RunScript(,1)"

    switch to

    1. #!/bin/sh
    2. /usr/bin/kodi-send --action="RunScript(,2)"

    Obviously my shell script locations won't work for you - just edit 99-btautoconnect.rules to point to wherever you want to stick them, add your MAC address(es), and change the audioprofile in the shell script to the required one for BT / TV.

  • Ok, little problem here. It seems that the 99-btautoconnect.rules doesnt work for me. The addr is correct! Scripts with this path are working (tested in terminal, bash /
    Any specific permission for the rule file?

    1. ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="00:22:37:1B:F7:2F", RUN+="/storage/.kodi/userdata/scripts/"
    2. ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="00:22:37:1B:F7:2F", RUN+="/storage/.kodi/userdata/scripts/"

    Edited once, last by Cris_ ().

  • Code
    1. journalctl -a | grep udevd
    2. Nov 17 14:59:31 Raspi systemd-udevd[911]: failed to execute '/storage/.kodi/userdata/scripts/' '/storage/.kodi/userdata/scripts/': Permission denied
    3. Nov 17 14:59:31 Raspi systemd-udevd[910]: Process '/storage/.kodi/userdata/scripts/' failed with exit code 2.
    4. Nov 17 14:59:31 Raspi systemd-udevd[913]: failed to execute '/storage/.kodi/userdata/scripts/' '/storage/.kodi/userdata/scripts/': Permission denied
    5. Nov 17 14:59:31 Raspi systemd-udevd[910]: Process '/storage/.kodi/userdata/scripts/' failed with exit code 2.


  • sh /storage/.kodi/userdata/scripts/ post

    It seems there is something wrong in the 99-btautoconnect.rules.
    Tried to copy the scripts to another folder, same behaviour.

    Edited once, last by Cris_ ().

    Deleted the /storage/.kodi/userdata/scripts folder and recreate on same path. Copied the two .sh. Voila!
    Don't know what gives the trouble but hey.

    Big THANKS trogggy

    Edited once, last by Cris_ ().

  • Hi, have a problem. udev rule doesn't work anymore to trigger my Audio Profiles scripts

    I'm now on latest Kodi Milhouse build (leia). Doesn't changed anything since my #13.

  • The problem is that the udev settings have changed in the latest releases.

    To fix the problem you have to override a setting to allow local network connections in udev.

    To do this you have to execute the following command using ssh:

    1. systemctl edit systemd-udevd

    Then you have to add these lines:

    1. [Service]
    2. IPAddressAllow=localhost

    Then press Ctrl+o and Ctrl+x to save the file and exit the editor.

    Then it should work again ;)