Announcement

Collapse
No announcement yet.

Can I check how many days a device has been on?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can I check how many days a device has been on?

    I need to know when a device has been on for x days. Is that possible to do with a script?

    Specifically, what I want to do is turn my sprinkler system rain delay off after it's been on for three days. If I want to reset it for another three days, I'll just turn it off and then back on. What I'm trying to avoid is forgetting that it's on.

    Thanks.

    #2
    <pre class="ip-ubbcode-code-pre">

    if hs.isOn(sprinklerDelay) Then
    if datediff("d",hs.DeviceLastChange(sprinklerDelay),now) &gt; 3 Then
    'do what you want
    end if
    end if

    ' use "h" and (3 * 24) or "n" and (3* 24 * 60) for better resolution</pre>

    Comment


      #3
      Michael,

      How is "datediff" calculated? Does it change at midnight each night or does it change every 24 hours? For example, if the device is turned on at 23:00, will it show it's been on for one day at 00:01, or will it be 23:00 the next day before it shows it's been on one day?

      Thanks for the help.

      Comment

      Working...
      X