Execute shell script when page is loading

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
mestereaga
Posts: 4
Joined: Friday 07 June 2019 8:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Execute shell script when page is loading

Post 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.
mestereaga
Posts: 4
Joined: Friday 07 June 2019 8:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Execute shell script when page is loading

Post 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!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Execute shell script when page is loading

Post by waaren »

Thx. I learned something new today !
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
mestereaga
Posts: 4
Joined: Friday 07 June 2019 8:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Execute shell script when page is loading

Post by mestereaga »

You welcome! Also I'm looking to extend this functionality to page refreshing too..
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest