SmartThings Community

(Tutorial) PC on/off and Activity Monitor with SmartThings

project_power
project_misc

(Ron Talley) #1

How about:

Turn on Kitchen PC
Turn off Bedroom PC
Mouse is Active
Turn on Kodi

Even Works with Alexa or Hey Google!!

This Tutorial will not only show you how to make your PC a totally controllable Switch in ST, but also use a Virtual Switches to be used as a Motion device or to Execute Programs which all can be used for Home Automation! After setup, You PC status will be in perfect sync with the Virtual Switch no matter if you turn on/off the PC manually or through SmartThings.

It might seem like a lot but you can have this up and running fairly quickly especially if you are already familiar with installing custom apps. It’s up to you how far you want to go down the rabbit hole!

Tools used: Send Events to Event Ghost (App), Host Pinger (App), EventGhost (Free Windows Program), CoRE or webCoRE (App) and Alexa Cloud Interface App (App) (Links are provided in Tutorial)

Steps 1-5 is all you need for on/off operation. (Shouldn’t take more than a couple of hours to get it up and running)

Steps 6-9 will take a little more time and if you are not computer savvy then steps 6-9 may be a little confusing. However, I will be here to answer any questions.

Every step is not fully “detailed”. You may have to leave this page to get a couple of things installed and figured out on your own before you can proceed to the next step. I have provided more detailed Screen Shots and Examples below in Post #2 in case you get stucked.

As far as I know, no other easy way to do this so if you find an easier way, be sure to drop a note.

Ok, here we go!

Warning! For complete integration, an always on PC or Linux Box to run the Host Pinger Sever is needed. However, you can still turn on or off your PC without Host Pinger. Host Pinger is only used to keep the Virtual Switch(s) in Sync and again, is highly recommended.

A Raspberry PI 3 is perfect for this task!

At the end, you will be able to easily monitor if PCs are on/off, turn them on/off (manually or via ST and the switch stays in sync), monitor if there has been activity on the PC, create macros for things (Virtual Switches) like, Alexa, open up Google Chrome or, Alexa, start Kodi, or Alexa, turn off Bedroom PC! Coupled with CoRE or webCoRE, I have complete control over my PC and you will too!

Second Warning! This tutorial is PC driven (Sorry Mac Users) and relies heavily on EventGhost (Free) which is a super easy PC tool. It will serve as the means to turn Off your PC. (Can also put it to sleep or hibernate.) Basic beginner info about Event Ghost can be found here:

http://www.eventghost.net/mediawiki/index.php/Main_Page

** Quick Setup for on/off PC control via SmartThings:** See Post #2 for detail instructions with Screenshots

  1. Install Event Ghost on the PC you want to control. Event Ghost is one of the main ingredients and it is super easy to learn. I used this initially to just turn “off” my PC from SmartThings but there is so much more you can do with it!

  2. If you do not know how to install custom code, then please see this FAQ:
    FAQ: An Overview of Using Custom Code in SmartThings

Install the custom app "Send Events to Event Ghost in the IDE.

  1. Create a Virtual Switch (VS) to turn “off” PC using Send Events to EventGhost App. (You could also create the VS with Host Pinger) In the Send Events to EventGhost App, make sure this switch is selected so it will show up on the EventGhost activity screen.
    FAQ: Creating a virtual Device

  2. Using the same VS, Use CoRE or webCoRE and the Wake on Lan (WOL) feature to turn “'on” PC (just point to mac address)

  3. Install Host Pinger to sync on/off status of Computer with VS. (CoRE rule example listed below) Basically Host Pinger will dictate the status of the switch. If the Ping is Live, the switch will be On, If the Ping is dead, the switch will turn off.
    [Release] Host Pinger (IP based Online State / Presence)

(More Advance setup below)

Quick Setup for using Event Ghost to monitor PC Activity: See Post #2 for detail instructions with Screenshots
6) Learn how to use Event Ghost to send “PC Events” to SmartThings. (However, we don’t need all of this just the Python Script and you need to create the index.html webpage)


Here are better instructions

  1. Create a Virtual Smart Switch that will be used to update computer mouse activity.

  2. Install Cloud Interface Smart App from Ask Alexa Setup to get the “End Points” of the VS. (So Cool!)
    http://thingsthataresmart.wiki/index.php?title=Alexa_Helper#Cloud_Interface_Smart_App_Setup

  3. Finally configure a Macro and Python Script in Event Ghost to send SmartThings the PC Activity Status

import urllib; urllib.urlopen(‘http://some smartthings address’)

This is better explained with the screen shots in Post #2 below with the label Step 9-Setup with Screen Shots for Mouse Activity in Event Ghost:.

  1. Like this Post and spread the word or come back to this post and update me if there is a better solution!

I hope this helps someone. Let me know if you need further information on my setup.

Thanks.


Computer Power with Wake On LAN
Super LAN Connect Beta!
Computer Power with Wake On LAN
[RELEASE CANDIDATE] CoRE (Community's own Rule Engine)
[WINDOWS TUTORIAL] PC On/Off (No Hardware Required)
Stereo with Z-wave, wifi or zigbee integration
Need help writing a WOL integration that gets triggered as a switch
IP Camera Inregration
[Release] Host Pinger (IP based Online State / Presence)
Using Mac as a Motion sensor? (Working on computer mode)
Smarthings hub - Windows 10 (Cortana) integration?
Control smartthings with computer?
Anyway to launch a routine from windows desktop?
[Release] Host Pinger (IP based Online State / Presence)
Bluetooth keyboard connection to PC
Is there a way to switch PC ON Wake On LAN using Smarthub?
Send Events to EventGhost
How to trigger Smartthings FROM PC not TO?
What do you have
(Ron Talley) #2

With Event Ghost, you can take an “Event” (Lightning Bolt), listed under the Log section on the left and click and drag it to an “Action” (we will be using macros), listed (installed) under the Configuration section.

Once you have Send Event to Event Ghost App installed and configured with a VS, you will see that Event sent from SmartThings on the left side, (HTTP.ST.Study PC.switch.off) then click and drag that to the right side macro, in my case, (Forced: Turn Off Computer)

Remember to save you Event Ghost file!

Setup Screens for PC Shutdown in Event Ghost:

In this Screen Shot, HTTP…switch.on is not doing anything in Event Ghost as this Action (Lightning Bolt) is not tied to any command (Macro) on the right side of the screen. However, ST will send both the on and off actions for any switch that you want the “Send Events Events to Event Ghost” App to monitor in EventGhost. Either the on or off Action can be tied to whatever command you like. For PC Shutdown, the HTTP…switch.off Action will be tied to the Shutdown Macro as you see on the right side of the Screen Shot.

I opened up Port 82 in my router configuration for my Study PC Local IP address (192.168.1.xxx). This is needed in order for EventGhost to receive Events from the ST Cloud. Then I configured the Send Events to Event Ghost App with the same information.

So when Study PC switch changes to “Off”, Event Ghost will receive the command and execute the Forced: Turn Off Computer.

The “On” command for the VS is done via CoRE with this Piston:

The problem is, if you turn off/on the computer manually then your VS looses sync. That is fixed with Host Pinger.
Hint (You can even create the VS in Host Pinger first)

Step 9-Setup with Screen Shots for Mouse Activity in Event Ghost:

Look at Screenshot showing the Python Scripts for Mouse Monitoring towards right bottom

Finally, to get the PC Activity Switch going, all you need is to find the End Points of your VS (Easily done with the Alexa Cloud Interface App) then put it in the Python Script listed above “import urllib; urllib.urlopen(‘http://some smartthings address’)” and apply it to the macro where mouse is idled or un-idled.

To be super clear, in Event Ghost, you will make a folder and call it PC Activity. In that folder, you will create a python macro: Configuration -> Add Folder -> Add Macro. Open the EventGhost tree and Select ‘Python Command’, then hit ‘OK’. Press ‘OK’ at this screen. This is where you will put the full Python Script including the End Point Address for idle or un-idle that matches with your VS on or off status.

Example 1. import urllib; urllib.urlopen(‘your End Point Address goes in between these two apostrophes’)

Example 2. import urllib; urllib.urlopen(‘http://graph.api.smartthings.com/api/smartapps/installations/numbersandletters/switches/numbersandletters/on?access_token=numbersandletters’)

Select your Virtual Switch (VS)

Here is where you get your VS End Points to put in the Python Script

That’s it!

Here is a Piston that I use to Auto Turn Off my PC if it is On and no one is on it or in the room.


[Release] Host Pinger (IP based Online State / Presence)
[WINDOWS TUTORIAL] PC On/Off (No Hardware Required)
Send Events to EventGhost
[Release] Host Pinger (IP based Online State / Presence)
(Ron Talley) #3

Troubleshooting:

WOL Windows 10 OS
Sometimes you have to turn on Wake on Lan in your Device Settings. Here is a quick Guide on how to do that.

WOL BIOS Settings
Sometimes you need to turn on Wake on Lan in your BIOS. Here is a quick Guide on how to do that.
https://www.manageengine.com/products/oputils/help/network/wake_on_lan_tool.html


#4

Awesome, thanks for sharing! I’m going to try implementing this in my system this weekend.


(Ron Talley) #5

This has really given my home automation a boost and a break on my utility bill. Enjoy.


(Ron Talley) #6

Did you get it going?


(Ron Talley) #7

Another Bump for This. Looks like a lot but it’s really simple and kicks arse.

Alexa, Turn on Kitchen PC
Alexa, Turn off Bedroom PC

If
Den PC is on
And
Den Motion is inactive
Then
Using Den PC
Wait 1 Hour
Turn Off


(Ron Talley) #8

Updated Tutorial


(Ahmed ElSerafy) #9

can this be done without the “always on” pc?


(Ron Talley) #10

This is needed for Host Pinger. It doesn’t technically need to be “always on” in order for it to work but it will not work if Host Pinger is not running the service that monitors your Local Area Network (LAN). This service can run on a PC, Mac or Linux based machine.

I use a Pi 3. It’s a really cheap Linux based PC. You can buy a kit that has everything you need (outside of a Micro SD) to get it up and running for about $50. Literally Plug and Play. I had a Power Supply and a 32 gig Micro SD so it was even cheaper for me. You just download a file and copy it to the SD and it just works. Magic!

Good to have one for other cool stuff as well!


(Ahmed ElSerafy) #11

Thanks a lot for your response…

well, i don’t have currently a pc to be always on, is there any workaround for that?

I saw a code/script for core that it would call a web url to trigger the wol command, can i do that without the always on pc?

ultimately, i want google home to trigger that, can you please suggest?


(Jason) #12

@rontalley Is the WOL supposed to turn on a computer that is off or a computer that is in sleep or hibernate mode? Also, have you had any issues with EG and multiple switches? If I use more than one switch EG is mixing up the commands. If I use the computer off switch it shows computer reboot switch in the activity feed. Sometimes I will hit off and it will show on, etc…


(Ron Talley) #13

If all you want to do is turn a PC on, then all you need is the WOL command sent. The always on part is for Host Pinger to keep the status of the Switch in sync.

CoRE has the WOL command built into it. No need for anything other than CoRE. The example is posted above.


(Ron Talley) #14

WOL will Turn a PC on from Off, Sleep or Hibernation depending on your specific motherboard. If you are using the NIC that is on the motherboard, the settings are in the BIOS. If you are using an add-on card, you have to go to the settings of that card and make sure Magic Packet is enabled.

Another trick is to use a Smart Plug and set your computer to turn on after Power Loss.

I have not been successful with WOL over Wi-Fi.

I have been successful with multiple switches. I have had up to 6 switches (Virtual) for my HTPC. Never had an issue.

Post your Pistons and/or screenshot of your E.G. Screen that is causing the issue.


(Jason) #15

Ok, so the WOL is not working for me, has something to do with windows 10, but I have few things to try in the bios when I get home.

Have you tried the smart plug setup that you mentioned? I read that if the computer is shut down normally then turn on after power loss will not work. They say it has to actually have power loss.


(Ron Talley) #16

How is your PC hooked up to your network? If it is WiFi then you will have to try a different approach as I have not been successful waking a computer up over WiFi even when my NIC supported it. If it is Hardwired, then believe me, it can be woke from a Magic Packet which CoRE can send. You just need to enable it. I updated the guide in post 3 for references on how to enable WOL from Windows 10 and from BIOS.

I have 7 PCs connected to ST

3 Hardwired-WOL works whether or not I turn off manually or use EV to either suspend or shutdown

Study-Hardwired to Switch-W10
Den-Hardwired to Switch-W8
Kitchen-Hardwired to Switch-W10

4 Wireless USB WiFi adapters-WOL does not work. I use an Iris Smart Plug for these. In BIOS, I set it to turn on after Power Loss.
TPC-Wireless WiFi USB adapter-W10
Boy’s Room-PCI WiFi adapter-W10
Daughter-Wireless WiFi USB adapter-W7
Master-PCI WiFi adapter-W7


(Jason) #17

I got everything to work except for the wol. I did however get the boot on power failure to work and used a smart plug on it and it turns on perfectly. So I am using EG ghost to turn it off and a smart plug to turn it on. I am still having the issue with EG giving reading from the wrong switch. I will see if I can figure out what is going on. I did notice that you are using different instances of EG, I was using one instance with 2 switches and that is what is not working.

Have you tried using 2 switches on 1 EG instance, going to the same machine?


(Jason) #18

I have 2 VS connected to EG, if I click computer off it shows computer restart on, if I click computer restart off it shows computer on. So it is totally mixing up the switch names and associated commands. I have no idea how to fix this issue other than getting rid of the computer restart and just use the computer on and off. The IDE is showing the correct commands being sent but EG is causing the issue.


(Ron Talley) #19

Aww…This is what Host Pinger is for. Let Host Pinger dictate the status of the Switch. In Host Pinger, associate the switch with the status. Don’t get confused as to what is actually going on. The (offline) will turn the switch on and visa-versa. Please post your rule that you are using.

As far as restart, You should create a virtual button for that as it would be a momentary switch just like on the actual PC. However, I don’t use restart. Just Off/On.

Other switches that I might have (on the same EG computer) would be like: WMC, KODI, NetFlix, WMP, Etc…EG can run any .exe and you can also chain events and macros.

One thing to note, I only check the switches in Send Events to Event Ghost settings that I am actually going to use.


(Jason) #20

Yeah, for some reason EG is mixing everything up, and I did have it as a momentary and a switch tried everything. No big deal I will just go with the off, same as restart just will take a little longer. I can always use WebCoRE to say if computer goes off wait 30 seconds and toggle the smart plug so everything would be just like a restart. Will have to think about that one, because I don’t want it to restart every time after 30 seconds.

Thanks for all your help with this. Even though I did not get everything to work as you have it the end result is I can now turn the computer on and off from smartthings and I could not do that before so it is a 100% win on my side!!!