I am just starting out in C# and I was wondering if there was an easy way to make this script work inside InControl by converting it to a CS file?
What it does is check if a phone is responding to pings, if it is, it marks the person as home and increases the temp in the house by activating a scene. Each it receives a response, it waits about 20 minutes before marking them away if it doesn't receive another response. It checks every minute or so.
I am open to any other ways of doing this, as long as it isn't manual and it doesn't require my wife to do anything. Motion sensors in every room of the house is also out (for now).
[code]
$ip = "192.168.1.xx"
$pw = "xxx"
$countTime = 20
#home scene name, away scene name, ip, 0, 0
$arrays = ("Home-1","Away-1","192.168.1.2","0","0"),("Home-2","Away-2","192.168.1.3","0","0"),("Home-3","Away-3","192.168.1.4","0","0"),("Home-4","Away-4","192.168.1.4","0","0")
do {
$date = get-date
foreach ($array in $arrays) {
if ($array[3] -eq 0) {
$array[3] = (get-date).AddYears(-1)
}
if (Test-Connection $array[2] -ea 0) {
if ($array[4] -eq 0) {
$array[3] = $date.addminutes(-20)
}
$array[4] = $countTime
$array[2] + " Ping"
} else {
if ($array[4] -eq 1) {
$array[3] = $date.addminutes(-20)
}
if ($array[4] -gt 0) {
$array[4] = $array[4] - 1
}
$array[2] +" Ping Failed " + $array[4]
}
if ($array[4] -eq $countTime) {
$array[2] + " is Home " + $array[4]
if ($date.AddMinutes(-10) -gt $array[3]) {
$sceneName = $array[0]
$hideMe = Invoke-RestMethod -Uri "http://$ip:1178/zwave/activateSceneGet?password=$pw&sceneName=$sceneName" -Method get<br> $array[2] + " activated"<br> $array[3] = $date<br> }<br> } elseif ($array[4] -eq 0) {<br> $array[2] + " is not Home " + $array[4]<br> if ($date.AddMinutes(-10) -gt $array[3]) {<br> $sceneName = $array[1]<br> $hideMe = Invoke-RestMethod -Uri "http://$ip
:1178/zwave/activateSceneGet?password=$pw&sceneName=$sceneName" -Method get
$array[2] + " deactivated"
$array[3] = $date
}
}
}
""
sleep 60
} while ($x -ne 1)
[/code]
PowerShell or C#?
- 291 Views
- Last Post 25 January 2015
lpschreck
posted this
25 January 2015