Hi, I hope this is the right place – I am struggling with a problem meanwhile since weeks and apparently cannot solve it without help:
Long story short: I have a setup with beamer using a Windows based Kodi 21, recent version. As there is no point in firing up the beamer, let the canvas screen down, etc when listening to music, the system is often used headless, without screen output or menu interaction. This is where IOS Remote comes into the picture.
For controlling the different devices or the whole environment, I have implemented an addon script.home that needs two arguments, the device and the command to be executed – the rest goes over many different ways, partly HTTP requests to services, partly COM Serial, or IR or even radio remotes. I have also a feature “scenes” which are kind of macros setting up several devices with one command. The whole thing works fine and I managed to integrate in different ways into my modified skin:
Addon.py (in shortened form):
from lib import automation
from lib import xbmchelper
ADDON = xbmcaddon.Addon()
CWD = ADDON.getAddonInfo('path') # for kodi 19 and up..
if (__name__ == '__main__'):
device = str(sys.argv[1])
command = str(sys.argv[2])
if device == 'this_or_that':
#do this or do that
pass
elif device == 'scene':
if command == 'listen':
automation.execute('audio', 'aux')
elif command == 'somethingelse'
#further "scenes" = environment macros
pass
else:
xbmcgui.Dialog().notification('script.home', 'Unknown ' + device + ' command ' + command)
else:
automation.execute(device, command)
# the end!
Calling from the skin works flawlessly, e.g. when music is played, the window MusicOSD.xml triggers switching on the amplifier and the speakers:
<onload>RunAddon(script.home,scene,listen)</onload>
<onload>Skin.SetBool(Audio_State,true)</onload>
Also calling from menu controls works fine:
<control type="radiobutton" id="11144">
<label>Stereoanlage</label>
<include>DefaultSettingButton</include>
<onclick>Skin.ToggleSetting(Audio_State)</onclick>
<selected>Skin.HasSetting(Audio_State)</selected>
<onclick condition="!Skin.HasSetting(Audio_State)">RunAddon(script.home,audio,aux)</onclick>
<onclick condition="Skin.HasSetting(Audio_State)">RunAddon(script.home,audio,power)</onclick>
</control>
Switching off the computer via the remote simply shuts down, so I cannot catch the OnUnload event of any skin window or similar and obviously it is senseless in a headless mode to fire up the beamer and let the canvas down, just to go to a menu and switch off the amp before shutting down. So I would like to call my addon in certain situations from the remote: as I have no access to custom menus or screens, the favourites appear to be the right place for this?
Now to my problem: whatever I try, I simply do not manage to call the addon from favourites via the IOS remote:
<favourite name="Stereoanlage" thumb="DefaultAudio.png">RunScript(script.home,scene,listen)</favourite>
or
<favourite name="Stereoanlage" thumb="DefaultAudio.png">RunScript("script.home","audio","power")</favourite>
results in Python exception:
2024-10-18 09:30:44.721 T:7812 error <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
Traceback (most recent call last):
File "C:\Users\Richard\AppData\Roaming\Kodi\addons\script.home\addon.py", line 17, in <module>
device = str(sys.argv[1])
IndexError: list index out of range
…which means the call is handed over to Kodi properly, the Addon is found and started, but no arguments are exposed and sys.argv remains empty. Without args the addon is useless, not knowing what to do.
I tried to work around by calling an extra py script that handles this without parameters:
toggle.audio.py (extra script in root of the addon):
from lib import automation
from lib import xbmchelper
if xbmchelper.getsetting('audio_state') == 'true':
automation.execute('audio','power')
else:
automation.execute('audio','aux')
and call this from favourites.xml:
<favourite name="Stereoanlage" thumb="DefaultAudio.png">RunScript("special://home/addons/script.home/toggle.audio.py")</favourite>
IOS Remote refuses with: “Execution of the action is not possible”, apparently cannot parse and the call does not reach Kodi at all?
All other workaround attempts failed as well, like calling a batch file via System.Exec, RunAddon instead of RunScript, with or without spaces, using single quotes, double quotes, no quotes, escaped quotes… also tried full path, C:\Users\… windows style, C:\\Users\\… python style, relative paths from special: or addon: protocols, etc, all in vain.
What would be the proper syntax to call a script addon via favourites in the remote? Or is this possibly some limitation of the remote with current Kodi releases?
Thank you in advance for any pointers or hints and greetings from Vienna, Austria.