Setting up Global variable using $Sunset +/- offsets


#1

1) Give a description of the problem
I have a number of pistons that control various evening lights. The start times are based on offsets from $sunset. The end times are based on specific times. The pistons are specifically written with the start/stop timing so they work together - which I ‘hard coded’ into each piston. Again, that all works. However, If I decide to change one witout mentally taking ionto account the others, thngs may get jumbled. What I’m now trying to do is set two global variables - PMOn and PMOff and then use those global variables in each piston as base times that I add or subtract offsets (in minutes). This would allow me to change a global variable and all of the pistons would automatically move in unison with that change - without having to modify each piston while mentally keeping the timing of each in mind.

I can handle creation of the @PMOff variable since the PMOff times are all based on specific times and not a system variable. I’m having trouble creating the @PMOn global variable. I attempted to use:
addMinutes($sunset, -x) in the expression section of the global variable setup for a ‘time’ type variable, but the expression disappears once the global variable settings are saved. So, I’m sure I’m doing something wrong. Here’s the table of my pistons showing the current and new times global variables names and offsets, etc.

So, the specific issue I’m having is creating the global variable @PMOn using the expression addMinutes($sunset, -x) so I can use it in the other pistons. I’ve figured everything else out.

image

2) What is the expected behavior?
See above

3) What is happening/not happening?
Pistons are working as is. I want to move to the next level and introduce cross-piston flexibility.(i.e., change a global variable (or two) to move start/stop times - while keeping same relative timing between all pistons.

4) Post a Green Snapshot of the pistonimage
This is just one of the pistons (probably the simplest one) that I’m talking about

5) Attach any logs (From ST IDE and by turning logging level to Full)
Not needed


#2

As you’ve noted, despite the presence of an expression field in the create global variable dialog, expressions cannot be saved there. I suspect this is inherent to the nature of global variables, but it’s possibly an as-yet undeveloped area of webCoRE.

I would either create a separate piston or add a timer event to an existing piston to set the global variable on a daily basis.

Every 1 day at Midnight
set variable @PMOn = (addMinutes($sunset, -10)
End Every


#3

Thanks! I couldn’t figure out why (but should have been able to) the expressions I entered into the Global Variable dialog were disappearing. Thanks for that insight! I’ve written the daily global variable calculation piston (it works fine) and have now started modifying all of the affected pistons.


#4

I just want to tip my hat to @lflorack. Beautiful spreadsheet you have there…
(I do something very similar)

I was especially impressed with your staggering of times.
Very professional to keep network congestion to a minimum.


#5

Thank you very much. As an old IT Manager and Project Manager, laying things out in a spreadsheet is something I always do. They help me see things that I’d miss and plan for better results.

Again, thank you. I think this comes from two places. The first is my background (see above) that causes me to always be concerned for taxing resources. The second is that I started out in Home Automation with X10. X10 wasn’t fond of executing multiple commands simultaneously or even close together. So, I got in the habit of time-spacing events as much as possible. (There’s also a third reason… I’m anal :wink:)


#6

Just to show how detailed (anal) I get with spreadsheets when I’m working on a project, here’s the final version of my spreadsheet. it’s been updated and expanded - because as I said, I see things better once they’re in a spreadsheet:

BTW, this project is now complete. I now have the ability to change my night schedules in the (15) affected pistons by just modifying one or both of the new global variables.


#7

This was my path as well. I’ve had a SmartHome since 2001


#8

I @iflorack
i’m fairly new to webcore and don’t have a great understanding. However i have the same problem as you did. are you able t osupply your latest piston code so i can unpick it and adapt to my circumstance please. Unfortunately i cant get my head around the thread above. Kind regards…


#9

Please correct me if I am wrong, but I believe the piston above is NOT meant to be imported or shared… It was meant as an example, that global variables cannot store Expressions(only the results of expressions)


#10

@WCmore is correct. This thread was exploring the use of @Global variables and the possibility of them storing expressions themselves (they can’t - only results are able to be stored). Further, the piston I posted was just an example for discussion of those facts. This thread is actually a discussion regarding the project I was working on to redo my (15) evening lighting pistons so they are based on variables and not 'hard coded ’ with specific times. In the end, I accomplished that with a couple of global variables (@PMStart & @PMStop) - which are calculated daily in a seperate piston, and then I calculate all of the start/stop times as offsets from those two variables in the individual pistons. (See the most recent spreadsheet/matrix above).

If you have questions about any of that, I can try to expand on the discussion and spreadsheets shown above. In other words, when you said, “i have the same problem as you did.”, what problem are you having?


#11

Hi, thanks for your response. Basically I want a global variable of sunset plus a certain amount of minutes, however I want to adjust the amount as and when necessary to it affects all pistons the same. I can’t quite work out how you’ve achieved this due to my naivety and lack of webcore experience. I suppose I can’t get my head around what @bthrock means above with:

Every 1 day at Midnight
set variable @PMOn = (addMinutes($sunset, -10)
End Every

I guess I’m trying to understand how the above looks in a piston…

Hope you can simplify for me please. Thanks in advance


#12

Oh, also if you can simplify your (@PMStart & @PMStop) piston, perhaps I can try to create my own. Thanks in advance…


#13

Just so you are aware before heading down this path…

Changing the time in a global will NOT change the times those pistons will fire next!

(that sentence is worth reading twice)


To say this another way, changing a global is not seen by ANY piston until after they run again.

  • Each piston continues on the old schedule (even after a @global change)
  • When the previous time occurs, the piston will execute & fail (since the time has changed)
  • That one piston will finally see the new global time
  • That one piston will schedule the next wakeup accordingly (likely 24 hours later)

Each piston has to go thru this process anytime you change the global.

Essentially, this means every single piston that refers to that global has to fire once at the old time (or using a pseudo-trigger) before it will see the new time.

When we deal with sunrise/sunset, it often takes over 24 hours for your piston to see the new time. (after one failed execution)


Note:

If you do decide to tackle this, please start a new thread, so we are not piggy backing on @lflorack’s thread.


#14

I’ll provide my current Global Variable Calculation Piston and an example of one of the other nightly pistons it feeds - since it would be a continuation of the discussion in this thread. However, if you’d like to continue further regarding your needs and questions, I’d recommend that you start a new message thread and we can continue your discussion there. Tag me in the new mesage so I can easily find it and respond.

Here’s my piston that calculates some of my Global Variables:

…and here’s an example of where I use the global variables:

Again, if you’d like to continue with a further discussion regarding your needs and any questions, start a new message and tag me so I can easily find it and respond.

Lee


Sunset offset global variable
#15

Thanks so much Lee, that’s very kind and most helpful. Best regards