groovy.lang.MissingMethodException: No signature of method: user_app_bptworld_aaDirect_Device_Control_App_4496.getDeviceById() is applicable for argument types: (java.lang.String) values: [9564] on line 34 (method run)
Where did this "sample code" come from? Such a user app method does not exist.
You'll have to find another way to do this, typically by having the user select a specific device from an input (or with some magic you can do in your app if it's a child device of that app).
getDeviceById() is a protected method, meaning it's not available to user apps. It is used by built-in apps. The reason has to do with security, and essentially wanting to force apps to only have access to devices selected by the app user.
If you read those posts, you'll see it's users hypothesizing such a feature. It's unlikely ro happen for user apps, as Hubitat's model is designed to require user consent for all devices used in an app (typically by way of an input).
LLMs are known to make up things that don't exist.
Okay, I understand the security aspect but the question I have is...
I can use MakerAPI, select all devices and then I can control any device from outside of Hubitat anytime.
Does something like this exist within Hubitat? My JSON file lives in the File Manager. I'm loading the file, parsing the data but need to be able to 'link' the device ID to the real device to be able to control it.
So I guess I need to either call makerAPI or create a parent app that uses an input to select all devices, then I can read in the JSON in a child app and match it to a real device shared in the parent... Not a bad idea I guess.
I think you could just use one app, have an input box and instruct the user to just select all devices to authorize. Then in that same app read the JSON file and filter down the device list from the input using the JSON data.
Unless you plan on using multiple instances of the app, then maybe a parent/child would make sense so you only have to select all the devices in one place.
This user was trying to do something similar, but just getting all devices. Looks like they are taking the device ID and forcing it into a setting so the app can access the full device object? Might be worth a look: Obtaining Devices Map
If it is a parent app, then the app can create the children and have access to them. You want access to other already created devices, I take it?
You can make a single multiple input for all device capabilities with capability.* in your app, and then just select them all. Now you have every device in a large array of devices, and you just have to sort through them all and then map them to have a way to access them when needed.
I've done that to a limited extent, to choose all lights in a room in one input, and then map them by label to access them later, but it will cause a headache in a user app to select all devices just to have them available "if needed". If you need it, add it specifically.
Yes, I've used app.updateSetting in the install() method to "hard code" devices into the app without needing the user to select them. Update Setting apparently also creates the setting if it was not there.
I was able to get around the issue of getDeviceById() by making the routine GetDeviceMap() and then just using the returned map with app.updateSetting(). The routine and discussion is available at the topic "Obtaining Devices Map" in "Custom Apps and Drivers/Custom Apps".