Skip to content

Commit

Permalink
Update xiaomi-sensor-ht.groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
fison67 committed May 8, 2019
1 parent fe0547b commit a6d7b7e
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions devicetypes/fison67/xiaomi-sensor-ht.src/xiaomi-sensor-ht.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ metadata {
attribute "currentDay", "String"

attribute "lastCheckin", "Date"
attribute "lastCheckinDate", "String"

command "chartTemperature"
command "chartHumidity"
Expand Down Expand Up @@ -205,16 +204,9 @@ def setStatus(params){
break;
}

def now = formatDate()
def nowDate = new Date(now).getTime()

// Any report - temp, humidity, pressure, & battery - results in a lastCheckin event and update to Last Checkin tile
// However, only a non-parseable report results in lastCheckin being displayed in events log
sendEvent(name: "lastCheckin", value: now, displayed: false)
sendEvent(name: "lastCheckinDate", value: nowDate, displayed: false)

// Check if the min/max temp and min/max humidity should be reset
checkNewDay(now)
checkNewDay()
updateLastTime()
}

def makeTemperature(temperature){
Expand All @@ -239,6 +231,11 @@ def refresh(){
sendCommand(options, callback)
}

def sendCommand(options, _callback){
def myhubAction = new physicalgraph.device.HubAction(options, null, [callback: _callback])
sendHubCommand(myhubAction)
}

def callback(physicalgraph.device.HubResponse hubResponse){
def msg
try {
Expand All @@ -263,9 +260,9 @@ def updateLastTime(){

def updated() {}

def checkNewDay(now) {
def checkNewDay() {
def oldDay = ((device.currentValue("currentDay")) == null) ? "32" : (device.currentValue("currentDay"))
def newDay = new Date(now).format("dd")
def newDay = new Date().format("dd")
if (newDay != oldDay) {
resetMinMax()
sendEvent(name: "currentDay", value: newDay, displayed: false)
Expand Down

0 comments on commit a6d7b7e

Please sign in to comment.