Input to array / collection?

I like KISS.
And yes RM is very powerful. But the learning curve is pretty steep (no problem there) and the UI can be a bitch if you mess up your rule.

Haha, yes. And I just spent months reworking the UI... The app ui model in general needs a rework...

3 Likes

btw no disrespect for all the great work of course! I mean really, you (and the whole team) are really working hard to help everybody and to improve your product!

It's like you've read my mind (or the few posts I've made wishing for this exact thing). :slight_smile: I'm really impressed with what you've managed to do with RM (and other apps) given the limitations of an app UI structure you more or less weren't responsible for creating, but I've always wondered what would be possible if Hubitat created its own.

Sounds a lot like you're trying to modify my app. :wink: I hope my code is readable to normal humans! If it's what you mentioned in the other thread, I'm almost thinking that what you want might be possible with just RM (it has a "capture" and "restore" feature for dimmers/switches, which you could use before and after changing lights for motion activity/inactivity). Not that there's anything wrong with learning Groovy--as Bruce said, it opens up a lot of possibilities.

Yes, I am rebuilding your app to overcome my difficult desires :crazy_face:. But to be honest I have not looked at your code yet. I decided to start from scratch. Though I have looked at some code of Cobra and some others I came across while searching for answers. And I really don't mind learning Groovy actually. It sort of a trip down memory lane. :joy:

We have some tricks up our sleeve. But I have to say that addressing the RM UI is down on our list a bit. Our focus will be on new-to-HA users, and giving them a smoother path into this fun.

6 Likes

Ok, it's been a while since I got around to go on with Groovy. Though I'm still struggling with the whole array part (List, Collection, Map or whatever they wanna call it).
The solution Bruce gave was fine for making it work on the "input" of things. But on the "output" side it's a hell. So I end up with all kinds of variables called "LevelBulb_1In_the_evening": 90
How would one go through all the different variables names and use the values? It does not make any sense. Well from a Basic point of view maybe... Should we use GOTO line number X also? I thought this was 2019? Where we can use multi-dimensional array's? What make sense to me is having something like: settings["Bulb_1"]["In_the_evening"]["Level"][90]

How do I get that? Or something like that.

Yeah, what you want to create is a data structure to store all of this in one place, a Map would be a good one to use, Maps are great, but you're going to have to study up to make good use of them.
Something like this maybe

["bulb1":["mode":"in the evening","level":"90"]]

Ok, thanks for helping me out here. I've come a little further now!
Running in the next chalange:

actions = ["$a.name":settings[modes].each {}]
log.debug actions["$a.name"].each {}
log.debug actions

This gives:
NULL
[bulb:[evening,day]]

I don't understand why the first log is NULL...

That should probably be

actions["$a.name"].each {log.debug it}

That would also make sense... But that gives nothing... So log.debug isn't even executed.

Which means the first part is wrong: actions["$a.name"].each

someMap.each{} is equivalent to someMap

settings[modes].each {} in your original code is probably not doing what you want unless you have a variable called modes

And I have a feeling that you may need to store the value in the actions map using
actions = [("$a.name") : settings['modes']].

It would really help to see what you get from log.debug settings and what you want your actions map to look like.

That is so true! Cleaned up the code a little :slight_smile:

Ok, so I played around with your other advise, but it did not help unfortunately.

Log.debug actions:
[((test)) (O) virtual switch:[In de avond, In de nacht]]

Log.debug settings:
[motions:[((test)) (I) virtual motion sensor], switches:[((test)) (O) virtual switch], modes_((test)) (O) virtual switch:[In de avond, In de nacht], levelIn de avond:90, levelIn de nacht:40]

I actually found out my problem might be somewhere else... I am trying to use this "actions" list in multiple pages... So I thought it would be a global thing. But it's not. How can I make it global within my app instance?

Store it in state

Was afraid of that... To be continued in a couple of days :slight_smile:

Ok, so I finally had some spare time to dive into this state story... But I'm still missing the big picture about multidimensional array's in Groovy. I come from PHP and I can't get this to make sense to me... I have read so many Google pages by now that I'm getting a little tired of Groovy. Can someone please tell me how this language thinks? I'm not the first one trying to store level values of switches per mode right? I've also looked through code of others but even then I can't make any sense of it. This is what I have now what does NOT work, but IMHO shouldn't be soo hard:

            input name: "switchChoices", type: "capability.switch", title: "Control these Switches", multiple: true, submitOnChange: true, hideWhenEmpty: true
            input name: "switch_by_modes", type: "bool", title: "Use modes for settings?", submitOnChange: true
            if (switch_by_modes == true) {
                input name: "modeChoices", type: "mode", title: "Which modes do you want to set the lights for?", multiple: true, submitOnChange: true, hideWhenEmpty: true
                modeChoices.each { modeName ->
                    state.levels = [modeName]
                    paragraph "Mode: <strong>$modeName</strong>",  style:"margin-top: 1rem; margin-bottom: -0.5rem;"
                    switchChoices.each { switchName ->
                        state.levels["$modeName"] = [switchName]
                        input name: "levelChoices", type: "number", title: "Light: <strong>$switchName</strong><br>Turn on to level:", hideWhenEmpty: true, style: "padding-left: 2rem;"
                        state.levels.["$modeName"]["$switchName"] = levelChoices
                    }
                }
            }

You need to have a study of maps, that's the data structure you're looking for.
I use maps for everything beyond a simple list.

I did that, but I can't get it to work or the manuals / tutorials I'm running into on Google aren't clear enough for me. And most of them don't say anything about multidimensional.

Exactly, i dont beleive there is any such thing, in groovy you have maps and lists, those are your data structures, maps and json are very similar have a look there has well.
You're going to have to architect your structures around those constraints.
A map is a key value pair, think of the key as being a nameable version of an array index, and it's used the same way.