2 * Copyright 2015 SmartThings
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
11 * for the specific language governing permissions and limitations under the License.
19 name: "Hub IP Notifier",
20 namespace: "smartthings",
21 author: "SmartThings",
22 description: "Listen for local IP changes when your hub registers.",
23 category: "SmartThings Internal",
24 iconUrl: "https://s3.amazonaws.com/smartapp-icons/MyApps/Cat-MyApps.png",
25 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/MyApps/Cat-MyApps@2x.png"
29 page(name: "pageWithIp", title: "Hub IP Notifier", install: true)
34 def currentIp = state.localip ?: 'unknown'
35 def registerDate = state.lastRegister ?: null
36 dynamicPage(name: "pageWithIp", title: "Hub IP Notifier", install: true, uninstall: true) {
37 section("When Hub Comes Online") {
38 input "hub", "hub", title: "Select a hub"
40 section("Last Registration Details") {
41 if(hub && registerDate) {
42 paragraph """Your hub last registered with IP:
46 } else if (hub && !registerDate) {
47 paragraph "Your hub has not (re)registered since you installed this app"
49 paragraph "Check back here after installing to see the current IP of your hub"
56 log.debug "Installed with settings: ${settings}"
62 log.debug "Updated with settings: ${settings}"
69 subscribe(hub, "hubInfo", registrationHandler, [filterEvents: false])
72 def registrationHandler(evt) {
73 def hubInfo = evt.description.split(',').inject([:]) { map, token ->
74 token.split(':').with { map[it[0].trim()] = it[1] }
77 state.localip = hubInfo.localip
78 state.lastRegister = new Date()
79 sendNotificationEvent("${hub.name} registered in prod with IP: ${hubInfo.localip}")