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_ (November 17, 2016 at 11:11 AM).


  • 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):

    Code
    ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="00:11:67:85:63:60", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/switchtoHDMIprofile.sh"
    ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="00:11:67:85:63:60", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/switchtobluetoothprofile.sh"
    ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="00:1F:81:08:25:AB", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/switchtoHDMIprofile.sh"
    ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="00:1F:81:08:25:AB", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/switchtobluetoothprofile.sh"
    ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="E8:28:AB:12:83:30", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/switchtoHDMIprofile.sh"
    ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="E8:28:AB:12:83:30", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/switchtobluetoothprofile.sh"
    ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="E8:28:AB:12:86:21", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/switchtoHDMIprofile.sh"
    ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="E8:28:AB:12:86:21", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/switchtobluetoothprofile.sh"
    ACTION=="remove", SUBSYSTEMS=="input", ATTRS{name}=="CD:63:90:94:A0:AA", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/switchtoHDMIprofile.sh"
    ACTION=="add", SUBSYSTEMS=="input", ATTRS{name}=="CD:63:90:94:A0:AA", RUN+="/storage/.kodi/userdata/favourites/scripts/audioscripts/switchtobluetoothprofile.sh"

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

    Bash
    #!/bin/sh
    
    
    /usr/bin/kodi-send --action="RunScript(script.audio.profiles,1)"


    switch to bluetoothprofile.sh:

    Bash
    #!/bin/sh
    
    
    /usr/bin/kodi-send --action="RunScript(script.audio.profiles,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.

    Edited once, last by trogggy (November 17, 2016 at 11:50 AM).

  • 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 /...sh)
    Any specific permission for the rule file?

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

    Edited once, last by Cris_ (November 17, 2016 at 1:09 PM).

  • All I did wasmake it in notepad++, sling it in and reboot, sorry.
    Did you make it in windows? If so maybe run dos2unix /storage/.config/...?
    Only other thing I can think is to run chmod +x /storage/.config/...etc.

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

    ..mhh?!

  • sh /storage/.kodi/userdata/scripts/switchtobluetoothprofile.sh post
    Works!

    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_ (November 17, 2016 at 3:13 PM).

  • What do you see if you run:

    Code
    ls -l /storage/.config/udev.rules.d


    ?
    For reference I get:

    Code
    -rwxr--r--    1 root     root          1599 Nov  4 02:28 99-btautoconnect.rules
  • UPDATE: YES IT WORKS NOW! :D
    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_ (November 17, 2016 at 8:32 PM).

  • 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:

    Code
    systemctl edit systemd-udevd

    Then you have to add these lines:

    Code
    [Service]
    IPAddressAllow=localhost

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

    Then it should work again ;)