I think $currentEventDeviceIndex is broke as it relates to multiple device if check

For some reason $currentEventDeviceIndex is not being filled in ....it should be right?
Vacuums has 3 devices
image

Why would there be an index even available? You are not in a for each loop, so there is no current index. Even in a for each, I've never seen an option for $currentEventDeviceIndex, and in a for each loop you are not working with an event at all, you are just iterating through devices.

Why would you need an index at all when you already have the device you need from $currentEventDevice?

Edit: Instead of trying to store the index of the device in your device list as an integer, as you are trying to do, just make a new "device" variable called lastCurrentEventDevice and assign it the $currentEventDevice. Then you have that device saved as a device reference, and you can get the device to send commands to it, instead of finding the device by what index it is in you device list.

Im trying to save a start time in an array and I needed a way to index into that array.
Why would an index be available? vacuums is an array with 3 elements, Dobbie was the 2nd vacuum in that array so I was expecting to be returned a 1 (0 based).
I understand chatGPT is wrong plenty but this is what is says
image

You know that the arrays are really maps? Numerical indices are just keys. You can use the device name as the key when storring in the array, instead of using a numerical index at all.

There is no index in your "any" device event subscription. It is more like an Or condition, if any of them send an event, it triggers, and then you use $currentEventDevice to find which one sent the event. There is only one event, it is not iterating through the devices in you device list at all to have an index.

Also see my edit on my post above. That may not apply since you want to store in an array, so you are saving a name, not a device as a key in the array.

ohhhhhh ..... I can use the device as an index....sorry very slow... Let me try that..
thank you!!!!

Summary

Yup, see my edit that you cannot use spaces for the key if you want to pull the value back out using the key name.

Scratch that, you can just put brackets around a key with spaces to retrieve it.

Hey, I just learned something, or I may have just forgotten it. You can retrieve a key with spaces, you just need to put brackets around the key name in the index field on the task you are pulling it for.

So you do not need to bother with the extra variable and the replace characters step.

I haven't used Webcore much lately, as I moved all my pistons into custom groovy apps, but I used to have like 200 pistons running everything.

2 Likes