Page 1 of 1

Execute shell script when page is loading

Posted: Saturday 08 June 2019 23:01
by mestereaga
Hi all,

I'm wondering if is possible to run a script when a specific page is loading in Domoticz, for example I have a server which is running Domoticz and a custom page, so when any user hit the page, then I want to execute a shell script to do something (in my case I want to send some data to a client using netcat).

Thanks.

Re: Execute shell script when page is loading

Posted: Wednesday 12 June 2019 10:21
by mestereaga
I have just found a workaround:
1. Go and create a simple switch and add the shell script for On action (or Off action as you wish).
2. Create a custom page in www/templates/ and give it a name like mypage.html
3. Add the following code into mypage.html:

Code: Select all

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script type="text/javascript">
        window.onload = SwitchLight(10,'On',RefreshFavorites,false);
        </script>
    </head>
    <body>

    </body>
</html>
Tips:
  • this is working when you switch from another page to this, just keep refreshing the page doesn't work
  • change the SwitchLight parameters to meet your configuration, the first parameters must be the device ID (in this case the dummy switch), and the second is the switch's event on which the script is executed: in our case this is On, but it could be Off as well
Hopes this will be useful for you!

Re: Execute shell script when page is loading

Posted: Wednesday 12 June 2019 11:55
by waaren
Thx. I learned something new today !

Re: Execute shell script when page is loading

Posted: Friday 14 June 2019 14:36
by mestereaga
You welcome! Also I'm looking to extend this functionality to page refreshing too..