I have been using a custom python script in kodi to control the volume on my AVR:
<key id="192">RunScript(/storage/.config/volume_mute.py)</key>
The problem with these is that when I press the button to control the volume, kodi deactivates the screensaver, and also when I’m watching a different input, like Live TV on the TV, CE switches the TV back to its input via CEC.
I believe CoreElec uses eventlircd to read the remote codes.
Is it possible to access the socket that eventlircd uses so I can write my own script to run the volume script outside of kodi?
Can anyone give me an example of how to do that, or any tips at all? Or even the location of the socket it uses?
It would help to know what code is in volume_mute.py. Does running the python script from SSH change the TV input too?
I believe it can run from ssh.
volume_mute.py:
#!/usr/bin/python
import subprocess
subprocess.run(["/storage/.config/volume.sh m"], shell=True)
The python script just calls a bash script that uses nc to send commands to the AVR.
Definitely running /storage/.config/volume.sh m over ssh will mute the AVR.
I can see the remote presses using irw
/usr/share/lirc/configs # irw
73 0 KEY_VOLUMEUP devinput
72 0 KEY_VOLUMEDOWN devinput
71 0 KEY_MUTE devinput
a7 0 KEY_RECORD devinput
a1 0 KEY_EJECTCD devinput
I can see that irexec is there, that’s what I used to use in Ubuntu to do this.
~/.config # irexec
irexec: could not open config files /storage/.lircrc and /etc/lirc/lircrc
irexec: No such file or directory
Cannot parse config file
I think I’m close to getting it working, just not sure how to set up irexec in CE as a service that runs all the time to run scripts from IR remote inputs.
You’re using CEC to control your AVR and not an IR blaster? This seems a bit convoluted for CEC control. CEC commands can be sent directly to the CEC device in the initial python script, without having to call another bash script that calls another program
Volume up
coreelec:~ # printf '\x10\x44\x41' > /dev/aocec
Volume down
coreelec:~ # printf '\x10\x44\x42' > /dev/aocec
Toggle mute
coreelec:~ # printf '\x10\x44\x43' > /dev/aocec
No, I’m using telnet to control the AVR (a Denon).
/storage/.config/volume.sh:
#!/bin/bash
Address=10.0.0.10
numrepeats=4
echo "$(date) $1" >> /storage/.config/volume.log
if [[ "$1" == "u" ]]
then
echo "sending up volume"
for (( c=1; c<=$numrepeats; c++ ))
do
echo MVUP | nc $Address 23
done
elif [[ "$1" == "d" ]]
then
echo "sending down volume"
for (( c=1; c<=$numrepeats; c++ ))
do
echo MVDOWN | nc $Address 23
done
elif [[ "$1" == "tvaudio" ]]
then
echo "switching to TV Audio"
echo SITV | nc $Address 23
elif [[ "$1" == "m" ]]
then
echo "toggling mute"
mutestatus=$(cat <(echo 'MU?') <(sleep 0.1) | nc 10.0.0.10 23 | tr '\r' '\n')
if [[ "$mutestatus" == "MUOFF" ]]; then
echo MUON | nc $Address 23
elif [[ "$mutestatus" == "MUON" ]]; then
echo MUOFF | nc $Address 23
else
echo "could not get mute status"
fi
elif [[ "$1" == "tog_dynvol" ]]
then
echo "toggling audyssey dynamic volume"
dynvolstatus=$(cat <(echo 'PSDYNVOL ?') <(sleep 0.1) | nc 10.0.0.10 23 | tr '\r' '\n')
if [[ "$dynvolstatus" == "PSDYNVOL LIT" ]]; then
echo 'PSDYNVOL OFF' | nc $Address 23
elif [[ "$dynvolstatus" == "PSDYNVOL OFF" ]]; then
echo 'PSDYNVOL LIT' | nc $Address 23
else
echo "could not get audyssey dynamic volume status"
fi
elif [[ "$1" == "smode" ]]
then
echo -n "toggling sound mode - "
smodestatus=$(cat <(echo 'MS?') <(sleep 0.2) | nc 10.0.0.10 23 | tr '\r' '\n')
# echo -n "currently in $smodestatus - "
if $(echo "$smodestatus" | grep -q 'MSMCH STEREO') ; then # were in MCH Stereo
echo 'MSDOLBY DIGITAL' | nc $Address 23
echo "switching to Dolby"
else
if $(echo "$smodestatus" | grep -q 'MSDOLBY') ; then # were in Dolby
echo 'MSSTEREO' | nc $Address 23
echo "switching to Stereo"
else
echo 'MSMCH STEREO' | nc $Address 23
echo "switching to Mch Stereo"
fi
fi
else
echo "first argument needs to be either u, d or m for volume, or smode"
fi
I created /storage/.config/irexec.lircrc:
#
# Initial test configuration for systemwide irexec service.
#
# Note that the system-wide service is useful only in corner-cases.
# Most scenarios are better off with a session service as described in the
# Configuration Guide. However, note that both can also be combined.
#
# Also note that the system-wide service runs without a terminal. To
# check the output generated use something like
# 'journalctl -b0 /usr/bin/irexec'. This service just echoes some keys
# commonly available.
#
begin
prog = irexec
button = KEY_VOLUMEUP
config = /storage/.config/volume.sh u
end
begin
prog = irexec
button = KEY_VOLUMEDOWN
config = /storage/.config/volume.sh d
end
begin
prog = irexec
button = KEY_MUTE
config = /storage/.config/volume.sh m
end
begin
prog = irexec
button = KEY_RECORD
config = /storage/.config/volume.sh smode
end
begin
prog = irexec
button = KEY_EJECTCD
config = /storage/.config/volume.sh tog_dynvol
end
Then I can run irexec /storage/.config/irexec.lircrc and it runs my script to control the volume:
~/.config # irexec /storage/.config/irexec.lircrc
sending up volume
sending down volume
sending up volume
sending down volume
sending up volume
sending down volume
Now I just need to work out how to get that to run as a service every time the box starts.
Sorry, I misunderstood the question before.
Running the script from SSH does not change the TV input.
Is there a reason you don’t use CEC?
irexec is present in CE, but I’ve not used it so I can’t offer any advise.
CoreELEC:~ # irexec --help
Usage: irexec [options] [lircrc config_file]
-d --daemon Run in background
-D --loglevel=level 'error', 'info', 'notice',... or 0..10
-n --name=progname Use this program name for lircrc matching
-h --help Display usage summary
-v --version Display version
Any tips on how I can get irexec /storage/.config/irexec.lircrc to run as a service every time the box boots?
Not a service, but you could put it in your /storage/.config/autostart.sh (create it if not already present) to automatically run on boot
#!/bin/sh
(
irexec /storage/.config/irexec.lircrc
)&
1 Like
The reason is because CEC wasn’t present on my Ubuntu PC which is where I first started with kodi.
The whole reason I created the script in the first place was because the volume adjustment was super slow on the AVR, 0.5dB at a time. So I made this script to send 4 volume controls for every single press of the volume control. Then later I added some controls to also set the sound mode, etc from the MCE remote.
Using the telnet interface to the AVR I can also control a lot more functions on it than I could via CEC. The telnet interface works great.
Thanks so much!
It wasn’t working properly at first, after googling I think it helped adding a sleep in there for it to work properly.
Also I added a -d to get irexec to run in daemon mode, not sure if that helped or not.
/storage/.config/autostart.sh
#!/bin/sh
(
sleep 20
irexec -d /storage/.config/irexec.lircrc
)&
Also I did chmod u+x /storage/.config/autostart.sh, not sure if that was necessary or not though.