LOGIN  |  REGISTER
Smart Living Made Brilliant!
CASTLEOS FORUM

HomeScripting

A forum for information about scripting with CastleOS. Get samples, suggestions, and other help here

Conditional script to check IP address ping Messages in this topic - RSS

Phil Hawthorne
Phil Hawthorne
Posts: 400


3/16/2016
Phil Hawthorne
Phil Hawthorne
Posts: 400
In my bedroom we have a smart TV. If we're watching TV and we don't move, the lights will turn off.

I've made a simple conditional script, that will ping an IP address on the network, and if it is up, the lights won't be turned off. This means while our smart TV is on, CastleOS won't turn off the lights in the bedroom when there's no motion detected.

I'm sure there are other uses for this, so you can grab a copy of the script here: https://gist.github.com/philhawthorne/42223ab86798055e37dd
+1 link
videobear
videobear
Posts: 57


3/16/2016
videobear
videobear
Posts: 57
That's clever!
0 link
Chris Stack
Chris Stack
Posts: 167


3/18/2016
Chris Stack
Chris Stack
Posts: 167
Thanks, I am going to try and use this to tell CastleOS who is home by pinging our phones over wifi. Then I can have conditions based on home or away
edited by cstack1009 on 3/18/2016
0 link
Phil Hawthorne
Phil Hawthorne
Posts: 400


3/18/2016
Phil Hawthorne
Phil Hawthorne
Posts: 400
Chris Stack wrote:
Thanks, I am going to try and use this to tell CastleOS who is home by pinging our phones over wifi. Then I can have conditions based on home or away
edited by cstack1009 on 3/18/2016


Just be careful with that one. Some phones (iPhone) won't always connect to the Wifi. To conserve battery, they will switch off Wifi here and there, or may just refuse to respond to the Ping.
0 link
Chris Stack
Chris Stack
Posts: 167


3/18/2016
Chris Stack
Chris Stack
Posts: 167
Phil Hawthorne wrote:


Just be careful with that one. Some phones (iPhone) won't always connect to the Wifi. To conserve battery, they will switch off Wifi here and there, or may just refuse to respond to the Ping.


Thanks, ill be sure to test that one. we have our phones set to switch to wifi automatically at home, to conserve data usage, so I dont think it will be a problem, but I will test it
0 link
Phil Hawthorne
Phil Hawthorne
Posts: 400


3/18/2016
Phil Hawthorne
Phil Hawthorne
Posts: 400
If you do find it to be an issue, a possible workaround might be this:

1. Create a Virtual device for every phone you want to check
2. Create an event to run once a day (say 10am, when you know no one should be home) to turn all the virtual devices "off"
3. Create your script to check the phone Ping. When the phones respond to the ping, turn the virtual device "on"

Then, in your events/scenes you can use that virtual device as a condition. If its on, the device is home. If its off, the device is not home.

The only downside is once the phone is registered as home, if it leaves before/after 10am, it won't be shown as away.
0 link
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3390


3/18/2016
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3390
That's a good idea, take it one step further and have the event recur every X minutes so it's always checking... or have the script go into a loop so it's always checking...
0 link
Phil Hawthorne
Phil Hawthorne
Posts: 400


3/18/2016
Phil Hawthorne
Phil Hawthorne
Posts: 400
Chris Cicchitelli wrote:
That's a good idea, take it one step further and have the event recur every X minutes so it's always checking... or have the script go into a loop so it's always checking...


That's what I was thinking. But you can't do that for the away/off status. As soon as the device stops responding to the Ping, the virtual device will get turned off and marked as away.
0 link
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3390


3/18/2016
Chris Cicchitelli
Chris Cicchitelli
Administrator
Posts: 3390
If the script is still running every few seconds/minutes and repinging, it will reupdate the status to on when it's detected again (assuming the device replies of course).
0 link
Chris Stack
Chris Stack
Posts: 167


3/19/2016
Chris Stack
Chris Stack
Posts: 167
Chris Cicchitelli wrote:
That's a good idea, take it one step further and have the event recur every X minutes so it's always checking... or have the script go into a loop so it's always checking...


Thts actually what I was planning on doing. I will update with how well it works
0 link