here is a little how to
https://discourse.osmc.tv/t/howto-for-auto-quit-start-kodi-based-on-tv-status/