How can I access a variable in a smartapp to enable me to change it externally? What I’m trying to do is change a setpoint that is normally entered from a presence page, but do it from say a core piston based on other conditions. I don’t mind modifying the smartapp code, but I can’t figure out how to expose the variable.
Though I don’t have the answer I do look forward to one. A general conversation around variables can be found here: Variables 101
Save it to state and use that state instead of the settings.You cannot access the state from an external source, but you can alwys check the state and update it accordingly by passing back and fourth.
I presume you mean “preference page”.
Don’t think of them as “variable”, but rather Attributes.
SmartThings is rather Object-Oriented, which means you shouldn’t be changing an Object’s data without using its “interfaces”. Devices and SmartApps are Object Instances.
SmartApps don’t provide a direct API (in general, though they can expose web REST-API endpoints…).
Ideally run Commands of the Device Type Handlers to set their Attributes, which in turn can trigger Event Subscriptions by SmartApps which read those Attributes.
I just posted a question in another thread about something nearly identical. Can CoRE change a devices attribute directly? I want to get the value of an attribute, change it, do something then set it back to its original. Can that be done without a smartapp??
If I understand correctly, you want to change the on status to off, without actually sending a command? That is not possible even with a smart app…
CoRE is a SmartApp.
Perhaps CoRE can change a Device Instance Attribute “directly”, but it should not.
Attributes of an Object (such as the state of a Device), should manipulated only by: (a) the external factors on the platform … i.e., the physical hardware; (b) the GUI Tiles for the Device; and/or © the Commands of the Device Type Handler.
This is Object-Oriented 101 fundamental concepts here, buddy.
I guess the better question is:
What are you really trying to accomplish? The experts here can give you a better solution that may be in an entirely different direction than you are “thinking”.
CoRE can change a device attribute. It does not do it directly (via SendEvent) - it uses commands that do it. The right way it has a list of all standard commands with their respective attribute that gets changed and the value they are changed to. Therefore, when you attempt to change a switch attribute to on, CoRE will actually invoke on().
Wow, not really sure how to interpret your response. I am going to assume you were trying to be helpful, but it certainly come off otherwise. I realize I didn’t offer much information so I apologize. I maybe I’m using the term attribute wrong. Basically I have a device a virtual dimmer switch that has a user set preference/attribute/variable, ramp rate. I want to for example set it to 1 minute turn on the light over that one minute then set it back to the default (0 for instance). That’s it. I can certainly add a custom method in the device handler to do it and maybe that’s the approach I need to take. I don’t really know. I do appreciate your assistance/advice.
Thanks @ady264. Appreciate your polite input. Like I mentioned I may be using the wrong term and attribute isn’t appropriate. It’s basically just a user preference variable for how fast a light turns on. What CoRE option does that? setVariable? Thanks a lot!!
If it is a preference input in the settings page of the device, then no, SmartApps cannot change those. They can only be modified by the user using the device UI.
Yah… Sorry; I admit it sounds harsh. I really just am trying to encourage people to read the manual and understand the terminology and architecture of the platform before cross-posting questions to multiple Topics.
Been a busy day and I often get the feeling far too many folks are on here who haven’t even skimmed the Developer Documentation.
Well it can be whatever I want. I haven’t created it yet. Lol. It my device type to build this functionality in however I want. I guess I’m just trying to figure out how to build it so that a smartapp such as CoRE can manipulate it.
I can appreciate that. I can assure you I have spent countless hours of my life in those docs working on various projects. This was just something a little different that I wasn’t sure how to approach. I also didn’t really mean to cross post. I posted on CoRE because I thought it was just applicable but then saw that other post trying to do something very similar so I thought I’d ask there. My mistake. I also should have provided more information. Being vague didn’t really help my cause. I totally get it and appreciate your response. Thanks!!
You can always create a custom attribute and a command to control it and then have CoRE or other smart apps that can access that custom command control the attribute. Then that attribute can alrer the behavior of other commands in that device, if that’s what you’re after
Yep I think that’s precisely what I’m after. I just happened across the below thread which seems to discuss it in pretty good detail. I think that’s the route I’ll go. Again thank you so much for your assistance!!