In my house I have multiple media players (nVidia Shield). On all these players I use Kodi to watch video. I’ve created a central MariaDB for Kodi on my Synology NAS. This whole setup is working fine, the only annoying thing is that I manually have to update the library to add the newly downloaded content to my library.
Is there a way to use the Kodi integration in Home Assistant to update the MariaDB on my Synology NAS? I’ve been trying to create a automation, but this doesn’t work unfortunately:
alias: KODI - Update Kodi Library
description:
triggers:
- trigger: state
entity_id:
- media_player.nvidia_shield_woonkamer
to: "on"
from: "off"
conditions:
- condition: state
entity_id: input_boolean.kill_switch
state: "off"
actions:
- action: kodi.call_method
data:
method: VideoLibrary.Scan
target:
device_id: 423f5d8800cfe7315412ad1a3f830237
mode: single
You shouldn’t have to. All Kodi clients should update the DB automatically (watched status/playback position) and Kodi csn be set up to update the DB when it notices new files in the storage location(s).
It’s ages since I set this up using a shared DB in the HA MariaDB add-on and I’m not at home at the moment to check it out but I think I use this Kodi add-on to keep the library synced when new media is added or deleted: https://kodi.wiki/view/Add-on:Library_Watchdog
Having said that, if the kodi addon does not work for you I have these two scripts called by dashboard buttons that I have not used since moving to a shared DB:
There are identical scripts for my Cinema Kodi box, only the media player id changes. Also I have no idea why I have it set to navigate to the home screen first. I wrote that a long time ago.
Thank you for your reaction! I will test this Watchdog add-on and will let you know if this solution is sufficient. That way I don’t need HA at all for this job
You are absolutely right, the WatchDog addon does what I want; auto update the (central) database when I start Kodi. Many thanks! One question though; Could it maybe be possible to update the MariaDB of Kodi frequently with a trigger from Home Assistant? This way it could be even better, the database can be updated before I start Kodi.
I have adjusted the automation to trigger when I turn the TV on:
alias: KODI - Update Kodi Library
description:
triggers:
- trigger: state
entity_id:
- media_player.tv_woonkamer
to: "on"
from: "off"
conditions:
- condition: state
entity_id: input_boolean.kill_switch
state: "off"
actions:
- action: kodi.call_method
data:
method: VideoLibrary.Scan
target:
entity_id: media_player.shield_woonkamer_kodi
mode: single
What I see is that the automation is triggered but my video library is not updated. Do you maybe have an idea way this update isn’t working? When I use the WatchDog addon in Kodi, the library is successfully updated.
Does anybody know if a video library scan can be limited to certain - not all - sources only? The API documentation does not specify that as far as I can tell, but that does not mean it is not possible…?
My mediaplayer is turned on when the tv is turned on. I’ve tracked the tv device in HA and the mediaplayer is fist online and after that the TV integration indicates that it is on. So far so good. But at that moment, the mediaplayer is on, but Kodi isn’t running. Should that be a problem?
Log from automation trace:
Triggered by the state of media_player.tv_woonkamer at January 13, 2025 at 19:51:04
Test If Kill Switch is Off
Perform action 'Kodi: Call method' on Shield Woonkamer Kodi
Finished at January 13, 2025 at 19:51:04 (runtime: 0.00 seconds)
In the log I’ve found this error:
Logger: homeassistant.components.kodi.media_player
Source: components/kodi/media_player.py:787
integration: Kodi (documentation, issues)
First occurred: January 11, 2025 at 16:09:36 (16 occurrences)
Last logged: 10:43:01
TransportError trying to run API method media_player.shield_woonkamer_kodi.VideoLibrary.Scan({})