Hi,
A newbie here, and with my maiden message on the forum. I've had Hubitat Elevation 7 now for a few months, and quite new to groovy also. I've got some programming experience, but for the last 10+ years it's been more of a hobby than profession. Lately I've played some with python and javascript.
I'm working on a custom app (* more about it below), where I have one input to select a capability.switch -kind of device:
input(name: "switch_selector", type: "capability.switch", title: "xxx...", submitOnChange: true, multiple: false, width: 6)
My problem / question:
In my app I would like to save the value (=the devide) of switch_selector away from it, and later on (after many page loads, user clicks and perhaps app hibernations) being able to restore it back into switch_selector. In the mean time switch_selector will have other values loaded into it, user modify them, and the results saved away.
To be concrete, I've tried saving switch_selector into a state variable, and later read / load the value back from state variable. I have managed to save something in a state variable, it looks like a dump of the deviceWrapper values. However, I have not found a way to programmatically modify the value of the switch_selector in any way, at least based on what is shown in UI. I cannot even "empty" it (=unselect any potentially selected device). Instead, switch_selector appears to always remember what was the previous value. This is at least the user interface result.
Maybe saving into a state variable is wrong approach? I tried to understand the childDevice concept, but it didn't appear as the right solution.
Any help is appreciated, for example links to code of apps that have solved this or a very similar issue. My searching skills and keywords have not given me the answers...
(*) About the app, giving context to my motivation: The apps purpose is to control multiple switches. Each switch can be scheduled to turn on and off separately of the other switches. There is a compact overall view of all included switches and their schedules (rather compact in a HTML table). Purpose is to make the overall easy to comprehend on a small mobile screen. Then the schedules and switches can be edited one at a time. I do not want to have many switch selector inputs in the user interface at the same time, it is not necessary, they are not modified very often, they would take up extra space, and on a small mobile screen there is a risk of accidentally altering them, when it was not the purpose.