Input to array / collection?

You don't want those square brackets.

Devices.each {a ->
   def myModes = "Modes$a"
   input (name: myModes, type: "mode", multiple: true, title: "Modes for device $a")
   settings[myModes].each {b ->
      input (name: "Level$a$b", type: "number", title: "Level for mode $b")
   }
}

What you are constructing is similar to Dimmer Per Mode in RM, except you are allowing different levels for each device for each mode.

BTW, not to discourage you, but you can do the outcome of this with Scenes Per Mode. In fact, I'd really encourage you to keep going. Groovy is not hard to learn, and it can open up many cool things for you.

Also, notice the shorthand that Groovy allows:

input "Level$a$b, "number", title: "Level for mode $b"

4 Likes

Thank you. I am going on with Groovy. Because I've got a lot of stuff up my sleeves. And a lot I can do with other apps, but some things are either to much work to make (especially with RM) or demands such a combination of apps that I lose oversight of all rules. And there are some things I just can't do at all (get items from Google calendar is also on my to-do list)

BTW I like RM, but it can be a monster to work with.

Before RM, the only option for doing automations was to write your own in Groovy. So it's intent is to allow most automations to be constructed. It has a lot of power, and with that power can come complexity. And complexity is the bane of understanding and hence of things working as expected.

I always encourage KISS.

3 Likes

With great Power comes.. great Confusion.

:slight_smile:

4 Likes

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: