Skip to content

Commit

Permalink
Merge pull request #36 from ShellyUSA/DanielWinks
Browse files Browse the repository at this point in the history
Add a few preferences to Motion 2.
  • Loading branch information
DanielWinks authored Feb 20, 2024
2 parents ecd1aaf + 46df458 commit 235e993
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ShellyDriverLibrary/ShellyUSA.ShellyUSA_Driver_Library.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
// /////////////////////////////////////////////////////////////////////////////
Expand Down
36 changes: 36 additions & 0 deletions WebhookWebsocket/ShellyMotion2.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ metadata {
capability "IlluminanceMeasurement" //illuminance - NUMBER, unit:lx
capability "TemperatureMeasurement" //temperature - NUMBER, unit:°F || °C
attribute 'lastUpdated', 'string'

command 'getPrefsFromDevice'
}
}

Expand All @@ -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
Expand Down

0 comments on commit 235e993

Please sign in to comment.