Reply To: start / stop kodi based on HDMI monitor status

Max2Play Home 2016 (en) Forums Max2Play on Raspberry PI start / stop kodi based on HDMI monitor status Reply To: start / stop kodi based on HDMI monitor status

12. Februar 2016 at 11:14 #18468

Hi noop and asplundj,

thanks for sharing your scripts!

If you like to add this feature to Max2Play you could contribute to the Github project of Max2Play.

There is one thing, that could be improved to use the capabilities of the Max2Play-Framework: Max2Play automatically runs the script „/opt/max2play/“ as cronjob every minute. This script looks for autostart parameters and can be used to run your script too (instead of doing the loop every 10 sec and permanently running the script).

In your scenario it would be easy to add a checkbox on the Kodi page of the max2play web interface that sets a parameter (e.g. AUTOSTART_STOP_KODI_BY_HDMI_STATUS) in /opt/max2play/autostart.conf to make the script run optional and to activate / deactivate it with the web interface.

To add a checkbox to the kodi page you should have a look at this 2 pages:

view file to add checkbox in HTML:

Autostart/Stop Kodi by HDMI Status: <input type="checkbox" <?php if($sp->view->AUTOSTART_STOP_KODI_BY_HDMI_STATUS) echo "checked"; ?> value="1" name="AUTOSTART_STOP_KODI_BY_HDMI_STATUS" />

controller file to set parameter AUTOSTART_STOP_KODI_BY_HDMI_STATUS in /opt/max2play/autostart.conf

there is an easy function for setting a Parameter in a file (add this to the existing „save“ action in Xbmc.php):

if($_GET['action'] == 'save'){							
    $this->selectAutostart(isset($_GET['autostart']) ? 1 : 0);
    // Set selected Status
    $this->saveConfigFileParameter('/opt/max2play/autostart.conf', 'AUTOSTART_STOP_KODI_BY_HDMI_STATUS', isset($_REQUEST['AUTOSTART_STOP_KODI_BY_HDMI_STATUS']);

// Get Status for Checkbox in view file (add this at the End of the function __construct)
$this->view->AUTOSTART_STOP_KODI_BY_HDMI_STATUS = $this->getConfigFileParameter('/opt/max2play/autostart.conf', 'AUTOSTART_STOP_KODI_BY_HDMI_STATUS');

The parameter for the autostart can be checked in the script „/opt/max2play/“ and run your script if set to 1.

# Add this to /opt/max2play/ 
AUTOSTART_STOP_KODI_BY_HDMI_STATUS=$(cat /opt/max2play/autostart.conf | grep AUTOSTART_STOP_KODI_BY_HDMI_STATUS=1 | wc -l)
     /opt/max2play/ &