Check if Computer On/Off

Is there a way to check if my windows 10 media computer is on or off. i would like to create a polling function to see if the computer is on or off and report back status.

parsing a reply to an ICMP command would normally be the way to do it, but I don’t know if that’s possible with THR. There is a way to send magic packets to WOL, but that’s not what you want.

What I’d probably do is write a simple python script that opens up a socket, you could use THR to get the status that way (if it responds with the expected ‘ack’ whatever that may be, it’s on. Otherwise, it’s off.

Even easier (but more overhead)…install a HTTP server and just serve up a page. Depending on your capabilities, you could report on the status of individual services too. There might be already a 3rd party tool that allows web monitoring of windows services…might be worth googling,

I used a ping sensor on my Vera Hub that tied into HR. It would ping once a minute and if ping was successful PC was on, and a ping failure triggered an off condition.

Thank you for the suggestion. I created a simple python server scrip that send back and ack when pinged.

I created a plugin. everything works when the computer is on. However if the computer is off I do not get a status. It seems like the HRP gets stuck since it is not receving anything. Can you please take a look at my code. i am attaching the code and HRP file.

plugin.Name = “Ping”;
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval =10000;

var socket = new TCPClient();

function onChangeRequest() {
}

function onConnect() {
var port=9999;
var host = “192.168.1.60”
socket.connect(host, parseInt(port));
}

function onDisconnect() {
socket.close();
}

function onPoll() {
computerStatus();
}

function onSynchronizeDevices() {
var device = new Device();
device.Id = plugin.Name;
device.DisplayName = “Ping”
device.Icon = “Computer”;
device.Capabilities = [“Switch”];
device.Attributes = [ “Signal”];
plugin.Devices[plugin.Name] = device;

}

function computerStatus() {

var device = plugin.Devices[plugin.name];
socket.send(“Hello”);
sleep(250);

if(device) {
var response = “”;
var Signal = “”;

    var response = socket.receive();
    switch(response) {

        case "ACK!":   //Sending Signal
            powerState = "Computer On";
            break;
        case null:  //Not Sending Signal
	      case "":
            powerState = "Computr Off";
            break;
        default:
        //this case should never happen
            powerState = "Error";
            break;
    }

    device["Signal"] = powerState;
}

}
Ping.hrp (9.2 KB)

1 Like

Nice work…I took some liberties to bring it across the finish line.

“On” will be registered with a response (any response) from the server. “Off” will be registered if a connection cannot be established at all.

There might be some redundant code, but it works :slight_smile:

Ping-revised.hrp (9.2 KB)

Still can’t get the status of “Computer Off”. Works beautifully when the computer is On.

Odd…works for me.

I used the Hercules Setup Utility [1] to simulate a TCP server. When the util was started and sent a response back, Computer OK would appear. As soon as I shutdown the server, Computer Off was returned.

I can record and share a video if necessary.

[1] Hercules SETUP utility | HW-group.com

I just ran the HRP file you posted. Did not change a thing, not even ip or port. Ideally the status would be computer off since you are trying to connect to a random port. However the status is blank

Don’t know what to say. Runs perfectly in the designer for me.

I noticed in the script above, powerstate is “computr off”. Is that a typo (no e)? Are you expecting “computer off”?

It must be a user error on my part. I am pretty new to this stuff. I was able to fix everything using Multidatatrigger. Thank you again for your support. And More importantly thank you for the JVC plugin, it is amazing.

1 Like

My pleasure. I find this to be a fun diversion from life :).

1 Like