I have several windows PCs in my house that run Kodi. I wanted to connect them to SmartThings for a range of purposes. There are various things that can be done depending on the functionality you want.
Firstly I wanted to be able to put my PCs to sleep and wake them up again via a button in SmartThings. I have achieved this, although the process is quite a long one to set up. I’ll detail it below.
Next I wanted to be able to control Kodi remotely via smartthings. This is reasonably straight-forward to set up, again I detail how below
Lastly, I wanted to get the status of a PC in SmartThings. This is so that when a PC goes to sleep I can use a routine in smartthings to turn off a power adapter with the home cinema amplifiers plugged in. I originally looked at doing this with an energy saving “smart” socket, but most of these have been discontinued and the reviews of them are mixed at best. Using SmartThings seemed a more reliable way to achieve the same thing, with the added benefit that I can override the behaviour at any time from the convenient of my phone.
PART A: Controlling sleep of a PC
I followed the (not in depth) article on the SmartThings forum written by rontalley. This took a bit of time to figure out as many of the things required I hadn’t used before, but it wasn’t as tricky as I’d expect. I’ll give a more detailed version below.
Note — you will need the target PC to have a fixed local IP address (usually in the format 192.168.x.x) and you will also need to know the MAC address of the network connection it uses. If you don’t know how to find these then you’re not really the kind of user this guide is aimed at — you do need a bit of technical knowledge to do this kind of tinkering with SmartThings.
1. Configure the PC with WOL
- Hold the windows key and R to open the run menu
- Type in devmgmt.msc and press enter
- Expand ‘network adapters’
- Double click on the network adapter yo use to connect to your network — this will need to be either a wired ethernet connection or a wireless card built in (not a USB WiFi card). In my case this was “Realtek PCIe GB Ethernet Connection” on 1 PC and “Intel Ethernet Connection” on another
- Click on the “Power Management” tab
- Make sure all 3 boxes are ticked, then click OK and close device manager
2. Install Event Ghost on the PC you want to control
- Download EventGhost
- Install EventGhost on the PC you want to control. The default settings are all ok to use. At the end of setup run EventGhost
- Create a new file (the white file button at the top left) and then use “File, Save As” to save it somewhere convenient (probably in My documents)
- Right Click on “AutoStart” and select “Add Plugin”
- Scroll to the bottom of the list and select “WebServer” and click OK
- Change the Event Prefix to ST. Do not create a username or password
- I changed the port as I already had something running on Port 80. You can change the port or leave it, but if you change it make a note of what you changed it to.
- Click OK, and then when the Windows Firewall prompt appears, click Allow.
- Click Cancel to reject the offer to add the “Configuration Tree” actions
- Right click on “AutoStart” again, this time select “Create Macro”
- Expand “system” and then “power management”
- Select “Stand By” (or “Hibernate Computer” if that is what you prefer your PC to do)
- Click OK, and Click OK again on the next prompt (without choosing force close all programs)
- Now resave the file. We’re nearly (but not quite) finished with it
- Go to File, Options
- Tick the first 2 options (run on startup and minimise to tray) and click OK
- Leave EventGhost for now and go on to the next stage.
3. Install the Custom SmartThings Smart App “Send Events to EventGhost” in the SmartThings IDE
- Login to the SmartThings IDE USA or EU & UK
- Click on “My SmartApps”
- Click on the green button “+ New SmartApp”
- Click on “From Code”
- Open a new browser tab and go to the GitHub code for Send-Events-to-EventGhost
- Click on the “Raw” button to view the raw code
- Copy and paste the code into the SmartApp creation form on the other tab you still have open
- Click “Create”
- Then Click “Save”, and finally “Publish”.
4. Create a virtual switch in SmartThings IDE
- Still in the SmartThings IDE (from the previous step) click on “My Devices”
- Click the Green “+ New Device”
- Give your device a sensible name and label — I used the same for each — using the name and location for the PC I wanted to control
- Change the type to “Virtual Switch”
- Give your device a unique network name — I used the format “vs-###” where ### was the computer name
- Select your Home location for Location and select your SmartThings Hub (most of us only have 1) that you want to control the switch from for the Hub
- Make sure version is set to published
- Leave group and zigbee ID blank
- Click “Create”
5. Set the switch to send the “off” signal to event ghost via the Smart App
- Open the SmartThings app on your mobile device
- Go to Automation and click on “+ Add a SmartApp”
- Scroll down to “My Apps” at the bottom of the list
- Select “Send Events to EventGhost”
- Enter the IP address of the PC you wanted to control (it should have a fixed IP)
- Change the port from 80 if you changed the port in the EventGhost webserver creation earlier, otherwise leave it at 80
- Click on the “Switches” option and select the name of the virtual switch you created and then press “Done”
- Click “Save” and you should see “Successfully added…” shown in green
- Switch back to “My Home” in the SmartThings app and toggle the switch that you created on and off
- Go back to the PC you wish to control and look at the “log” on the left hand side of “EventGhost”. You should see a couple of entries that show your switch toggle activity in SmartThings — mine were listed as “ST.ST.CompName.switch.off []” and “ST.ST.CompName.switch.on []”
- We want to put the PC to sleep when we toggle the switch to off, so we need the entry “ST.ST.CompName.switch.off []”
- Drag and drop the “ST.ST.CompName.switch.off []” from the log onto the “Stand By” entry in the main panel
- Save the EventGhost file again
- Now try the button in SmartThings on your mobile device. When you toggle the switch to “off” the PC should go to sleep! You’ve completed the first part of the operation. The rest will be easy from here.
6. Setup webCoRE for your SmartThings
- I have based this on the official guide which is well worth looking at if you have any problems
- You will need a GitHub account (free) so if you don’t already have one then head over to GitHub and create one, it only takes a few seconds
- Als (like me) you are in the EU or UK then yo uneed to activate GitHub integration for your SmartThings IDE.
Go to this link and follow the instructions to link your GitHub account to SmartThings - Once you are done (or if it’s already set up) log into the SmartThings IDE USA or EU & UK
- Click on “My SmartApps”
- Click on “Settings” and then click on “Add new repository” in the window that appears
- Use the following details for the repository: Owner= ady624; Name= webCoRE; Branch= master
- Click “save”
- Next click the button “Update from Repo” and select “webCoRE (master)”
- Tick ONLY the “webCoRE” option (not the other 3 options), and tick the “publish” button and click “Execute Update”
- Click on “Update from Repo” again, and select “webCoRE (master)” again
- Tick the remaining 3, tick “publish” again, and click “Execute Update” again
- Click on the “edit properties” button (the right of the 2 buttons) next to the webCoRE smart app in the list
- Scroll down and click on “OAuth” to expand the OAuth options
- Click on “Enable OAuth in Smart App” and then click “Update”
- Now go to the SmartThings app on your mobile device
- Click on “MarketPlace” at the bottom and then select “Smart Apps” at the top
- Scroll down to “My Apps” and select “webCoRE” (not the dashboard, storage or piston)
- Follow the setup wizard, including choosing a password
- Give webCoRE access to the virtual switch you created earlier when you get to the devices to control choices.
You can also select any other devices you might want to control web webCoRE - Now click on the “Automation” tab in the SmartThings App
- Scroll down until you find webCoRE and click on “Dashboard”
- Enter the password you created in the webCoRE setup
- To make webCoRE easier to use we are going to access it via the browser on your PC…
- In the automation tab click on webCoRE again, but this time select “Register a browser”
- On your PC open dashboard.webcore.co and enter the code shown on your SmartThings App
- Now you have webCoRE set up we can use it to send a WOL signal
7. Create a webCoRE piston to send a WOL signal when the switch it toggled to “on”
- In the webCoRE Dashboard, at the left hand side, click on “+ New Piston”
- Select “Create a blank piston”
- Set your Author Name, and give the piston a sensible name (e.g. WOL) and click “Create”
- In the code view window click on “+ add a new statement”
- Click on “Add an if” and select “Add a Condition”
- Change “what to compare” to “physical device” and then change “nothing selected” to the name of the virtual switch you created earlier. Change the final box to “switch”
- Leave the next box set to “any interaction”
- Set the box “what kind of comparison” to “changes to” and set the value to “on”
- Click the “add” button. You will see a little bit of code has been added.
- Next, click on the section of code that says “then” and click on “Add an action”
- Leave the “devices” box set to “location” and click “add a task”
- in the “Do” list, scroll down and select the “Wake a LAN device” option
- In the “value” field enter the MAC address of the PC you want to control. Use the format xx:xx:xx:xx:xx:xx:xx:xx
- Click the “Add” button
- Now click the “Save” button at the top right of the webCoRE Dashboard to save your code
- You should now be able to use the switch in your SmartThings app to wake your PC from sleep mode as well as putting it to sleep. We finally have the basic functionality we wanted! Try putting the PC to sleep and waking it up with the switch. Wait 20+ seconds between each operation to give the PC chance to respond or the button can get out of sync with the real state of the PC. We’ll do some more work next to keep the button always in sync with the status of the PC.
8. Install HostPinger on an always-on PC
- To keep the switch always in sync with the real condition of the PC we ‘ping’ the PC from another device which needs to be always on. I have a server which I have used for this purpose, but you could use a Raspberry Pi. This guide will focus on using a Windows PC, but you can use the guide by the STHostPinger app author to do this with other devices.
- Download STHostPinger.exe from GitHub (EXE V2.zip) and extract it to a convenient location on the “always on” PC
- Modify the config.config file that comes with STHostPinger.exe to include the IP address of the PC that your virtual switch controls
- Change the check interval if you wish — I changed mine to 10 seconds from the default of 30
- Keep the config file open as we need 3 more settings for it once we have set up the smartapp
- Login to the SmartThings IDE USA or EU & UK and click on “My SmartApps”
- Click on “Settings” and then click on “Add new repository” in the window that appears
- Use the following details for the repository: Owner= jebbett; Name= STHostPinger; Branch= master
- Click “save”
- Next click the button “Update from Repo” and select “STHostPinger (master)”
- Tick the only option, and tick the “publish” button and click “Execute Update”
- Click on the “edit properties” button (the right of the 2 buttons) next to the STHostPinger smart app in the list
- Scroll down and click on “OAuth” to expand the OAuth options
- Click on “Enable OAuth in Smart App” and then click “Update”
- Now click on “My Device Handlers”
- Next click the button “Update from Repo” and select “STHostPinger (master)”
- Tick the only option, and tick the “publish” button and click “Execute Update”
- Go to the SmartThings app on your mobile device
- Click on Automation at the bottom right, and then scroll down and select “Add a SmartApp”
- Scroll down and choose “My Apps”
- Choose HostPinger, enter the name of the PC you want to monitor, the IP address of the PC you want to monitor,
change the “Turn this device on/off with status” and select the virtual switch you created earlier. For the delay I’ve found I needed to change the default to 30 seconds to avoid rebooted PCs going straight to sleep. Once set click “Save” - Open the HostPinger smartapp from the automation menu, scroll down and turn on debug logging and click Save to close the smartapp
- Switch back to the SmartThings IDE and select the “live logging” menu
- Reopen the HostPinger smartapp on your mobile device
- Switch back to the IDE and you should see that several events have appeared in the live log. These will include some information called “AppId”, “accessToken” and the IDE entity (US or EU). You need this information
- In the config.config file that you were editing earlier you need to enter the 3 bits of information from the live log. The IDE entity will look something like this: “https://graph-eu01-euwest1.api.smartthings.com”. The other 2 entries will be in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
- Copy these entries into your config.config file and save it. Now run the STHostPinger.exe and you should see a command prompt style window. It should display the status of the PC you want to monitor as either online or offline, and hopefully this will match what the PC is actually doing.
- Your virtual switch should now accurately show the status of your PC, no matter how it was switched on or off. You can test this by turning the PC and making sure it shows as “on” on the switch in the SmartThings App. Now go to the PC and turn it fully off (turn it off at the wall). Now, use the switch in the SmartThings App to turn the PC on. Of course the PC can’t turn on because it is off at the wall. The switch should say “turning on” for 10–15 seconds, and afterwards should go back to saying “off”. If this works the pinger service has turned the button back to off correctly.
PART B: Controlling Kodi
I tried a couple of different Smart Apps for SmartThings, but found one was easier to set up and did what I needed. Again, I followed a guide on the SmartThings forum, this time written by the author of the smartapp called “Kodi for SmartThings Beta”.
1. Install smart app and device handler in the SmartThings IDE
Use the same principles as for the first stage, add the custom smart app and device handler and then configure.
- Login to the SmartThings IDE USA or EU & UK and click on “My SmartApps”
- Click on “Settings” and then click on “Add new repository” in the window that appears
- Use the following details for the repository: Owner= iamcanadian2222; Name= ST-Kodi; Branch= master
- Click “save”
- Next click the button “Update from Repo” and select “ST-Kodi (master)”
- Tick the only option, and tick the “publish” button and click “Execute Update”
- Now click on “My Device Handlers”
- Next click the button “Update from Repo” and select “ST-Kodi (master)”
- Tick the only option, and tick the “publish” button and click “Execute Update”
2. Enable HTTP control of Kodi
- Load Kodi on your PC
- Open System settngs
- Navigate to the “Services” option
- In the UPnP tab, turn on “Allow remote control via UPnp”
- In the “Web server” tab, turn on “Allow remote control via HTTP”
3. Configure the smartapp via the SmartThings app
- Open the SmartThings App on your mobile device
- Click on SmartApps at the bottom right
- Scroll down to the bottom to “My Apps”
- Select “Kodi (formerly XBMC)”
- The automatic setup should find your Kodi box, when it has, select it and click done
- Click “Done” a second time to finish the setup
- A device will appear in “My Home”, it should show what the Kodi machine is doing. Click on it to get a set of media controls
PART C: Using SmartThings routines to turn off sockets when PC goes to sleep
Once the above 2 guides were complete it was very easy to create a SmartThings routine to monitor the status of the PC and turn off sockets when it is off, and turn on sockets when it is on.
1. Create SmartThings routine
- Open the SmartThings app on your mobile device
- Click on the “automation” tab at the bottom and then select the “Routines” tab at the top
- Click “Add a routine”
- Give your routine a name
- In the second screen, select the “turn off these lights or switches” and set the smartplug you want to turn off
- Next click on “Automatically perform…” and then select “Something turns on or off”
- In the next menu click on “Which?” and select the virtual switch you created for your PC. Change “On” to “Off”
for the “Turns” option, then click save, then click save again. You should now see your routine listed - Create a second routine to turn the smartplug back on when the virtual switch is turned on
Thanks for this. I found rontalley’s original article a few weeks ago, and also struggled with the level of detail that was or wasn’t provided. Your arrangement just works, and well arranged so I can see which things are doing which. I’ve now got my PC going to sleep when I’m not in my office, and waking back up as soon as I walk back in. With a Smart Plug as well, all the peripherals power down in sync!
Hi there, this article was really helpful for me. Thank you guys