Piston taking way too much resource


#1

I have a couple of pistons that control my Kitchen skylight blinds based on
a. the time of year and then
b. the amount of sunlight actually hitting the window and the time of day, temp, etc

One of the pistons is for Spring and Fall and the other for Summer. The Spring and Fall piston is number one in my Hubitat use of resources right now and it is not even the time of year where it is triggering!


There must be a simple answer to this but how to I redesign this Piston to take up less resources? I would have thought that he ‘only when’ command would be the first evaluated and if false then not look at any more of the Piston but that is evidently not the case. Is there a way in a piston to just evaluate a single trigger (in my case time of year) and if false do nothing else?


#2

A quick glance at the triggers do indicate a lot of activity. Each temp and illumination change would trigger that piston. Now on how to efficiently code this… not sure, I haven’t gotten to that part yet :slight_smile:


#3

Agreed. Lots of triggers in this. They are kind of needed. Wouldn’t the ‘only when’ command be there to kind of be a master trigger of sorts? Look at that first of if it is not true dont go any further…

It would seem like that would be its job but evidently is not. That is what I need - a master trigger of sorts that does not run the piston when the time of year is not true.


#4

I may be wrong on this but my interpretation of it is it’s just another condition, meaning the triggers will still fire but the piston will look at ‘only when statement’ and proceed only if true.


#5

Taking a wild shot in the dark … How about a master piston that pauses or resumes the piston at each change in seasons?


#6

In looking at the Piston further, you are correct. No lighting bolt next to the ‘Only When’ so a condition not a trigger.

Not such a wild shot in the dark! Actually probably the most elegant solution to this. These two pistons are almost 50% of my Hubitat App activity. Doing that should take that down considerably.

If anyone knows of a a ‘master trigger’ of sorts that would only look at time of year without looking at a all the other triggers in the Piston, please let me know!


#7

Here is a sketch of what I was thinking. There may be more elegant schemes, but I ran quick tests to confirm that it pauses/resumes the pistons as instructed, and then schedules to check again next month.


#8

Here is actually what I did already. Much less elegant and without variables but I think will work fine. I see you have your piston triggering at a point in time every day. My piston below does not do that so I am wondering what WebCore does in terms of when these month and week triggers will run? Midnight or something?
Anyone who knows, let me know!

I


#9

When you open the piston, does anything show up as “Next scheduled:” in the Quick Facts box? Hopefully, it would show the actual “Time is any” that will run next. If not, then Full logging would be good.

My perception of how things ought to work - in any programming - never quite lines up with reality. I have to be simple and explicit, and then test and log details.


#10

Well that’s interesting. I have never even paid attention to the Quick Facts box but it is very helpful. In this case it shows even though there are a few months/weeks triggers, it is never going to run becuase it does not subscribe to any events! I always thought creating a trigger would always run a Piston but evidently not date Triggers.

Changed my piston to run every day at 12:05 am and look at the dates and it should now work:


#11

I like this last approach, but I would also recommend throwing in a small safety net.
(in case there was an issue on the exact day and time of the execution)

For example:

pic

Every day at 12:05am
Do
   IF dayOfYear is between 91 and 93
      Resume PistonX
   END IF
   IF dayOfYear is between 152 and 154
      Pause PistonX
      Resume PistonY
   END IF
   IF dayOfYear is between 251 and 253
      Pause PistonY
      Resume PistonX
   END IF
   IF dayOfYear is between 293 and 295
      Pause PistonX
   END IF
   Log to console = 'Today is day 'dayOfYear
END EVERY

This basically does what your last piston does… but it also attempts to run the following 2 days. This is great in case the first one mis-fired for any reason.

My logic is: It’s better to be a day late, than to have to wait 6 months for it to auto correct itself… and there is no harm done when trying to Pause/Resume a piston that is already in that state.

(One caveat: On Leap Years, it will fire 1 day early)


Pro Tip:

I would also likely move the Pause before the Resume


Side Note:

That Expression in the define section returns a number from 1-366:
formatDateTime($now, 'D')

I grabbed numbers for your example from here.


#12

I agree 100%. Thanks for the detailed Piston as an example. Fancy, schmancy variable you have :smile:

I know with my limited (ie just about zero) coding experience, I am only using something like 5% of WebCore’s capabilities. Nice to see new examples of stuff I can add to my repertoire!