[FIXED] Windows Shutdown switch and LUA script help needed Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

[FIXED] Windows Shutdown switch and LUA script help needed

Post 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.
Last edited by HansieNL on Saturday 19 November 2016 17:36, edited 1 time in total.
Blah blah blah
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Windows Shutdown switch and LUA script help needed

Post 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
Not using Domoticz anymore
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Windows Shutdown switch and LUA script help needed

Post 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
Blah blah blah
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Windows Shutdown switch and LUA script help needed

Post 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.
Not using Domoticz anymore
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Windows Shutdown switch and LUA script help needed

Post 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.
Blah blah blah
User avatar
AlwinHummels
Posts: 7
Joined: Sunday 22 November 2015 20:25
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Dordrecht, The Netherlands
Contact:

Re: [FIXED] Windows Shutdown switch and LUA script help needed

Post by AlwinHummels »

Hello HansieNL and others,

I'' try to understand this topic but still doesn''t know what and how it works :oops:
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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest