How can I record the state of a group of devices?


#1

1) Give a description of the problem
I need to record the state of a group of devices (in a variable) before I turn them on, then return all devices to their previous state when they get ‘turned off’.

Can this easily be done?


#2

Click the x2 button at the top of the piston editor to display the ‘define’ section at the top of the piston code (this is where you can add a variable)

Create two variables of type device and give them names (say varOn and varOff), do not give it a value.

Create the rest of the piston similar to this:

If something happens
Then

If lights x, y or z are on
(Save matching devices to variable (varOn)
(Save Non-matching devices to variable (varOff)
End if

With lights x, y and z
Turn on
Do other stuff
end with

End if

If something else happens
Then

with (varOn)
turn on
end with

with (varOff)
turn off
end with

end if


#3

You can also save to the global store if triggering action is likely to repeat during the piston, which would override the variable values.

I’ll knock up an example.


#4

Here is and example of the first method (using local variables):


#5

And here is an example using the local store:


#6

Whoa. That’s super cool. What exactly is local store (I swear I searched the wiki first!)


#7

And mine doesn’t seem to be working. I’m using a button to toggle this stuff…

I get the following error in the log:

11/2/2017, 7:23:39 PM +709ms
+1ms ╔Received event [Xiaomi Button].button = pushed with a delay of 383ms
+126ms ║RunTime Analysis CS > 16ms > PS > 42ms > PE > 68ms > CE
+136ms ║Runtime (40746 bytes) successfully initialized in 42ms (v0.2.0fb.20171026) (134ms)
+137ms ║╔Execution stage started
+148ms ║║Comparison (enum) pushed gets (string) pushed = true (1ms)
+150ms ║║Cancelling condition #4’s schedules…
+150ms ║║Condition #4 evaluated true (7ms)
+154ms ║║Comparison (boolean) true is (boolean) false = false (1ms)
+155ms ║║Condition #7 evaluated false (4ms)
+156ms ║║Condition group #1 evaluated false (state did not change) (13ms)
+162ms ║║Comparison (enum) pushed gets (string) pushed = true (1ms)
+163ms ║║Condition #10 evaluated true (6ms)
+167ms ║║Comparison (boolean) true is (boolean) true = true (1ms)
+168ms ║║Condition #11 evaluated true (4ms)
+169ms ║║Condition group #6 evaluated true (state did not change) (11ms)
+170ms ║║Cancelling statement #8’s schedules…
+361ms ║║An error occurred while executing the event: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.call() is applicable for argument types: (null) values: [null] Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure), take(int)
+366ms ║╚Execution stage complete. (228ms)
+373ms ╚Event processed successfully (373ms)


#8

Try setting the variable after saving / restoring the state, not before.

By doing it before it changes the condition and cancels the execution.

Local store is basically a local variable but specifically designed for saving device states with the option to label into containers and prevent overriding by repeat events such as motion.


#9

I’m still getting that same error. In fact, it occurs as soon as I save the piston.

║An error occurred while executing the event: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.call() is applicable for argument types: (null) values: [null] Possible solutions: wait(), any(), wait(long), any(groovy.lang.Closure), each(groovy.lang.Closure), each(groovy.lang.Closure)


#10

Will you bite if I bump this?


#11

Post a screenshot of you’re latest attempt.


#12


#13

The structure of your piston is a bit odd (using else if) but I don’t think that’s the issue here…

For starters, try formatting as follows:

If button 1 is pressed
Then

If alarm is false
Save states
Set alarm = true
End if

If alarm is true
Restore states
Set alarm = false
End if

End if

But there may be a bigger issue at play here, you’re the second person today to mention the exact same error message appearing immediately after saving a piston. The other mention was via PM.

@ady624, I’ll invite you to join the PM reporting the other instance of this error, it’s on the ST forum… might be a bug?


#14

I get the same error.


#15

if you save it to a global store or a named store, do you still get the same error?


#16

Time to fall on my sword. It turns out this was all my fault. I added some extra devices to this piston, so I changed alarmLights to alarmDevices. But I missed changing that in the local store commands. o.O

However, it’s still not working. It seems that it’s not reacting to the button being pressed. I can see it pressed in Live Logging, but it never registers in the webcore logging.


#17

That’s good… the not responding to button press thing is a different issue.

Daylight saving changes by ST messed up WC… @ady624 had allowed for it but ST had also put in precautions which clashed with the WC precautions.

Anyway… it’s fixed now so upgrade to the latest version of WC and you should be in business.

https://community.webcore.co/t/pistons-stop-to-work/2159


#18

That was it! This is what I ended up with. Thanks!