[RELEASE] HTTP Online Sensor

SmartThings-HTTP-Online-Sensor

A SmartThings device handler that regularly GETs an HTTP endpoint, including local network addresses. It reveals a status of OFFLINE or ONLINE. (For automation purposes, it is a Presence Sensor, and is either “present” or “not present”, but the visual indication in the SmartThings app is ONLINE/OFFLINE.)

GitHub

Background

While my home automation is done through SmartThings, I like Apple HomeKit as a usable dashboard.
Therefore I have a Raspberry Pi running HomeBridge, and exposing all my SmartThings devices to HomeKit.
The problems were that:

  • The Raspberry Pi might lose wifi
  • When my router rebooted, the Pi didn’t always reconnect
  • Sometimes HomeBridge itself would hang, breaking my HomeKit dashboard.

The easiest fix for all of this is just a reboot of the Raspberry Pi.

Solution:

  1. Plug the Pi into a smart z-wave plug/outlet.
  2. Create a rule in WebCoRE (or CoRE or whatever rules engine you use) to cycle the Pi’s power if it is detected that the Pi is offline
  3. Create a Device Handler type that could detect if the Pi was offline.

Next problem: You can’t do a real PING of a local network device from a SmartThings hub. You can only do simple HTTP GET requests. However, HomeBridge (and specifically the SmartThings plugin for it) exposed a very simple endpoint at port 8000 that would just return OK if you get it. So that would work for a ping-substitute. The SmartThings hub just needs to regularly GET http://192.168.1.xxx:8000. If a couple requests are missed in a row, consider it offline.

So that’s the reasoning behind this device handler. Hopefully it will help your home automation solutions too.

Installation

This handler supports SmartThings/GitHub integration.

  1. Log in to https://account.smartthings.com
  2. Click “My Device Handlers”
  3. Click “Settings”
  4. Add a new Git repo:
    a) Owner: joelwetzel
    b) Name: SmartThings-HTTP-Online-Sensor
    c) Branch: master
    d) Click “Save”
  5. Click Update from Repo
  6. Click SmartThings-HTTP-Online-Sensor
  7. Check the http-online-sensor.groovy file
  8. Check “Publish”
  9. Click “Execute Update”

Now the device handler should be installed. Next, you have to add and configure the device itself.

  1. Click “My Devices”
  2. Click “+ New Device”
  3. Enter “Name”
  4. Enter “Device Network Id”. Use your desired IP address and port. Example: 192.168.1.91:8000
  5. Set “Type” to “HTTP Online Sensor”
  6. Set Location
  7. Set Hub
  8. Click Create

Final step: The Device Network Id actually needs to be hex encoded. To find and set this encoding:

  1. Click “Live Logging”
  2. Watch for an error message from the device you just added. It will say that you need to use the HEX encoded value and show it.
  3. Copy the HEX encoded value
  4. Go back to the edit screen for your device and paste the HEX encoded value as the new “Device Network Id”

Now, if you go back to live logging, you should see messages about your device being ONLINE or OFFLINE, depending on if it can be reached. Your device will show up in the SmartThings mobile apps and you’ll be able to run automation based on its presence state.

3 Likes

Thanks for this! I have a Home Assistant Server that I use for certain scripts and wanted a way to see if it was offline before things failed.

Somehow i didnt realize that “live logging” was across the top of the screen. I was looking everywhere for it in the device section… im a rookie ha.

Can this also check https sites? my link is https:x.x.x.x:8123. It is showing offline right now, whatn it is up - wondering if it is my setup or if it is unable to check the https site.

Perfectly! Thanks You! This is the really easiest monitoring solution for my home infrastructure. Now I always know if some TV, router, IP camera or server is not available on my network :slight_smile:

Hi,
This is great - sad didn’t find it earlier
First one worked fine but next few didn’t.
First device: IDE device status: online, Logging shows online, presence sensor shows present
Second+ device: IDE device status: online, Logging shows offline, presence sensor shows not present

This is a problem for any future adds (I thought initially issue was only for password protected site)
Reboot hub - same problem

Kind of realizing what happened. The IDE only recognizes http 200 as success
On IDE
I modified the Device Handler
This line
if (msg.status == 200 ) {
changed to
if (msg.status == 200 || msg.status == 301 || msg.status == 401 ) {
Then saved and publish
Go to already created devices and modify version from Published to Self Published

Now other devices that respond with
(301) Redirect
(401) Ask for user/password
Work fine

I also couldnt figure out how to make https work

(PS Above works but appreciate if somebody can comment verify if there is a good way to save modified handlers. I am afraid at some point my handler will revert back to original)

UPDATE - I was obviusly disconnected of recent developments and above relies on the ST Groovy architecture that is about to fully be phased out. All that can be accomplished with EDGE drivers now