Page 1 of 1
[FIXED] Windows Shutdown switch and LUA script help needed
Posted: Saturday 19 November 2016 13:38
by HansieNL
Hello,
I'm trying to write a script to check if a computer is online and update the switch to the right state.
I can switch off and then a script send the shutdown command.
What I've done:
commandArray = {}
ping_success=os.execute('ping -c3 192.168.1.11')
if ping_success then
print("Desktop PC is online")
commandArray['Desktop PC']='On'
elseif
ping_success=false and (otherdevices['Desktop PC'] ~= 'Off') then
print("Desktop PC is offline")
commandArray['OpenURL']='
http://192.168.2.14:8080/json.htm?type= ... 3&nvalue=0'
elseif
ping_success=false and (otherdevices['Desktop PC'] ~= 'Off') then
print("Desktop PC is offline")
end
return commandArray
What code do I have to use for
ping_success=false if ping_success is not successful?
Thanks a lot
Regards.
Re: Windows Shutdown switch and LUA script help needed
Posted: Saturday 19 November 2016 14:15
by G3rard
You can just use else in stead of elseif.
See this example from the
Wiki
Code: Select all
commandArray = {}
ping_success=os.execute('ping -c1 192.168.1.156')
if ping_success then
print("ping success")
commandArray['Ping']='On'
else
print("ping fail")
commandArray['Ping']='Off'
end
return commandArray
Re: Windows Shutdown switch and LUA script help needed
Posted: Saturday 19 November 2016 14:44
by HansieNL
Thanks,
I used the example, but that does set the switch to off and then the shutdown script runs automaticly.
I don't want that the shutdown script runs automaticly, but only when I push the switch myself.
Then only the switch status has to be changed.
What command do I have to use to set the ping_success to false?
Thanks again
Re: Windows Shutdown switch and LUA script help needed
Posted: Saturday 19 November 2016 14:57
by G3rard
Then I suggest you don't do anything in the else part of the script (that is actually the ping_success false part).
Then the switch stays on, so you can turn it off by yourself.
Re: Windows Shutdown switch and LUA script help needed
Posted: Saturday 19 November 2016 17:32
by HansieNL
Thanks again,
I think I got it...
I changed my script to:
commandArray = {}
ping_success=os.execute('ping -c3 192.168.1.11')
if ping_success then
print("Desktop PC is online")
commandArray['Desktop PC']='On'
else
if
(otherdevices['Desktop PC'] ~= 'Off') then
print("Desktop PC is offline")
commandArray['UpdateDevice']='232|0|0'
else
print("Desktop PC is offline")
end
end
return commandArray
Now it does what I want. Updating the switch without activating the shutdown script and I can still use the switch to shutdown.
Re: [FIXED] Windows Shutdown switch and LUA script help needed
Posted: Friday 07 July 2017 16:52
by AlwinHummels
Hello HansieNL and others,
I'' try to understand this topic but still doesn''t know what and how it works
I hope someone can/will help me to create a switch that shows the status of my windows PC and when I press the switch shutdown the windows PC.
I tried the script and placed it in my Scripts/lua folder on my Pi.
I created a dummy switch I called "Desktop PC" and replaced de correct IDX in the script.
on the off action I used "script://home/pi/domoticz/scripts/shutdown_PC.sh" but still no luck my windows PC is still on and doesn't go shutdown.
my shutdown_PC.sh looks as follow:
Code: Select all
#!/bin/sh
#Shutdown Computer
# IP of computer and admin user needed
net rpc -S 192.168.1.XX -U USER%PASS shutdown -t 10 -f
were I changed the XX and the USER%PASS by correct values.