def prefHub() { return dynamicPage(name: "prefHub", title: "Connect to BOND", nextPage:"prefListDevices", uninstall:false, install: false) { section("Hub Information"){ input("hubIp", "text", title: "BOND Hub IP", description: "BOND Hub IP Address", required: true) input("hubToken", "text", title: "BOND Hub Token", description: "BOND Hub Token", required: true) input("refreshIntervalMin", "number", title: "BOND Home Poll Interval minutes [0-59]", required: true, defaultValue: 0) input("refreshIntervalSec", "number", title: "BOND Home Poll Interval seconds [0-59]", required: true, defaultValue: 30) input("debugOutput", "bool", title: "Enable debug logging?", defaultValue: true, displayDuringSetup: false, required: false) } displayFooter() } } def translateBondFanSpeedToHE(id, max_speeds, speed) { def speedTranslations = [ 10: [10: "high", 9: "high", 8: "medium-high", 7: "medium-high", 6: "medium", 5: "medium", 4: "medium-low", 3: "medium-low", 2: 1, 1: "low"], 9: [9: "high", 8: "medium-high", 7: "medium-high", 6: "medium", 5: "medium", 4: "medium-low", 3: "medium-low", 2: "low", 1: "low"], 8: [8: "high", 7: "medium-high", 6: "medium-high", 5: "medium", 4: "medium", 3: "medium-low", 2: "medium-low", 1: "low"], 7: [7: "high", 6: "medium-high", 5: "medium", 4: "medium", 3: "medium-low", 2: "medium-low", 1: "low"], 6: [6: "high", 5: "medium-high", 4: "medium", 3: "medium", 2: "medium-low", 1: "low"], 5: [5: "high", 4: "medium-high", 3: "medium", 2: "medium-low", 1: "low"], 4: [4: "high", 3: "medium", 2: "medium-low", 1: "low"], 3: [3: "high", 2: "medium", 1: "low"], 2: [2: "high", 1: "low" ], 1: [1: "low" ] ] if (!speed.toString().isNumber()) return speed if (max_speeds > 10 || speed > max_speeds) return 0 logDebug "${id} -> Translating ${speed}:${max_speeds} to HE ${speedTranslations[max_speeds][speed]}" return speedTranslations[max_speeds][speed] } def translateHEFanSpeedToBond(id, max_speeds, speed) { if (speed.isNumber()) return speed.toInteger() def speedTranslations = [ 10: ["high": 10, "medium-high": 8, "medium": 5, "medium-low": 3, "low": 1], 9: ["high": 9, "medium-high": 7, ":medium": 5, "medium-low": 3, "low": 1], 8: ["high": 8, "medium-high": 6, "medium": 4, "medium-low": 3, "low": 1], 7: ["high": 7, "medium-high": 6, "medium": 4, "medium-low": 3, "low": 1 ], 6: ["high": 6, "medium-high": 5, "medium": 3, "medium-low": 2, "low": 1], 5: ["high": 5, "medium-high": 4, "medium": 3, "medium-low": 2, "low": 1], 4: ["high": 4, "medium": 3, "medium-low": 2, "low": 1], 3: ["high": 3, "medium": 2, "low": 1], 2: ["high": 2, "low": 1], 1: ["low": 1] ] if (max_speeds > 10) return null logDebug "${id} -> Translating ${speed}:${max_speeds} to BOND ${speedTranslations[max_speeds][speed]}" return speedTranslations[max_speeds][speed] } def initialize() { logDebug "initializing" cleanupChildDevices() createChildDevices() subscribeSensorEvents() def refreshEveryMin = refreshIntervalMin ?: 0 def refreshEverySec = (!refreshEveryMin && !refreshIntervalSec) ? 30 : refreshIntervalSec schedule("0/${refreshEverySec} ${refreshEveryMin} * * * ? *", updateDevices) }