From 323dfc279fab005acb333fac2756a642b9fd73a9 Mon Sep 17 00:00:00 2001 From: Daniel Winks Date: Mon, 19 Feb 2024 20:43:28 -0500 Subject: [PATCH 1/2] Update ShellyUSA.ShellyUSA_Driver_Library.groovy --- .../ShellyUSA.ShellyUSA_Driver_Library.groovy | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ShellyDriverLibrary/ShellyUSA.ShellyUSA_Driver_Library.groovy b/ShellyDriverLibrary/ShellyUSA.ShellyUSA_Driver_Library.groovy index 0f4ea18..64e3fe5 100644 --- a/ShellyDriverLibrary/ShellyUSA.ShellyUSA_Driver_Library.groovy +++ b/ShellyDriverLibrary/ShellyUSA.ShellyUSA_Driver_Library.groovy @@ -41,6 +41,7 @@ if (device != null) { input 'deviceUsername', 'string', title: 'Device Username (if enabled on device)', required: false, defaultValue: 'admin' } input 'devicePassword', 'password', title: 'Device Password (if enabled on device)', required: false, defaultValue: '' + preferenceMap.each{ k,v -> if(getDeviceSettings().containsKey(k)) { if(v.type == 'enum') { @@ -50,6 +51,7 @@ if (device != null) { } } } + if(hasPowerMonitoring() == true) { input(name: 'enablePowerMonitoring', type:'bool', title: 'Enable Power Monitoring', required: false, defaultValue: true) input(name: 'resetMonitorsAtMidnight', type:'bool', title: 'Reset Total Energy At Midnight', required: false, defaultValue: true) @@ -122,6 +124,9 @@ void updated() { current_limit: [type: 'number', title: 'Overcurrent protection in amperes'], power_limit: [type: 'number', title: 'Overpower protection in watts'], voltage_limit: [type: 'number', title: 'Overvoltage protection in volts'], + gen1_motion_sensitivity: [type: 'number', title: 'Motion sensitivity (1-256, lower is more sensitive)'], + gen1_motion_blind_time_minutes: [type: 'number', title: 'Motion cool down in minutes'], + gen1_tamper_sensitivity: [type: 'number', title: 'Tamper sensitivity (1-127, lower is more sensitive, 0 for disabled)'] ] @Field static List powerMonitoringDevices = [ "SNPL-00116US" @@ -966,6 +971,30 @@ void setTamperOn(Boolean tamper) { void setIlluminance(Integer illuminance) { getDevice().sendEvent(name: 'illuminance', value: illuminance) } + +@CompileStatic +void setGasDetectedOn(Boolean tamper) { + if(tamper == true) { + getDevice().sendEvent(name: 'naturalGas', value: 'detected') + } else { + getDevice().sendEvent(name: 'naturalGas', value: 'clear') + } +} + +@CompileStatic +void setGasPPM(Integer ppm) { + getDevice().sendEvent(name: 'ppm', value: ppm) +} + +@CompileStatic +void setValvePosition(Boolean open, Integer valve = 0) { + if(open == true) { + getDevice().sendEvent(name: 'valve', value: 'open') + } else { + getDevice().sendEvent(name: 'valve', value: 'closed') + } +} + // ///////////////////////////////////////////////////////////////////////////// // End Power Monitoring Getters and Setters // ///////////////////////////////////////////////////////////////////////////// From 46df4589238dbfdc6f53f4255a419ebee4373c40 Mon Sep 17 00:00:00 2001 From: Daniel Winks Date: Mon, 19 Feb 2024 20:43:32 -0500 Subject: [PATCH 2/2] Update ShellyMotion2.groovy --- WebhookWebsocket/ShellyMotion2.groovy | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/WebhookWebsocket/ShellyMotion2.groovy b/WebhookWebsocket/ShellyMotion2.groovy index cfbe22b..3b38794 100644 --- a/WebhookWebsocket/ShellyMotion2.groovy +++ b/WebhookWebsocket/ShellyMotion2.groovy @@ -9,6 +9,8 @@ metadata { capability "IlluminanceMeasurement" //illuminance - NUMBER, unit:lx capability "TemperatureMeasurement" //temperature - NUMBER, unit:°F || °C attribute 'lastUpdated', 'string' + + command 'getPrefsFromDevice' } } @@ -22,6 +24,40 @@ void configure() { this.device.setDeviceNetworkId(convertIPToHex(settings?.ipAddress)) this.device.sendEvent(name: 'numberOfButtons', value: 3) setDeviceActionsGen1() + + if(getDeviceDataValue('ipAddress') == null || getDeviceDataValue('ipAddress') != getIpAddress()) { + getPrefsFromDevice() + } else if(getDeviceDataValue('ipAddress') == getIpAddress()) { + sendPrefsToDevice() + } + setDeviceDataValue('ipAddress', getIpAddress()) +} + +@CompileStatic +void sendPrefsToDevice() { + if( + getDeviceSettings().gen1_motion_sensitivity != null && + getDeviceSettings().gen1_motion_blind_time_minutes != null && + getDeviceSettings().gen1_tamper_sensitivity != null + ) { + String queryString = "motion_sensitivity=${getDeviceSettings().gen1_motion_sensitivity}".toString() + queryString += "&motion_blind_time_minutes${getDeviceSettings().gen1_motion_blind_time_minutes}".toString() + queryString += "&tamper_sensitivity${getDeviceSettings().gen1_tamper_sensitivity}".toString() + sendGen1Command('settings', queryString) + } +} + +@CompileStatic +void getPrefsFromDevice() { + LinkedHashMap response = (LinkedHashMap)sendGen1Command('settings') + logJson(response) + LinkedHashMap prefs = [ + 'gen1_motion_sensitivity': ((LinkedHashMap)response?.motion)?.sensitivity as Integer, + 'gen1_motion_blind_time_minutes': ((LinkedHashMap)response?.motion)?.blind_time_minutes as Integer, + 'gen1_tamper_sensitivity': response?.tamper_sensitivity as Integer + ] + logJson(prefs) + setDevicePreferences(prefs) } @CompileStatic