How to set/use dates in device handlers?

I’m writing a DH for an energy monitor in ST classic. I’ve already added some cost calculations and these create a new attribute “cost” that’s derived from the current value of kWh * costPerUnit that’s set by the user in preferences.

The next step is to add a resetDate and resetOffest. The idea here is you press reset and instead of resetting the meter’s internal reading, it just records the current date and meter reading.

In this way the cost can be calculated from the last reset date by subtracting the resetOffset and using the resetDate to calculate the standing charge aspect of the bill.

But I can’t find a “date” type for attributes or preferences.

I’d rather use an attribute or stored variable for resetDate and resetOffset, I don’t want them user configurable. I just want to create a method that sets these values to the current date and current meter reading when the users presses a tile.

What’s the best way to do this?

  • bool
  • decimal
  • email
  • enum
  • number
  • password
  • phone
  • time
  • text

Source : https://docs.smartthings.com/en/latest/device-type-developers-guide/device-preferences.html#supported-input-types

These are the types supported by preferences.

If think time might help.

  • STRING
  • NUMBER
  • VECTOR3
  • ENUM

Source : https://docs.smartthings.com/en/latest/ref-docs/attribute-ref.html#getdatatype

These are the types supported by attributes.

The best you can have here is STRING.

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.