Global Store vs. Local Store


#1

1) Give a description of the problem
I’m trying to understand the global and local stores. I have a piston that gets initiated from Ask Alexa. I run it when my dog needs to go out at night and it sets a bunch of outdoor lights to 100%. I’m capturing the current state of all of those lights before the levels get set to 100%. I have another piston that runs when she comes back inside. I want that piston to restore the level and switch state of all of the lights to what they were before I adjusted the brightness. Where should I capture each light’s attributes? To the local store or to the global store? Can anyone explain the difference? Are there other uses for each store?

2) What is the expected behavior?
(PUT YOUR INFO HERE)

3) What is happening/not happening?
Just looking for a better understanding of the local and global store.

4) Post a Green Snapshot of the pistonimage
(UPLOAD YOUR IMAGE HERE)

5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

Global variables will allow you to access those values from any piston, but if you have a lot of them it may be cleaner to have a single piston in charge of both turning them on and back off, tracking the state in local variables.

There are a number of ways to accomplish that, but one that comes to mind is executing that piston from another and passing in an argument when you want to reset the lights. You could set up the piston to check if $args.reset is provided, otherwise handle the AskAlexa behavior.


#3

So a store is like a pre-defined container where you can store device attributes without having to create individual variables for every attribute you want to capture? And attributes captured to the global store are available to all pistons, but attributes captured to the local store are only available to the piston that captured the attributes to the local store? Am I understanding things correctly?


#4

Yes,
Local Variables - are created in that piston.
It cannot be shared outside that piston without passing it to a global variable.

Global variables - are created in webcore off to the right. They can be update from any piston


#5

Ah, you are referring to the actions to capture and restore attributes from a store. I’m not familiar with what those are used for, time to do some research.


#6

So that seems to follow the same local and global scopes, it doesn’t create variables but rather stores the attributes that you select based on the state container name that you specify.

For convenience you could make a local device variable with all of the physical devices where you want to restore state. Use that variable in an action block to capture the attributes, then restore the same attributes to the same devices at a later time.


#7

That’s what I was looking for. Thanks!


#8

This is what I am trying to solve in a thread I’ve posted


I want to lower the volume of ECHO devices before an ANNOUNCEMENT and restore when announcement is finished. I’m sending announcement to FOUR different devices. Will RESTORE ATTRIBUTES restore multiple devices?

Attaching code for piston that works for ONE device and code that needs to be modified.

Could I use an ARRAY and a WHILE LOOP to send CURRENT LEVEL (before announcement) to variable(s) and restore that level individually? Seems like more code than it needs.

!