sprinkler action

Posted on
Tue May 22, 2018 8:29 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

sprinkler action

I like to get the time duration of the zone that is running called by a regular indigo sprinkler action
Code: Select all
    def actionControlSprinkler(self, action, dev):
the information available in the method is (indigo. server.log(unicode(action))
Code: Select all
delayAmount : 900:
description : "device - zone1" on
deviceId : 1757238557
multiplierVarId : None
replaceExisting : True
sprinklerAction : ZoneOn
textToSpeak :
zoneDurations : []
zoneIndex : 1


in the method I like to have the duration of the zone action.! is there anyway of getting that, besides going through the logfile:
Code: Select all
   Schedule                        rpi sprinkler
   Sprinkler                       scheduled "rpi-14-sprinkler" zone durations: 5.00, 2.00, 5.00, 6.00, 4.00, 6.00, 3.00, 2.00, 8.00
   Sprinkler                       turning "rpi-14-sprinkler" zone 1 on for 5.00 minutes


there is one prop in action : zoneDurations [] that is empty.
- how can that be set, and will it be used by the action


Have an rpi with pibecon setup that turns the relays on/off and has a display that shows zone info: accumulate time today, yesterday, this week, last week, this month, last month, active zone , rain amount .... date time, temp humidity ..



Only thing missing is the runtime time left for the current zone .

Thanks

Karl
Attachments
Screen Shot 2018-05-22 at 21.26.07.png
Screen Shot 2018-05-22 at 21.26.07.png (363.94 KiB) Viewed 2138 times

Posted on
Tue May 22, 2018 10:24 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: sprinkler action

figured it out, but it is not simple

the sprinkler device -- NOT the ACTION -- has :
Code: Select all
zoneMaxDurations : [20.0, 12.0, 30.0, 15.0, 10.0, 10.0, 10.0, 10.0, 10.0, 200.0]
zoneScheduledDurations : [19.9, 11.9, 29.9, 14.9, 9.9, 9.9, 9.9, 9.9, 9.9]
adding a device state "active sprinkler started", populated with
Code: Select all
dev.updateStateOnServer("activeZoneStarted", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
and
if action.sprinklerAction == indigo.kSprinklerAction.AllZonesOff:
  dev.updateStateOnServer("activeZoneStarted", "")

in the action method.

then in the display action:
Code: Select all
import datetime
dev    = indigo.devices[1757238557]
props  = dev.pluginProps
durations = dev.zoneScheduledDurations
zoneMaxDurations = dev.zoneMaxDurations
activeZone = int(dev.states["activeZone"])
zoneStarted = dev.states["activeZoneStarted"]
if len(zoneStarted) > 10:
   secDone = (datetime.datetime.now() - datetime.datetime.strptime(zoneStarted, "%Y-%m-%d %H:%M:%S")).total_seconds()
   minutes  = int(secDone/60)
   dur = min(durations[activeZone-1], zoneMaxDurations[activeZone-1])
   timeLeft = "%2d"%( dur - minutes)
   dur = "%2d"%dur
   aText  = "ActiveZone: #"+str(activeZone)+";    start:"+ zoneStarted[10:-3]+"; dur:"+dur+"; left:"+ timeLeft+" [min]"
else:
   timeLeft =""
   dur = ""
   aText  = "Zones off"

gives:
"ActiveZone: #1; start: 23:13; dur:19; left:13 [min]"

Karl

will all be available in std pibeacon if you like to try..
Attachments
Screen Shot 2018-05-22 at 23.36.55.png
Screen Shot 2018-05-22 at 23.36.55.png (364.44 KiB) Viewed 2123 times

Posted on
Tue May 22, 2018 10:42 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: sprinkler action

if anyone is interested here the complete display script:
Code: Select all
import datetime
dev    = indigo.devices[1757238557]
props  = dev.pluginProps
zNames = dev.zoneNames
nZones = dev.zoneCount
durations = dev.zoneScheduledDurations
zoneMaxDurations = dev.zoneMaxDurations
activeZone = int(dev.states["activeZone"])
zoneStarted = dev.states["activeZoneStarted"]
#indigo.server.log(unicode(activeZone))
#indigo.server.log(unicode(zoneStarted))
#indigo.server.log(unicode(durations))
#indigo.server.log(unicode(zoneMaxDurations))
if len(zoneStarted) > 10 and activeZone > 0 and len(durations) == nZones:
   secDone = (datetime.datetime.now() - datetime.datetime.strptime(zoneStarted, "%Y-%m-%d %H:%M:%S")).total_seconds()
   minutes  = int(secDone/60)
   dur = min(durations[activeZone-1], zoneMaxDurations[activeZone-1])
   timeLeft = "%2d"%( dur - minutes)
   dur = "%2d"%(dur+0.2)
   aText  = "ActiveZone: #"+str(activeZone)+";    start:"+ zoneStarted[10:-3]+"; dur:"+dur+"; left:"+ timeLeft+" [min]"
elif len(zoneStarted) > 10 and activeZone > 0 :
   secDone = (datetime.datetime.now() - datetime.datetime.strptime(zoneStarted, "%Y-%m-%d %H:%M:%S")).total_seconds()
   minutes  = int(secDone/60)
   dur = zoneMaxDurations[activeZone-1]
   timeLeft = "%2d"%( dur - minutes)
   dur = "%2d"%(dur+0.2)
   aText  = "ActiveZone: #"+str(activeZone)+";  manual start:"+ zoneStarted[10:-3]+"; dur:"+dur+"; left:"+ timeLeft+" [min]"
else:
   timeLeft =""
   dur = ""
   aText  = "Zones off"

onTime = "1"
if dev.states["activeZone"] == 0:
   onTime = "3"
   aText  = "sprinklers OFF"
tDay   = dev.states["minutesRunToday"].split(",")
yDay   = dev.states["minutesRunYesterday"].split(",")
tWeek  = dev.states["minutesRunThisWeek"].split(",")
lWeek  = dev.states["minutesRunLastWeek"].split(",")
tMonth = dev.states["minutesRunThisMonth"].split(",")
lMonth = dev.states["minutesRunLastMonth"].split(",")


line = ["" for ii in range(10)]
for ii in range(len(zNames)):
   line[ii]  = "%2d "%(ii+1)
   line[ii] += (zNames[ii][0:11]).ljust(11)
   line[ii] += tDay[ii].rjust(3)
   line[ii] += yDay[ii].rjust(5)
   line[ii] += tWeek[ii].rjust(5)
   line[ii] += lWeek[ii].rjust(5)
   line[ii] += tMonth[ii].rjust(6)
   line[ii] += lMonth[ii].rjust(6)



plug = indigo.server.getPlugin("com.karlwachs.piBeacon")
plug.executeAction("Display" ,   props ={
   "outputDev":"601124473"
  ,"device":"OUTPUT-Display"
  ,"restoreAfterBoot":"False"
  ,"intensity":""
  ,"repeat":"9999999"
  ,"resetInitial":"(0,0,0)"
  ,"scrollxy":""
  ,"showDateTime":"0"
  ,"startAtDateTime":"0"
  ,"scrollPages":""
  ,"scrollDelay":""
  ,"scrollDelayBetweenPages":""
  ,"command":'['+
      '{"type":"rectangle",   "position":[0,0,800,600],        "fill":[50, 50,50],       "display":"wait"}'+
     ',{"type":"text",        "position":[0,0],    "width":20, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf",       "text":" Zone    Min.:  Day YestD Week LWeek Month LMonth" }'+
     ',{"type":"text",        "position":[5,25],   "width":22, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf", "text":"'+ line[0]+'" }'+
     ',{"type":"text",        "position":[5,50],   "width":22, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf", "text":"'+ line[1]+'" }'+
     ',{"type":"text",        "position":[5,75],   "width":22, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf", "text":"'+ line[2]+'" }'+
     ',{"type":"text",        "position":[5,100],  "width":22, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf", "text":"'+ line[3]+'" }'+
     ',{"type":"text",        "position":[5,125],  "width":22, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf", "text":"'+ line[4]+'" }'+
     ',{"type":"text",        "position":[5,150],  "width":22, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf", "text":"'+ line[5]+'" }'+
     ',{"type":"text",        "position":[5,175],  "width":22, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf", "text":"'+ line[6]+'" }'+
     ',{"type":"text",        "position":[5,200],  "width":22, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf", "text":"'+ line[7]+'" }'+
     ',{"type":"text",        "position":[5,225],  "width":22, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf", "text":"'+ line[8]+'" }'+
     ',{"type":"text",        "position":[5,250],  "width":22, "fill":[0, 255, 0],     "display":"wait",     "font":"Andale Mono.ttf", "text":"'+ line[9]+'" }'+
     ',{"type":"text",        "position":[5,275],  "width":30, "fill":[255, 0, 0],     "display":"wait",     "font":"Arial.ttf",       "text":"'+aText+'",  "offONTime":[0, '+onTime+', 1]  }'+
     ',{"type":"text",        "position":[5,315],  "width":30, "fill":[255,255, 255],  "display":"wait",     "font":"Andale Mono.ttf", "text":"Outside Temp" }'+
     ',{"type":"textWformat", "position":[203,315],"width":30, "fill":[255,255, 255],  "display":"wait",     "font":"Andale Mono.ttf", "text":"%%d:340764825:Temperature%%FORMAT%5d [F]" }'+
     ',{"type":"text",        "position":[5,350],  "width":30, "fill":[255,255, 255],  "display":"wait",     "font":"Andale Mono.ttf", "text":"        Hum.  %%d:340764825:Humidity%% %" }'+
     ',{"type":"text",        "position":[5,390],  "width":30, "fill":[255,255, 255],  "display":"wait",     "font":"Andale Mono.ttf", "text":" Rain Today" }'+
     ',{"type":"textWformat", "position":[203,390],"width":30, "fill":[255,255, 255],  "display":"wait",     "font":"Andale Mono.ttf", "text":"%%d:57636140:currentDayTotal%%FORMAT%5.1f [in]" }'+
     ',{"type":"dateString",  "position":[10,425], "width":50, "fill":[255, 255, 255], "display":"wait",     "font":"Arial.ttf",       "text":"%a, %b  %d, %Y"  }'+
     ',{"type":"digitalClock","position":[550,425],"width":50, "fill":[250, 255, 50],  "display":"immediate","font":"Arial.ttf",       "box":{"on": "box", "width": "250", "height": "60", "fill": [0, 0, 0]} }]'
  })
and the sprinkler device has the following states
Screen Shot 2018-05-22 at 23.40.34.png
Screen Shot 2018-05-22 at 23.40.34.png (67 KiB) Viewed 2123 times

and the device edit:
Screen Shot 2018-05-22 at 23.41.52.png
Screen Shot 2018-05-22 at 23.41.52.png (109.21 KiB) Viewed 2123 times
Last edited by kw123 on Wed May 23, 2018 3:35 pm, edited 1 time in total.

Posted on
Wed May 23, 2018 9:46 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: sprinkler action

Unfortunately, that's not necessarily going to be accurate since the schedule runtimes for each zone will likely be different than the max zone durations (which is a config setting Indigo uses to make sure that any zone never runs over that threshold).

A plugin can get schedule details, but if it does then it needs to handle all schedule management (on/off/pause/resume, durations, etc.).

As we've said before, Actions are not fully implemented in the IOM (not much really, only enough to allow custom actions for plugins) so getting the schedule details is not available yet. Finishing the IOM is pretty high on the priority list.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed May 23, 2018 10:09 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: sprinkler action

Ok, after rereading your posts and code in the last post, it is actually be closer to correct than I first thought and probably as good as you can get... :lol:

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed May 23, 2018 3:36 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: sprinkler action

reposted the code. this now also works for manual start (non schedule). in the plugin there is an auto off after max time

tried with various settings triggers schedule, manual etc seems to show the right time left

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest