Webcore - overriding lights with changing variable

Hello, I am trying to have my kitchen lights turn on at 50% when the PIR registers motion. I want 20 minutes of no motion to result in them dropping to 23%. Finally, I would like me telling Alexa to invoke the Routine ‘zz - Brighten Kitchen’ to result in 100% brightness forever (or until I give another command).

At the moment I suspect the variable isn’t being changed because as soon as I bark my order at Alexa, the PIR picks up motion and overrides it back to 50%.

What am I doing wrong? Think my understanding of variables here is somewhat lacking.

Cheers.

image|451x500

In the define - did you set it ‘false’ explicitly or is that just set from the last time the piston was run?

Drop some log lines in there that tell you hat voice override is at the top and bottom of your piston and I think you’ll figure out what’s going on. :wink: I’d also drop a ‘cancel all pending tasks’ into the piston right before you set the voice override to true. - AND, I’m wondering how you’re going to set it back to false again :wink:

1 Like

from WebCoRE Docs:

Local Variables

Local variables are owned by an individual piston. They are unique to each piston and are not shared, so multiple pistons can safely define local variables with the same name.

The Show variables option in the piston editor enables a define block where variables are added. Local variables can have an initial value that is set every time the piston runs. If omitted, any value set to the variable will carry over for use in future executions of the piston.

1 Like

Thanks :+1:t2: I set ‘false’ explicitly hoping it would use that as the default variable, therefore if the ‘ZZ - Brighten Kitchen’ was executed it would change to ‘true’ and allow that to be the only rule the piston would use. Thinking about it now, presumably I need an action to set it back to false once I’m done with my ‘Brighten Kitchen’ routine?

Feel like a right n00b but I can’t figure out how to add log lines to the code?

I typically add restrictions to most of my Pistons with a “Name Room” Automation Virtual Switch. For example, “Kitchen Automation”, “Living Room Automation”, “Downstairs Bathroom Automation”, etc. In my Pistons, I typically have the Restriction, Only If “Name of Room” Automation is On. This way, if I say, Alexa, turn off Day Room Automation, then none of the Pistons in that room work until I turn the Automation Virtual Switch back on.

Of course, I have a Piston to automate that as well! :rofl:

Don’t necessarily give you the answer to your Piston but gives you another way to look at it.

For you:

I would still use the restriction and define a variable “whatever_name”

If “X” Routine executes (this is the routine to turn the lights on 100%)
Then set variable “whatever_name” to true

If “Y” Routine executes (this is the routine to enable the 50% and 20 minutes to 23%)
Then set variable “whatever_name” to false

If PIR changes to active
And
“whatever_name” is false
Then set level to 50%
Wait 20 minutes
Set level to 23%

1 Like

Look under Location as the device, Log to console as the action

1 Like

Thanks for the hints and tips, I’ve learnt a lot in the past 24 hours!

The solution I’ve gone with (after now seeing that the variable rule wasn’t getting changed mid-piston) has been to split the process into multiple pistons for each section and use a global variable that each of those pistons can change depending on the trigger (PIR, routine, etc.). Hopefully I won’t regret this route!

Thanks again.