I have a key that I have programmed successfully in the past to turn on my AVR using cec-client. When I pass the command over ssh it turns the avr on. I ran "python .kodi/avr.py" and that too also turns on the avr.
However when I pass the python script via the key, it doesn't turn on. 
Here is my python script located at /storage/.kodi/avr.py
	
	
		import os
os.system('echo "on 4" | cec-client -s -d 1')
	
	 
Here is keymap:
	
	
		<keymap>
    <global>
        <keyboard>
            <key id="196">System.Exec(/storage/.kodi/avr.py)</key>
        </keyboard>
    </global>
</keymap>
	
	 
Here is the debug log:
	
	
		07:53:06.385 T:4017087344   DEBUG: LIRC: - NEW 8e 0 KEY_SLEEP devinput (KEY_SLEEP)
07:53:06.386 T:4094271408   DEBUG: HandleKey: rewind (0xc4) pressed, action is System.Exec(/storage/.kodi/avr.py)
07:53:06.647 T:4072665968    INFO: CAESinkALSA - Unable to open device "default" for playback
07:53:06.688 T:4072665968    INFO: CAESinkALSA - Unable to open device "hdmi:CARD=AMLM8AUDIO,DEV=0" for playback
07:53:06.692 T:4072665968   DEBUG: PulseAudio: Context authorizing
07:53:06.694 T:4072665968   DEBUG: PulseAudio: Context setting name
07:53:06.694 T:4072665968   DEBUG: PulseAudio: Context ready
07:53:06.695 T:4072665968 WARNING: Pulseaudio module module-allow-passthrough not loaded - opening PT devices might fail
07:53:06.697 T:4072665968  NOTICE: Found 1 Lists of Devices
07:53:06.697 T:4072665968  NOTICE: Enumerated PULSE devices:
07:53:06.697 T:4072665968  NOTICE:     Device 1
07:53:06.697 T:4072665968  NOTICE:         m_deviceName      : Default
07:53:06.697 T:4072665968  NOTICE:         m_displayName     : Default
07:53:06.697 T:4072665968  NOTICE:         m_displayNameExtra: Bluetooth Audio (PULSEAUDIO)
07:53:06.697 T:4072665968  NOTICE:         m_deviceType      : AE_DEVTYPE_PCM
07:53:06.698 T:4072665968  NOTICE:         m_channels        : FL, FR
07:53:06.698 T:4072665968  NOTICE:         m_sampleRates     : 5512,8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,176400,192000,384000
07:53:06.698 T:4072665968  NOTICE:         m_dataFormats     : AE_FMT_U8,AE_FMT_S16NE,AE_FMT_S24NE3,AE_FMT_S24NE4,AE_FMT_S32NE,AE_FMT_FLOAT
07:53:06.698 T:4072665968  NOTICE:         m_streamTypes     : No passthrough capabilities
07:53:06.700 T:4064273264    INFO: CActiveAESink::OpenSink - initialize sink
07:53:06.701 T:4064273264   DEBUG: CActiveAESink::OpenSink - trying to open device ALSA:default
07:53:06.701 T:4064273264    INFO: CAESinkALSA::Initialize - Attempting to open device "default"
07:53:06.713 T:4064273264    INFO: CAESinkALSA - Unable to open device "default" for playback
07:53:06.713 T:4064273264   ERROR: CAESinkALSA::Initialize - failed to initialize device "default"
07:53:06.714 T:4064273264   DEBUG: CActiveAESink::OpenSink - trying to open device PULSE:Default
07:53:06.719 T:4064273264   DEBUG: PulseAudio: Context authorizing
07:53:06.721 T:4064273264   DEBUG: PulseAudio: Context setting name
07:53:06.722 T:4064273264   DEBUG: PulseAudio: Context ready
07:53:06.727 T:4064273264   DEBUG: PulseAudio: Stream ready
07:53:06.727 T:4064273264  NOTICE: PulseAudio: Opened device Default in pcm mode with Buffersize 300 ms
07:53:06.730 T:4064273264   DEBUG: CActiveAESink::OpenSink - PULSE Initialized:
07:53:06.730 T:4064273264   DEBUG:   Output Device : Default
07:53:06.730 T:4064273264   DEBUG:   Sample Rate   : 44100
07:53:06.730 T:4064273264   DEBUG:   Sample Format : AE_FMT_FLOAT
07:53:06.731 T:4064273264   DEBUG:   Channel Count : 2
07:53:06.731 T:4064273264   DEBUG:   Channel Layout: FL, FR
07:53:06.731 T:4064273264   DEBUG:   Frames        : 4410
07:53:06.731 T:4064273264   DEBUG:   Frame Size    : 8
07:53:06.742 T:4072665968   DEBUG: CActiveAE::ClearDiscardedBuffers - buffer pool deleted
07:53:06.747 T:3461284720   DEBUG: Previous line repeats 1 times.
07:53:06.747 T:3461284720   DEBUG: Sink changed
07:53:11.477 T:4094271408   ERROR: ActiveAE::Resume - failed to init
07:53:11.478 T:4094271408   FATAL: OnApplicationMessage: Failed to restart AudioEngine after return from external player
	
			Display More