Skip to content

Commit

Permalink
Update ShellyMotion2.groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWinks committed Feb 20, 2024
1 parent 323dfc2 commit 46df458
Showing 1 changed file with 36 additions and 0 deletions.
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 46df458

Please sign in to comment.