Hi, i’m new here and i would like to give my experience.
I created two scripts to start-stop kodi, each of them based on TV status. If TV is on, then kodi starts, if TV is off then Kodi stops itself.
First script is for people with a TV compatible with /sys/class/amhdmitx/amhdmitx0/hpd_state.
Second script is for those with a TV not compatible.
With my LG TV, if i give cat /sys/class/amhdmitx/amhdmitx0/hpd_state in SSH, result is 0 (tv off) or 1 (tv on).
Based on this, i made this script:
#!/bin/bash
oldcmd=“”
while :
do
cmd=$(cat /sys/class/amhdmitx/amhdmitx0/hpd_state)
if [[ “$cmd” == “1” && “$cmd” != “$oldcmd” ]]
then
echo starting xbmc
$(sudo systemctl start mediacenter)
oldcmd=$cmd
elif [[ “$cmd” != “$oldcmd” ]] ; thenecho stopping xbmc $(sudo systemctl stop mediacenter) oldcmd=$cmd fi echo $cmd sleep 3
done
If you are lucky and hpd_state works as expected, Kodi start-stop based on tv status(on-off) with this script. All you have to do is disable mediacenter via ssh ( sudo stop disable mediacenter ) install crontab, and add a cron with this script.
Now the second script, for those unlucky which hdp_state results always in a “1”… like me. I’ve now a Samsung TV, latest model, cat /sys/class/amhdmitx/amhdmitx0/hpd_state results always as 1, so my script can’t work.
First of all we have to enable in cec adapter the option to CLOSE kodi on tv standby.
Second, disable mediacenter (as seen before), then my second script:
#!/bin/bash
while true
do
KODI_OFF=$(ps x |grep -v grep |grep -c “kodi.bin”)if [[ "$KODI_OFF" == "0" ]] then # Kodi is off echo Kodi is off CEC_OUT=$( echo pow 0 | cec-client -d 1 -s) if [[ $CEC_OUT == *"power status: on"* ]] then # TV is on echo TV is on # start Kodi sudo systemctl start mediacenter fi fi sleep 5
done
For this script to work i need some help. It works as expected only first time. The cause is that when Kodi exit (forced or with cec control), it restarts after 10 seconds, and the script cannot work anymore as expected.
So, is there a way to completely disable auto restart of Kodi when exit?
I hope this helped someone, and someone could help me.