I’m trying to map a key to toggle the TV power. I firstly created an xml file in ~/.kodi/userdata/keymaps
, confirming that it works.
<keymap><global><keyboard>
<key id="61952">pagedown</key>
</keyboard></global></keymap>
And after rebooting, this key indeed does send a pagedown signal. I created this script to toggle power on the TV. This script works perfectly from the command line.
However, when I try to call the script from the keymap file with System.Exec(/usr/local/bin/toggle-tv-power auto)
, it fails. I turned on debug, and can see it getting triggered in ~/.kodi/temp/kodi.log
, but nothing happens. I get some cryptic output that may or may not be related:
2021-02-27 10:58:32.534 T:1915720624 DEBUG: Keyboard: scancode: 0xf0, sym: 0x0000, unicode: 0x0000, modifier: 0x0
2021-02-27 10:58:32.534 T:1915720624 DEBUG: GetActionCode: Trying Hardy keycode for 0xf200
2021-02-27 10:58:32.534 T:1915720624 DEBUG: Previous line repeats 1 times.
2021-02-27 10:58:32.534 T:1915720624 DEBUG: HandleKey: 0 (0xf200, obc-61697) pressed, action is System.Exec(/usr/local/bin/toggle-tv-power auto)
2021-02-27 10:58:32.534 T:1915720624 DEBUG: Keyboard: scancode: 0xf0, sym: 0x0000, unicode: 0x0000, modifier: 0x0
2021-02-27 10:58:32.717 T:1875894496 DEBUG: CAESinkPi:Drain delay:99ms now:0ms
2021-02-27 10:58:32.717 T:1875894496 DEBUG: CAESinkPi:Deinitialize
2021-02-27 10:58:32.718 T:1875894496 DEBUG: CAESinkPi:SetAudioProps hdmi_stream_channels 0 hdmi_channel_map 00000000
2021-02-27 10:58:32.722 T:1875894496 DEBUG: COMXCoreComponent::Deinitialize : OMX.broadcom.audio_render handle 0x6e902e70
2021-02-27 10:58:32.734 T:1884287200 INFO: CAESinkALSA::EnumerateDevice - device default description
2021-02-27 10:58:32.738 T:1884287200 INFO: CAESinkALSA::EnumerateDevice - device @ description
2021-02-27 10:58:32.740 T:1884287200 INFO: CAESinkALSA - Unable to open device "surround71" for playback
2021-02-27 10:58:32.743 T:1884287200 INFO: CAESinkALSA - Unable to open device "surround51" for playback
2021-02-27 10:58:32.744 T:1884287200 INFO: CAESinkALSA - Unable to open device "surround71" for playback
2021-02-27 10:58:32.746 T:1884287200 INFO: CAESinkALSA - Unable to open device "surround40" for playback
2021-02-27 10:58:32.747 T:1884287200 INFO: CAESinkALSA - Unable to open device "surround51" for playback
2021-02-27 10:58:32.747 T:1884287200 INFO: CAESinkALSA - Unable to open device "surround71" for playback
2021-02-27 10:58:32.794 T:1884287200 INFO: CAESinkALSA::EnumerateDevice - device sysdefault:CARD=ALSA description bcm2835 ALSA, bcm2835 ALSA
Default Audio Device
2021-02-27 10:58:32.798 T:1884287200 NOTICE: Found 2 Lists of Devices
2021-02-27 10:58:32.798 T:1884287200 NOTICE: Enumerated ALSA devices:
2021-02-27 10:58:32.799 T:1884287200 NOTICE: Device 1
2021-02-27 10:58:32.799 T:1884287200 NOTICE: m_deviceName : @
2021-02-27 10:58:32.799 T:1884287200 NOTICE: m_displayName : Default (bcm2835 ALSA bcm2835 ALSA)
2021-02-27 10:58:32.799 T:1884287200 NOTICE: m_displayNameExtra:
2021-02-27 10:58:32.799 T:1884287200 NOTICE: m_deviceType : AE_DEVTYPE_PCM
2021-02-27 10:58:32.800 T:1884287200 NOTICE: m_channels : FL, FR
2021-02-27 10:58:32.800 T:1884287200 NOTICE: m_sampleRates : 8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,176400,192000
2021-02-27 10:58:32.800 T:1884287200 NOTICE: m_dataFormats : AE_FMT_S16NE,AE_FMT_S16LE,AE_FMT_U8
2021-02-27 10:58:32.800 T:1884287200 NOTICE: m_streamTypes : No passthrough capabilities
2021-02-27 10:58:32.801 T:1884287200 NOTICE: Device 2
2021-02-27 10:58:32.802 T:1884287200 NOTICE: m_deviceName : sysdefault:CARD=ALSA
2021-02-27 10:58:32.802 T:1884287200 NOTICE: m_displayName : bcm2835 ALSA
2021-02-27 10:58:32.802 T:1884287200 NOTICE: m_displayNameExtra: bcm2835 ALSA
2021-02-27 10:58:32.802 T:1884287200 NOTICE: m_deviceType : AE_DEVTYPE_PCM
2021-02-27 10:58:32.802 T:1884287200 NOTICE: m_channels : FL, FR
2021-02-27 10:58:32.802 T:1884287200 NOTICE: m_sampleRates : 8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,176400,192000
2021-02-27 10:58:32.802 T:1884287200 NOTICE: m_dataFormats : AE_FMT_S16NE,AE_FMT_S16LE,AE_FMT_U8
2021-02-27 10:58:32.802 T:1884287200 NOTICE: m_streamTypes : No passthrough capabilities
2021-02-27 10:58:32.802 T:1884287200 NOTICE: Enumerated PI devices:
2021-02-27 10:58:32.802 T:1884287200 NOTICE: Device 1
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_deviceName : HDMI
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_displayName : HDMI
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_displayNameExtra:
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_deviceType : AE_DEVTYPE_HDMI
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_channels : FL, FR
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_sampleRates : 8000,11025,16000,22050,24000,32000,44100,48000,88200,96000,176400,192000
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_dataFormats : AE_FMT_FLOAT,AE_FMT_S32NE,AE_FMT_S16NE,AE_FMT_S32LE,AE_FMT_S16LE,AE_FMT_FLOATP,AE_FMT_S32NEP,AE_FMT_S16NEP,AE_FMT_RAW
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_streamTypes : STREAM_TYPE_AC3,STREAM_TYPE_EAC3,STREAM_TYPE_DTSHD_CORE,STREAM_TYPE_DTS_2048,STREAM_TYPE_DTS_1024,STREAM_TYPE_DTS_512
2021-02-27 10:58:32.803 T:1884287200 NOTICE: Device 2
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_deviceName : Analogue
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_displayName : Analogue
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_displayNameExtra:
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_deviceType : AE_DEVTYPE_PCM
2021-02-27 10:58:32.803 T:1884287200 NOTICE: m_channels : FL, FR
2021-02-27 10:58:32.804 T:1884287200 NOTICE: m_sampleRates : 48000
2021-02-27 10:58:32.804 T:1884287200 NOTICE: m_dataFormats : AE_FMT_FLOAT,AE_FMT_S32LE,AE_FMT_S16LE,AE_FMT_FLOATP,AE_FMT_S32NEP,AE_FMT_S16NEP
2021-02-27 10:58:32.804 T:1884287200 NOTICE: m_streamTypes : No passthrough capabilities
2021-02-27 10:58:32.804 T:1884287200 NOTICE: Device 3
2021-02-27 10:58:32.804 T:1884287200 NOTICE: m_deviceName : Both
2021-02-27 10:58:32.805 T:1884287200 NOTICE: m_displayName : HDMI and Analogue
2021-02-27 10:58:32.805 T:1884287200 NOTICE: m_displayNameExtra:
2021-02-27 10:58:32.805 T:1884287200 NOTICE: m_deviceType : AE_DEVTYPE_PCM
2021-02-27 10:58:32.805 T:1884287200 NOTICE: m_channels : FL, FR
2021-02-27 10:58:32.805 T:1884287200 NOTICE: m_sampleRates : 48000
2021-02-27 10:58:32.805 T:1884287200 NOTICE: m_dataFormats : AE_FMT_FLOAT,AE_FMT_S32LE,AE_FMT_S16LE,AE_FMT_FLOATP,AE_FMT_S32NEP,AE_FMT_S16NEP
2021-02-27 10:58:32.806 T:1884287200 NOTICE: m_streamTypes : No passthrough capabilities
2021-02-27 10:58:32.808 T:1875894496 INFO: CActiveAESink::OpenSink - initialize sink
2021-02-27 10:58:32.809 T:1875894496 DEBUG: CActiveAESink::OpenSink - trying to open device PI:HDMI
2021-02-27 10:58:32.810 T:1875894496 DEBUG: CAESinkPi:Initialize Format:15 Channels:2 Samplerate:44100 framesize:8 bufsize:17640 bytes/s=352800.00 dest=PI:HDMI
2021-02-27 10:58:32.810 T:1875894496 DEBUG: CAESinkPi:SetAudioProps hdmi_stream_channels 0 hdmi_channel_map 00000008
2021-02-27 10:58:32.812 T:1875894496 DEBUG: COMXCoreComponent::Initialize OMX.broadcom.audio_render input port 100 output port 100 m_handle 0x6e94eae0
2021-02-27 10:58:32.815 T:1875894496 DEBUG: COMXCoreComponent::AllocInputBuffers component(OMX.broadcom.audio_render) - port(100), nBufferCountMin(1), nBufferCountActual(2), nBufferSize(17648), nBufferAlignment(16)
2021-02-27 10:58:32.816 T:1875894496 DEBUG: CActiveAESink::OpenSink - SinkPi Initialized:
2021-02-27 10:58:32.816 T:1875894496 DEBUG: Output Device : HDMI
2021-02-27 10:58:32.816 T:1875894496 DEBUG: Sample Rate : 44100
2021-02-27 10:58:32.816 T:1875894496 DEBUG: Sample Format : AE_FMT_FLOAT
2021-02-27 10:58:32.816 T:1875894496 DEBUG: Channel Count : 2
2021-02-27 10:58:32.816 T:1875894496 DEBUG: Channel Layout: FL, FR
2021-02-27 10:58:32.816 T:1875894496 DEBUG: Frames : 2205
2021-02-27 10:58:32.816 T:1875894496 DEBUG: Frame Size : 8
2021-02-27 10:58:32.821 T:1884287200 DEBUG: CActiveAE::ClearDiscardedBuffers - buffer pool deleted
2021-02-27 10:58:37.620 T:1915720624 ERROR: ActiveAE::Resume - failed to init
2021-02-27 10:58:37.621 T:1915720624 FATAL: OnApplicationMessage: Failed to restart AudioEngine after return from external player
2021-02-27 10:58:42.363 T:1763700960 DEBUG: Thread JobWorker 1763700960 terminating (autodelete)
2021-02-27 10:58:42.363 T:1536676064 DEBUG: Thread JobWorker 1536676064 terminating (autodelete)
2021-02-27 10:58:42.364 T:1755308256 DEBUG: Thread JobWorker 1755308256 terminating (autodelete)
2021-02-27 10:58:42.440 T:1787318496 DEBUG: Thread JobWorker 1787318496 terminating (autodelete)
I also created a python wrapper so I could instead call RunScript(/usr/local/bin/toggle-tv-power.py)
, but that also failed.
2021-02-27 11:11:16.216 T:1915646896 DEBUG: Keyboard: scancode: 0xf0, sym: 0x0000, unicode: 0x0000, modifier: 0x0
2021-02-27 11:11:16.216 T:1565516000 INFO: initializing python engine.
2021-02-27 11:11:16.217 T:1565516000 DEBUG: CPythonInvoker(13, /usr/local/bin/toggle-tv-power.py): start processing
2021-02-27 11:11:16.517 T:1565516000 DEBUG: -->Python Interpreter Initialized<--
2021-02-27 11:11:16.518 T:1565516000 DEBUG: CPythonInvoker(13, /usr/local/bin/toggle-tv-power.py): the source file to load is "/usr/local/bin/toggle-tv-power.py"
2021-02-27 11:11:16.518 T:1565516000 WARNING: CPythonInvoker(13): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.
2021-02-27 11:11:16.535 T:1565516000 DEBUG: CPythonInvoker(13, /usr/local/bin/toggle-tv-power.py): setting the Python path to /usr/local/bin:<redacted>
2021-02-27 11:11:16.535 T:1565516000 DEBUG: CPythonInvoker(13, /usr/local/bin/toggle-tv-power.py): entering source directory /usr/local/bin
2021-02-27 11:11:16.807 T:1565516000 INFO: CPythonInvoker(13, /usr/local/bin/toggle-tv-power.py): script successfully run
2021-02-27 11:11:16.807 T:1565516000 DEBUG: onExecutionDone(13, /usr/local/bin/toggle-tv-power.py)
2021-02-27 11:11:16.816 T:1565516000 INFO: Python interpreter stopped
2021-02-27 11:11:16.817 T:1565516000 DEBUG: Thread LanguageInvoker 1565516000 terminating
I also tried mapping CECToggleState
, but this failed too.
2021-02-27 11:32:40.206 T:1916404656 DEBUG: Keyboard: scancode: 0xf0, sym: 0x0000, unicode: 0x0000, modifier: 0x0
2021-02-27 11:32:40.206 T:1916404656 DEBUG: GetActionCode: Trying Hardy keycode for 0xf200
2021-02-27 11:32:40.207 T:1916404656 DEBUG: HandleKey: action CECToggleState [122], toggling state of playing device
2021-02-27 11:32:40.207 T:1916404656 DEBUG: Keyboard: scancode: 0xf0, sym: 0x0000, unicode: 0x0000, modifier: 0x0
How can I call this script from the keymap?
EDIT: I also tried assigning a test script date >> /tmp/test
to the same key, and this works fine.