Launching script via remote when Kodi is stopped

Hello,
as there is a problematic standby functionality on Homatics/Dune boxes Running CoreELEC, I was thinking about a workaround for this feature to

  1. use short script that would check if kodi is up/down, then either stop/start it
  2. map execution of this script on specific key on Homatics BT remote

This should reduce CPU temperature when Kodi is up and not being used (e.g. during nights), but should keep CorELEC up und running for whatever purposes (TV Headend server, socks proxy or other services that you want keep running).

  1. This is simple standby.sh script that solves 1st step:
#!/bin/sh
run=$(ps -ef | grep -v grep | grep kodi.bin | wc -l)
if [[ $run == "0" ]]; then
systemctl start kodi
else
systemctl stop kodi
fi
  1. I could catch BT code for the power off button on B25 remote:
Testing ... (interrupt to exit)
Event: time 1700334739.583423, type 4 (EV_MSC), code 4 (MSC_SCAN), value c0030

Then I mapped it to f7 function in homatics.hwdb:
KEYBOARD_KEY_c0030=f7 #standby

and added this function into gen.xml into global section of BT remote controller

<keymap>
        <global>
                <keyboard>
                        <f7>System.Exec(/storage/.config/standby.sh)</f7>
                </keyboard>
        </global>

Now I can stop kodi using power off button on Homatics remote, that will shut down kodi and TV via hdmi-cec.
And here comes the problem and my question. Since Kodi is down, I am not able to start it anymore by pressing BT remote as it no longer catches any signal from its BT remote. I can of course run the script manually, but that’s not intention.
Is there a way how to launch standby.sh/any script using the remote controller different way than I originally intended?

I hate BT and dont’t know the proper answer but a workaround could be to use evtest program which captures button presses. Piping to some shell commands could maybe work.

Righ, this is good start. unfortunately my scripting skills are close to zero, so I might need bit of help. I’d like to focus on starting of kodi when it’s already stopped.
Let’s assume that my remote controller has handler10 when checking /proc/bus/input/devices and key I want to capture has code of c0030 (this is by the wat power off button on B25 Homatics remote).

Then I’d like to use something like this:

#!/bin/sh -x
evtest /dev/input/event10 > /storage/.config/evtest-capture.xml
capture=$(grep c0030 /storage/.config/evtest-capture.xml | wc -l)
if [ $capture -ge 1]; then
systemctl start kodi
else
echo "waiting"
fi

Meanwhile I press c0030 key and if I check evtest-capture.xml it has the lines inside, so it has captured correct key, but does’t run the condition (systemctl start kodi)
If I debug the script with -x it waits on
+ evtest /dev/input/event10

As mentioned, I don’t use scripting, so now I would need a little help here.

Try something like [How-To] capture keyboard/mouse/buttons/IR events and execute actions - Community Builds, Projects & Packages - OpenWrt Forum

But looks like daemon called triggerhappy could be winner: GitHub - wertarbyte/triggerhappy: A lightweight hotkey daemon

I can compile it for you if you want.

yeah, I pretty much like how the keystroke is captured using evtest on the first link vpeter provided. I used that in 2 simple scripts, both are working fine. I can either stop kodi and then start it back based on the captured BT event, however as already mentioned, my scripting skills are bad, so once I merge those two scripts, I am getting error:
./standby.sh: line 13: syntax error: unexpected end of file

So I missing some basic syntax in if condition. Can anybody please kick me what is wrong below?

#!/bin/sh -x
up=$(ps -ef | grep -v grep | grep kodi.bin | wc -l)
device='/dev/input/event10'
match='*type 4 (EV_MSC), code 4 (MSC_SCAN), value c0030'
if [ $up == "1" ]; then
    systemctl stop kodi
else
    evtest "$device" | while read line; do
    case $line in
        ($match) systemctl start kodi;;
esac
done

I guess either “;” or maybe the structure of if condition is wrong?

Here’s the debug:

++ ps -ef
++ grep -v grep
++ grep kodi.bin
++ wc -l
+ up=1
+ device=/dev/input/event10
+ match='*type 4 (EV_MSC), code 4 (MSC_SCAN), value c0030'
./standby.sh: line 13: syntax error: unexpected end of file

you are missing fi at the end.

1 Like

Does stop Kodi really reduce CPU usage. When it’s idle I think there is no load.
So you just can use fblank to make screen black like here just write a 1:

Thanks vpeter for helping out. at least I am learning some basic bash conditions.

Portisch> well, in general, I am quite missing standby feature on Homatics/Dune box in CE (I know it can be achieved by remounting usb FS to internal storage, but I am bit hesitant to do this).
I got used to it in osmc that I had on my previous box. you are right, I really don’t know if stopping Kodi helps or not, but since I made this solution working now, I can check cpu temperature after couple hours of kodi being stopped. if I turn TV and check temperature while kodi is up, but “idle”, it is slightly above 50C, so wondering if that helps. It may help on some older devices…

For those who would be interested on how to achive kodi stop/start using BT remote (not IrDA), first use this script:

#!/bin/sh
up=$(ps -ef | grep -v grep | grep kodi.bin | wc -l)
device='/dev/input/event10'
match='*type 4 (EV_MSC), code 4 (MSC_SCAN), value c0030'
if [ $up == "1" ]; then
    systemctl stop kodi
else
    evtest "$device" | while read line; do
    case $line in
        ($match) systemctl start kodi;;
esac
done
fi

you need to map it to specific key. I used power on/off button on B25 remote. this button is already assigned in Kodi, so I remapped it via homatics.hwdb:

KEYBOARD_KEY_c0030=f7 #standby

You need to save changes to the database:

#udevadm hwdb --update
#udevadm trigger -s input
#reboot

Then assign this function to your gen.xml. Snippet of mine looks like this:

<keymap>
        <global>
                <keyboard>
                        <key id="61526">contextmenu</key>
                        <key id="c0030">System.Exec(/storage/.config/standby.sh)</key>
                        <f5>activatewindow(10000)</f5>
                        <f6>System.Exec(/storage/.config/mutehdmi.sh)</f6>
                        <one mod="longpress">Skin.ToggleDebug</one>
                </keyboard>
        </global>

Then add the script from beginning of this post into autostart.sh

sleep 5
nohup /storage/.config/standby.sh &

Reboot box and it should work.

What I noticed is that keeping Kodi on main window does makes less cpu usage of it.

Most probably there won’t be any major difference when using default CE skin, but I can imagine other, more fancy and eye catching skins that use CPU more heavily, so stopping Kodi can save something.

There’s also one more benefit. As CE can’t be suspended on Homatics boxes, I personally keep the box running, I set up hdmi-cec not to suspend the box when turning off TV and using TV remote controller for turning on/off TV. My TV controller is big and heavy so I really prefer Homatics remote. You can now turn on/off TV with box’s remote as systemctl sends hdmi-cec signals to switch tv on/off.

at least for me, this is something I will be using.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.