Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Turning off a pc using lua


Question

Guest sk8er000
Posted

Hello,

I've found in this forum how to turn on a pc using HC2 and is very useful!!

is there a way to turn off a device with lua?

I've found this scripts on the web:

Shudown on Windows:

Code: [select]

os.execute("shutdown %-s %-t 01")

Shutdown on Linux:

Code: [select]

os.execute("shutdown %-h now")

but os.execute is disabled on HC2

thanks in advance

15 answers to this question

Recommended Posts

  • 0
Posted

Hi sk8er000,

you can use SwitchOff ->

Please login or register to see this link.

and create lua script to use the SwitchOff embed web server :

Please login or register to see this link.

Please login or register to see this image.

/emoticons/default_icon_razz.gif" alt=":-P" />

  • 0
Guest dsilletti
  • Inquirer
  • Posted
    Hi sk8er000,

    you can use SwitchOff ->

    Please login or register to see this link.

    and create lua script to use the SwitchOff embed web server :

    Please login or register to see this link.

    Please login or register to see this image.

    /emoticons/default_icon_razz.gif" alt=":-P" />

    Cool!

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" />

    • 0
    Posted

    Something like this ...

    Please login or register to see this code.

    Best regards.

    • 0
    Guest sk8er000
  • Inquirer
  • Posted

    thank you very much Krikroff!

    I'll try it as soon as i come back home..do you know something similar for osx or linux?

    • 0
    Posted

    Krikroff

    i have done something like this. Is that correct?

    Please login or register to see this code.

    the SwitchOff software is installed. web server running port is 8000, basic authentication set to User password. Its still not working. what is wrong?

    Just in case the firewall is turned of.

    • 0
    Posted
    Krikroff

    i have done something like this. Is that correct?

    Please login or register to see this code.

    the SwitchOff software is installed. web server running port is 8000, basic authentication set to User password. Its still not working. what is wrong?

    Just in case the firewall is turned of.

    Hi, have you replace with your userid and password? Have you tried directly in a web browser?

    • 0
    Posted

    I have set the user to "User" and the password to "password".

    When i try to open the the browser from local computer

    Please login or register to see this link.

    i come to the switch of menu. When i use a remote computer and try

    Please login or register to see this link.

    i also see the menu. Portforwarding is open and firewall is turned off.

    I think i am doing something wrong with the code. Just to be sure. The code is lua option is checked in HC2 and also the "wait for anwser from remote computer is checked.

    Maybe it's the spelling? Can you show one more time the full lua code set on your hc2?

    • 0
    Guest captainigloo
  • Inquirer
  • Posted

    With MCE Controler, it's easy :

    Please login or register to see this link.

    In Virtual Devices :

    Button Off:

    Please login or register to see this code.

    Button On

    Please login or register to see this code.

    Ping Main loop & Status Icon

    Please login or register to see this code.

    • 0
    Posted
    thank you very much Krikroff!

    I'll try it as soon as i come back home..do you know something similar for osx or linux?

    On OSX i just have a file "shutdown.php" on my mac with this code:

    <?php

    echo "Shutdown mac";

    $results = shell_exec('sudo shutdown -h now');

    ?>

    and a restart.php:

    <?php

    echo "Rebooting mac";

    $results = shell_exec('sudo shutdown -r now');

    ?>

    but I remember I had to play with user permissions on apache to allow the sudo from this script. Can't remember how exactly...

    Please login or register to see this image.

    /emoticons/default_icon_curve.gif" alt=":-/" />

    ub

    • 0
    Posted
    httpSession =  Net.FHttp(Your_SwitchOff_MachineIP, SwitchOff_Webserver_Port);

    It works also fine with a computer name instead of IP adress.

    [ Added: 2014-02-28, 22:10 ]

    Hmmm, no. Sorry, it works in my imagination only.

    Please login or register to see this image.

    /emoticons/default_icon_curve.gif" alt=":-/" />

    It seems I forgot to save the script. So IP adress is needed anyway.

    • 0
    Posted
    Krikroff

    i have done something like this. Is that correct?

    Please login or register to see this code.

    the SwitchOff software is installed. web server running port is 8000, basic authentication set to User password. Its still not working. what is wrong?

    Just in case the firewall is turned of.

    Hi, have you replace with your userid and password? Have you tried directly in a web browser?

    It seems that I have the same problem...When I try in another browser the

    Please login or register to see this link.

    then my computer shut-down..but when try with LUA code nothing happens

    Please let me know if I done this correctly:

    Created virtual device and in the button code I put:

    --[[

    %% properties

    %% globals

    --]]

    httpSession = Net.FHttp(192.168.1.15, 8000);

    httpSession:setBasicAuthentication(User, pass);

    response = httpSession:GET("/?action=System.Shutdown");

    selected LUA code and then Saved

    Not working... What is wrong?

    It could be that the quotation marks are missing on IP or port?

    • 0
    Posted

    emariu, when you use that link from your smartphone PC is going down too?

    • 0
    Posted

    I give my own answer,this worked for me:

    httpSession = Net.FHttp("192.168.1.15", 8000);

    httpSession:setBasicAuthentication("User","pass");

    response = httpSession:GET("/?action=System.Shutdown");

    the quotation marks did the trick

    • 0
    Posted

    did anyone ever get this working? if so can you export your VD so I can have a look, I have tried everything and am still unsuccessful ...

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...