I’ve tried to research this for a number of hours now and I’m just coming up blank. I got a lot of pieces and parts, but I think I’m still missing something and I just can’t seem to get it all together.
I’m trying to write a new SmartApp that will be triggered when a user turns on a virtual on/off tile. I could write the app with the user manually creating the tile, but I’d like to do it via a virtual child device. Unfortunately I’m just not getting how it all works.
I’ve read the documentation but that seems more geared towards LAN devices.
So, the specific questions I guess are:
1.) Can this app work? That is, can I create a virtual device AND subscribe to that device as my trigger for when to run the app?
2.) What’s the command to create a child device? How is this done? Is it it’s own procedure?
3.) How to I specify the name of this device so that the user can fine/use it later?
Sorry, I know this question has come up before and I tried to read previous threads to figure it out, but I’m just not getting it.
I did see those before, but they didn’t help so much, at least the first time. I looked again at Switch Mania, specifically the “sub apps” that actually do the creating and I think I might have found something.
There’s a link in the initialize part of virtual switch creator that looks like this:
So in theory, could I put that line in the initialize procedure and then AFTER that, subscribe to when that device was turned on?
If so, can we run down the extra data here so I know what it is?
“smartthings” = The library to look for the type?
“Momentary Button Tile” = the device type
deviceID = ???
null = ???
[label: switchLabel] = presumably the internal name of this device. This is what I’m going to subscribe too in my next line, yes?
Where do I give the device a “friendly” name so that the user knows what to look for?
The problem seems to be that when that line runs it isn’t seeing the text I entered when I setup the app and just putting ‘null’ for the name and label, which crashes the app. And ideas?
The child app for SwitchMania is just Eric Roberts’ “Virtual On/Off Switch Creator” app (with a few edits to make it a child app and to allow for Momentary Switches). Search for his app in the IDE templates.
Thanks for all your help on this guys. I’m still struggling with this app but I’m not sure why. I’m feel frustrated honestly at this point and the ‘child device’ is only part of it.
I’m basically trying to re-create my Goodnight Ubi app but set it up for any TTS device and refine it to have better options and use “pages” in the preferences section.
But I seem to be failing miserably. I coded everything and it saves without issue (yeah!). I can install it in the simulator using the child device and it actually creates a device (yeah!) but here’s the problem: None of my physical devices show up in the simulator so I can’t really test it in the simulator to see if it works.
Interestingly, if I remove the pages and just put in a bunch of sections in the prefs area … the old way of doing things, then my real devices show up, but when I try to install I just a flood of errors saying all kinds of crap about unacceptable values, but no references to lines.
When I install it on my phone, it doesn’t work… it doesn’t create the child device in my device list at all.
I finally made a version that that uses an externally created virtual device, and that seemed to work… except it wasn’t sending TTS to my tablet… so I’ve got problems all over the place and not much of an idea how to tackle them.
What you have to do, is to have Live Logging running when you attempt to install it on the mobile app. Then you will see the error message, and hopefully a line number. There’s some little detail you’re missing. Just work forward from the beginning of the install process of the app. Put log.debug messages in the dynamic pages as needed to see where it’s falling down, and on what values it’s missing, etc.
Code debugging 101 to the rescue. log.debug is your friend, even for dynamic pages!
I’ve abandon the pages (for now) to get the rest working. I’ve got just about everything going. Next step to tackle: Letting the user set the name of the virtual childDevice I’m creating.
I looked through you Lutron app and I see that is has something to do with settings.find.
Can you help with the syntax here? I’m requesting buttonName as a text variable earlier. If I want to use the variable buttonLabel in my childDevice call I’m thinking the command will be something like this:
Settings of course is the array of data created automatically when a SmartApp is initialized.
Settings.find scrolls through the items in the array.
“it” is the individual items in the array.
it.key is the key record for each item. When it finds an item with the key record equal to buttonName (that’s what I called my variable), it assigns that value to “buttonLabel.”
Then in the childDevice creation process I’ll use buttonLabel.value as the label part.
Well, after tinkering forever and playing with settings, I think I finally got it all worked out…
…only to find out that Amazon Echo apparently can’t see virtual child devices. ARGH!!
This whole app was to be used with Echo so that’s a big fail. Well, not a total fail cause I can still used non-child virtual devices. And I at least learned (sorta) how to create child devices so if I need 'em for a future project I’ll know how to do it, or at least I’ll know how to get started doing it.
I did run the rediscovery, but no… I kinda forgot that I’d have to authorize 'em first in the echo app. Welp, looks like I’ve got some more work to do tonight.
(Part of me was almost happy that when the childDevice didn’t show up in Echo. Using the childDevice is a lot more elegant method for the end user, but man is it a pain programming-wise to get it to play nice… at least it has been for me.)