Skip to content
Nicholas Wilde edited this page Oct 23, 2015 · 12 revisions

Adding Contacts to the Device Type

Raspberry Pi

$ nano /usr/share/berryio/includes/views/api/pages/smartthings.php
...
    "gpio_value_17":"<?=$gpio_values[17]?>"
}

Restart the Apache service

$ sudo service apache2 restart

Test to make sure that the command works

http://<rpi-ip>/api_command/smartthings
{ "1M_load":"0.54", "5M_load":"0.26", "15M_load":"0.1", "cpu_temp":"59.5", "cpu_speed":"1000104000", "cpu_volt":"1.3500", "cpu_perc":"0", "disk_usage":"40.59", "mem_avail":"404.67578125", "gpio_value_17":"not_exported" }

SmartThings

Add the tile to the SmartThings device type. Be sure to give a unique name to the tile and add it to the details section. In this example, the unique name is contact.

metadata{
...
    tiles {
    ...
        standardTile("contact", "device.contact", width: 1, height: 1) {
			state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821", action: "open")
			state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e", action: "close")
		}
		details(["button", "temperature", "cpuPercentage", "memory" , "diskUsage", "contact", "restart", "refresh"])
    }
}
// parse events into attributes
def parse(String description) {
...
    if (result.containsKey("disk_usage")) {
    	log.debug "disk_usage: ${result.disk_usage.toDouble().round()}"
        sendEvent(name: "diskUsage", value: result.disk_usage.toDouble().round())
    }
  	if (result.containsKey("gpio_value_17")) {
    	log.debug "gpio_value_17: ${result.gpio_value_17.toDouble().round()}"
        if (result.gpio_value_17.contains("0")){
        	log.debug "gpio_value_17: open"
            sendEvent(name: "contact", value: "open")
        } else {
        	log.debug "gpio_value_17: closed"
            sendEvent(name: "contact", value: "closed")
        }
    }
  	
}

Testing the Raspberry Pi Setup

http://<rpi-ip>/gpio_status

Click on OUT on GPIO-17 to enable the GPIO and set it to an output.

Test to make sure that the command works.

URL:

http://<rpi-ip>/api_command/smartthings

Response:

{ "1M_load":"0.54", "5M_load":"0.26", "15M_load":"0.1", "cpu_temp":"59.5", "cpu_speed":"1000104000", "cpu_volt":"1.3500", "cpu_perc":"0", "disk_usage":"40.59", "mem_avail":"404.67578125", "gpio_value_17":"0" }

Click on ON to turn on GPIO-17.

Test to make sure that the command output turned on.

URL:

http://<rpi-ip>/api_command/smartthings

Response:

{ "1M_load":"0.54", "5M_load":"0.26", "15M_load":"0.1", "cpu_temp":"59.5", "cpu_speed":"1000104000", "cpu_volt":"1.3500", "cpu_perc":"0", "disk_usage":"40.59", "mem_avail":"404.67578125", "gpio_value_17":"1" }

Alternate Raspberry Pi Test Method

Instead of using your browser to look for a response, you can use a cURL command from a terminal command line.

$ curl -D- -u <username>:<password> -X GET -H "Content-Type: application/json" http://<rpi-ip>/api_command/smartthings

Response:

HTTP/1.1 200 OK
Date: ...
Server: Apache/2.2.22 (Debian)
X-Powered-By: PHP/5.4.45-0+deb7u1
Vary: Accept-Encoding
Content-Length: 229
Content-Type: text/html


{ 
  "1M_load":"0",
  "5M_load":"0.04",
  "15M_load":"0.12",
  "cpu_temp":"58.9",
  "cpu_speed":"1000000000",
  "cpu_volt":"1.3500",
  "cpu_perc":"0",
  "disk_usage":"40.61",
  "mem_avail":"356.89453125",
  "gpio_value_17":"1"
}

Testing the SmartThings Device Type Setup

Hit the refresh button from the Raspberry Pi Device Type SmartThings app and monitor the live logging.

Response:

...
body: 
{
"1M_load":"0",
"5M_load":"0.01",
"15M_load":"0.09",
"cpu_temp":"58.4",
"cpu_speed":"1000000000",
"cpu_volt":"1.3500",
"cpu_perc":"0",
"disk_usage":"40.61",
"mem_avail":"357.2890625",
"gpio_value_17":"1"
}
debug Executing hubAction on <rpi-ip>:<rpi-port>
...