definition(
name: "Hub Details",
namespace: "hubDetails",
author: "Josh Lobe",
description: "Hub details and statistics.",
category: "Convenience",
iconUrl: "",
iconX2Url: ""
)
import java.text.DecimalFormat
import java.text.SimpleDateFormat
hubUrl = "http://${location.hub.localIP}"
preferences {
page(name: "mainPage", title: "Hub Details", install: true, uninstall: true) {
section {
Integer DD = location.hub.uptime / (24 * 3600)
Integer HH = (location.hub.uptime % (24 * 3600)) / 3600
Integer MM = (location.hub.uptime % 3600) / 60
Integer SS = location.hub.uptime % 60
// Scripts
html = ""
html += "
"
html += "
"
// Hub Details
html += "
"
html += "| Hub Details |
"
html += "| Name | ${location.hub.name} |
"
html += "| Model | ${getHubVersion()} |
"
html += "| Local IP | ${location.hub.localIP} |
"
html += "| Firmware | ${location.hub.firmwareVersionString} |
"
html += "| Zigbee ID | ${location.hub.zigbeeId} |
"
html += "| Zigbee EUI | ${location.hub.zigbeeEui} |
"
html += "| Zigbee Channel | ${location.hub.properties.data.zigbeeChannel} |
"
html += "| Zigbee Pan ID | ${location.hub.data.zigbeePanID} |
"
html += "| Uptime | ${ DD + ' days, ' + HH + ' Hours, ' + MM + ' Minutes, and ' + SS + ' Seconds' } |
"
html += "
"
httpGet([ uri: "${hubUrl}:8080/hub2/hubData", contentType: "application/json" ]) { resp ->
if (resp.success) {
// Hub Data
html += "
"
html += "| Hub Data |
"
html += "| Hub ID | ${resp.data.hubId} |
"
html += "| Access Token | ${resp.data.baseModel.dashboard.accessToken} |
"
html += "| Hub Version | ${resp.data.hubVersion} |
"
html += "
"
// Hub Alerts
html += "
"
html += "| Hub Alerts |
"
html += "| Load High | ${resp.data.alerts.hubHighLoad} |
"
html += "| Load Elevated | ${resp.data.alerts.hubLoadElevated} |
"
html += "| Load Severe | ${resp.data.alerts.hubLoadSevere} |
"
html += "| Low Memory | ${resp.data.alerts.hubLowMemory} |
"
html += "| Large-ish Database | ${resp.data.alerts.hubLargeishDatabase} |
"
html += "| Large Database | ${resp.data.alerts.hubLargeDatabase} |
"
html += "| Huge Database | ${resp.data.alerts.hubHugeDatabase} |
"
html += "| Zigbee Offline | ${resp.data.alerts.zigbeeOffline} |
"
html += "| ZWave Offline | ${resp.data.alerts.zwaveOffline} |
"
html += "| Spammy Devices | ${resp.data.alerts.spammyDevices} |
"
html += "
"
}
}
html += "
"
html += "
"
// Location Details
html += "
"
html += "| Location Details |
"
html += "| Name | ${location.name} |
"
html += "| ID | ${location.id} |
"
html += "| Firmware | ${location.hub.firmwareVersionString} |
"
html += "| Zip Code | ${location.zipCode} |
"
html += "| Latitude | ${location.latitude} |
"
html += "| Longitude | ${location.longitude} |
"
html += "| Sunrise | ${location.sunrise} |
"
html += "| Sunset | ${location.sunset} |
"
html += "| HSM Status | ${location.hsmStatus} |
"
html += "| HSM Mode | ${location.properties.currentMode} |
"
html += "| Temp Scale | ${location.temperatureScale} |
"
html += "
"
// Hub Endpoints
html += "
"
html += "| Hub Endpoints |
"
httpGet([ uri: "${hubUrl}:8080/hub/advanced/freeOSMemory" ]) { resp ->
if (resp.success) {
DecimalFormat df = new DecimalFormat( "#,###" )
historyLink = "(history)"
html += "| Hub Memory | ${df.format( resp.data.toString() as Integer )} KB ${historyLink} |
"
}
}
httpGet([ uri: "${hubUrl}:8080/hub/advanced/internalTempCelsius" ]) { resp ->
if (resp.success) { html += "| Hub CPU Temp | ${celsiusToFahrenheit( new Double( resp.data.toString() ) )} °F |
" }
}
httpGet([ uri: "${hubUrl}:8080/hub/advanced/databaseSize" ]) { resp ->
if (resp.success) { html += "| Database Size | ${resp.data} MB |
" }
}
httpGet([ uri: "${hubUrl}:8080/hub/advanced/maxDeviceStateAgeDays" ]) { resp ->
if (resp.success) { html += "| Max State Time | ${resp.data} Days |
" }
}
httpGet([ uri: "${hubUrl}:8080/hub/advanced/maxEventAgeDays" ]) { resp ->
if (resp.success) { html += "| Max Event Time | ${resp.data} Days |
" }
}
html += "
"
httpGet([ uri: "${hubUrl}:8080/hub/zwaveVersion" ]) { resp ->
if (resp.success) {
zString = resp.data.toString()
Integer start = zString.indexOf( '(' )
Integer end = zString.length()
String wrkStr = zString.substring( start, end ).replace( "(", "[" ).replace( ")", "]" )
HashMap zMap = (HashMap)evaluate( wrkStr )
// ZWave Data
html += "
"
html += "| ZWave Data |
"
html += "| Library Type | ${zMap.zWaveLibraryType} |
"
html += "| Protocol Version | ${zMap.zWaveProtocolVersion} |
"
html += "| Protocol Sub Version | ${zMap.zWaveProtocolSubVersion} |
"
html += "| Firmware Version | ${zMap.firmware0Version} |
"
html += "| Firmware Sub Version | ${zMap.firmware0SubVersion} |
"
html += "| Hardware Version | ${zMap.hardwareVersion} |
"
html += "
"
}
}
html += "
"
html += "
"
httpGet([ uri: "${hubUrl}:8080/hub/advanced/freeOSMemoryHistory", contentType: "text/html" ]) { resp ->
if (resp.success) {
html += ""
// Memory Graph
html += "
"
// CPU Graph
html += "
"
html += "
"
def count = 0
def times = ''
def mems = ''
def cpus = ''
loadWork = resp.data.toString()
loadWork.eachLine{
if( it.contains( "Date" ) ) return
count++
if( count % 20 != 0 ) return
line = it.split( "," )
Date date = Date.parse( 'MM-dd H:mm:ss', line[0] )
String newDate = date.format( 'MM-dd, h:mm a' )
times += '"' + newDate + '",'
mems += line[1] + ','
cpus += line[2] + ','
}
times = times.replaceAll(',$', '');
mems = mems.replaceAll(',$', '');
cpus = cpus.replaceAll(',$', '');
html += ""
}
}
// Styles
html += ""
// Print the page
paragraph html
}
}
}
def installed() {
log.trace "Installed Hub Details Application"
updated()
}
def updated() {
log.trace "Updated Hub Details Application"
}
def uninstalled() {
log.trace "Uninstalled Hub Details Application"
}