Global Variables?


#1

This might sound dumb, but can I set a global variable that houses the time for sunset-30 and sunrise+30? In a lot of my pistons I started using Time > Preset > Sunset/Sunrise > Offset, but it would be nice if I could just set this once, then use it across all of my pistons.

When trying to set a global variable with an expression, it looks like it’s showing a value of 6:00:00PM instead of sunset/sunrise +/- 30. The expression I’m using is addMinutes($sunset, -30) and addMinutes($sunrise, 30). What am I doing wrong? :slight_smile:


#2

Are you trying to make various pistons start at sunset and sun rise?


#3

Yes. For example, I have three pistons I’m trying to control with sunset-30 and sunrise+30.

Piston 1: Turns on front porch light and back door light to 10% at sunset-30
Piston 2: Changes back door light from 10% to 80% if the back door or garage door opens.
Piston 3: Does the same as Piston 2, but with some color changing as well.

I know I could combine these all into on piston, but for complexity sake and learning how things work… 3 pistons are easier. Instead of having to set local variables in each piston or use sunset/sunrise time function with offset, I thought it would be easier to just have two global variables set with sunset-30 and sunrise+30. :slight_smile:


#4

Try this.
This triggers at the time. And then calls the pistons. Create a separate piston for each


#5

Maybe this will make more sense. Here is an example of one of my pistons. Instead of setting the same local variable in multiple pistons, I was trying to value one set of global variables to be used across all pistons, not necessarily to make them execute pistons.


#6

For whatever reason setting global sets to 6;00 pm. However this sets correctly. Give it a try


#7

Nevermind that. Set your sunset like this

Set global variable = Time(addMinutes({$sunset},30))

You need to define that in a piston run though. It won’t set via expression directly to the global variable. For whatever reason


#8

Ahhhh… That’s what I was wondering. Yeah, I don’t really want a piston to set a global variable. haha. I suppose I’ll just deal with setting local. Not that hard to copy/paste… was just hoping for a global situation. Thanks for your help!


#9

You can pass a local variable to other pistons, kind of like global variables using $args. I just started playing with them. Kind of handy, this might be an option. Not sure


#10

Recently pistons using a global variable as a condition no longer register the correct state of the variable when that variable changes. This has been the case since the latest update. Anyone have any suggestions?


#11

Did this start happening with the introduction of SUPER @@ global vars?
If so, Adrian may want to be alerted…

Thanks
J


#12

Using the “Always Subscribe” method may have fixed the issue. I’ll have to do more testing to see for sure.