If anyone wants to know how to trigger a Library rescan on a (remote) Kodi / XBMC machine, this is how I’ve done it:
Sending the curl / json command directly through a rule or from a binding was too difficult because of the escaping of the characters. So I created a script:
Then I created an item and bound it to the sitemap as a simple push-button: In .items
Switch i_Kodi_Rescan "Video Library" <office>
In .sitemap:
Switch item=i_Kodi_Rescan mappings=[ON="Rescan"]
Last thing is to create a rule to run the shell script when the button is pushed: In .rules
rule "Kodi Video Library Scan"
when
Item i_Kodi_Rescan received command
then
val result = executeCommandLine("\/home\/user\/kodi_rescan.sh", 5000)
logInfo("Kodi Library Scan", result)
end
Hi Martiniman,
Do you mean ‘customized’ button presses ? I searched also a lot for that, but haven’t found it yet. I found a add-on which uses mqtt to feedback status changes from Kodi to your mqtt broker, but it does not accept customized (with customized I mean ‘free’ shortcut keys that are not assigned to any Kodi command) button presses from Kodi.
See link: https://github.com/owagner/kodi2mqtt. If you just want feedback on certain Kodi commands, this could work for you.
Yes, i mean ‘customized’ button presses.
I want use my Harmony remote to control lights and other devices when i Kodi is running.
I can send any keypress to windows/kodi, and i need to Kodi somehow send that keypress to OH.
I have created the item created the script saved it in the right place this time and edited the rule
Rule
rule "Kodi Video Library Scan"
when
Item Kodi_Rescan received command
then
val result = executeCommandLine("/home/openhabian/kodi_rescan.sh", 5000)
logInfo("Kodi Library Scan", result)
end
@Sharpy At a guess, it looks like either the user that tries to run the script isn’t allowed to access it in the way it needs to. Check the rights on the file, is it executable for the user running it (owner/group, I would assume)?
Normally the script is executed by the user openhab. So this user needs to have permission to execute the script, if it needs sudo, you also need to update your sudoers config.
See the documentation of the exec binding in openhab Docs
This is a way to do it directly by rules (no scripts):
Item:
Switch Kodi_Rescan "Run Library scan"
Rule:
rule "Run kodi library scan"
when
Item Kodi_Rescan received command ON
then
var String content = '{"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "myOpenHAB"}'
var String url = 'http://username:password@192.168.xx.zz:8081/jsonrpc?request='
sendHttpPostRequest(url,'application/json',content)
createTimer(now.plusSeconds(1)) [| Kodi_Rescan.postUpdate(OFF) ]
end
If you define your switch with the autoupdate parameter then you don’t need the timer in your rule to switch the Kodi_Rescan switch back to the off position. The visual confirmation due to the switch being in the on position for one second may be a good reason to keep the current implementation though.