SmartThings Host Pinger
Using an EXE or Python script running on any computer (Windows, Mac or Linux) - Ping any IP, host name or URL and pass this to a switch in SmartThings!
Code and Program Location:
Requirements
1. Application to Ping Hosts (running on any PC connected to the internet.)
>> Option A - STHostPinger.exe - Application (Windows or Mac&Linux via Mono) - config.config needs to be configured with details as described below and can be running on any PC connected to the internet.
>> Option B - PingerPy - Python Script - Cross platform script based on python, which also provides a web interface to configure the settings, you will need to download Python to use this.
>> Option C - Arduino / ESP8266 Device - Use a small piece of Arduino/ESP8266 compatible hardware such as the Wemos D1 Mini, which can be purchased for only a couple of ÂŁ/$ powered by USB.
>> Option D - Bash Script - For use in Unix shells, ideal for Raspberry Pi.
2. Host Pinger SmartApp - This passes the output of the exe to the custom device types.
3. Host Ping Device Type (optional) - This device type revieves the online/offline event and translates this in to an on/off switch or presence sensor.
How To Install:
1. Install the Smart App and Custom Device Type
Go to your IDE, thenâŠ
My SmartApps:
A. Create New SmartApp
B. Select âFrom Codeâ
C. Paste App source code with the code from the file SmartApp_HostPinger.txt.
D. Save and publish the app for yourself.
E. Enable OAuth in IDE by going in to IDE > My Smart Apps > [App Name] > App Settings > Enable OAuth.
F. Get the Token and API Endpoint values via one of the below methods:
- EASY OPTION: Enable debugging, open live logging in IDE and then open the app again and press done and values will be returned in Live Logging.
- Open the SmartApp and click API Information (this will involve manually typing the codes)
My Device Handlers (optional):
A. Create New Device Handler
B. Select âFrom Codeâ
C. Paste App source code with the code from the file DeviceType_HostPinger.txt.
D. Save and publish the device for yourself.
2. Configure Your Chosen Polling Application (Option A / B / C)
>> Option A: STHostPinger.exe & config.config
(Mac and Linux users can launch this exe by downloading Mono from the Mono-Project and running âmono STHostPinger.exeâ)
Linux mono install instructions: Download - Stable | Mono Also make sure you follow the instructions about certificates otherwise it will error when trying to send the https request.
Help for running on startup and in the background using mono (Post 143: Thanks RobbieCrash): [OBSOLETE] Host Pinger (IP based Online State / Presence) - #143 by RobbieCrash
A. Download the exe and config.config file.
B. Open the config.config file.
C. In config/smartThingsEndpoints fill in your API token and add the APP ID to the endpoint urls from the previous section.
ENTITY accessToken âXXXXXX FROM SMARTTHINGS XXXXXXXXXâ
ENTITY appId âXXXXXX FROM SMARTTHINGS XXXXXXXXXâ
ENTITY ide âhttps://graph-eu01-euwest1.api.smartthings.comâ
D. Be sure to also check that your IDE URL matches the URL in config.config, if you have the URL from the app then this should be correct, if you were unable to get this from the app then you willl need to copy from IDE, itâll be something like âgraph-na02-useast1.api.smartthings.comâ
E. Configure all of the IPs / Hosts or Addresses you want to ping.
item HOST=âgoogle.comâ
item HOST=â192.168.1.1â
item HOST=âSERVER1â
G. The polling interval, timeout and debugging can also be configured to your liking or leave as the default values.
H. Run The EXE
You can now run the EXE and and this should push the updates to your ST Hub via the cloud.
If anything obvious isnât working you will receive errors in the console, you can enable extra debugging by setting to 2 in config.config, or have no updates by setting to 0.
To run this on mono you will need to download mono for Mac, or for Linux install âmono-completeâ, the standard run time doesnât contain everything you need.
On Linux you can run âmono STHostPinger.exeâ or âmono STHostPinger.exe &â to run in the background (âjobsâ will show running instances and âkill $1â will kill process 1)
In windows you can make this a tray icon using:
http://rbtray.sourceforge.net/
>> Option B: PingerPy - Python Script
This has been developed by @CurlyTailed_Buffalo and I have linked directly to his post below for reference, you will need to download and install Python if you donât already have it and detailed instructions are available on the GitHub page:
>> Option C: HostPinger ESP8266 Edition
Using the Arduino IDE, load the Arduino sketch, amend the settings with your details and upload to an ESP8266 device such as the Wemos D1 Mini, which can be purchased for only a couple of ÂŁ/$ and powered from a standard USB socket.
>> Option D: Pinger Bash Script
This has been developed by @camedia and I have linked directly to his post below, this should probably be the most simple way to get a Raspberry Pi or any Unix device running.
3. Configure the Smart App
Configuration should be self explanatory however come back here with any questions.
Add a new device give it the same name you have specified as the host in config.config, you can open the device later and change to a different name if you like!
4. Errors / Debugging
EXE - SendGetRequest: the remote server returned and error: (403) Forbidden
There is an issue with the URL, App ID or token in config.config re-check section 2.D
No error in the EXE and no âEventâ present in the App
This is because SmartThings is not reciving an event, this is usually because the App ID or Token are incorrect, if you re-install the app these values will change and need to be setup again.
âEventâ in the app, but hasnât triggered the switch to change.
This is likely to that the Child Device has been configured with a name not matching the host in config.config.
Live Logging - java.lang.NullPointerException: Cannot get property âauthoritiesâ on null object @ line xx
You have not enabled OAuth in the SmartApp
Running using Mono - Failed to SendGetRequest: Error getting response stream (Write: The authentication or decryption has failed.)
This is a certificates issue using mono, follow this link:
http://www.mono-project.com/download/stable/#download-lin-raspbian