Is it possible to create an endpoint to directly control level of light?

(Tony - SmartThings Unpublished Contributor ) #1

I know I can create a virtual switch that in turn controls a hello home action. But I’m wondering if it’s possible to have an endpoint for a light that accepts a variable X and then sets the light level to X.

Bonus points if you can also direct me to / provide me with example code.


( co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #2

Ummm… I think SmartTiles must do this, since it offers dimmer control on tiles. And it’s open source.

We can dig through the code (or ask Alex).

(Tony - SmartThings Unpublished Contributor ) #3

Thanks Terry. That’s a good recommendation. I’ll take a look.

( co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #4

So the endpoint calls are buried in the script.js; but it isn’t hard to search for the word dimmer…
I should use line numbers, but just do a search on the raw files. Some relevant clips…

    $(".dimmer, .dimmerLight").on('slidestop', function(e) {
    	var level = $(this).find("input").val()
		if ($(this).hasClass("active")) {
			sendCommand($(this).attr("data-type"), $(this).attr("data-device"), "level", level);
		$(this).attr("data-level", level);

Which calls the sendCommand function…

function sendCommand(type, device, command, value) {
	//alert("&type=" + type + "&device=" + device + "&command=" + command + "&value=" + value);
	var access_token = getUrlParameter("access_token");
	var request = { type: type, device: device, command: command, value: value};
	if (access_token) request["access_token"] = access_token;
	$.get("command", request).done(function( data ) {
		//alert( "Data Loaded: " + data);
		if (data.status == "ok") {
	}).fail(function() {

And in the SmartTiles.groovy SmartApp itself, the def command endpoint method:

def command() {
	log.debug "command received with params $params"
	if (disableDashboard || readOnlyMode) return [status: "disabled"]

    def id = params.device
    def type = params.type
    def command = params.command
    def value = params.value

   def device


	} else if (type == "dimmer" || type == "dimmerLight") {
		def deviceSet = (type == "dimmer" ? dimmers : dimmerLights)
		device = deviceSet?.find{ == id}
		if (device) {
			if (command == "toggle") {
				if(device.currentValue('switch') == "on") {
				} else {
					device.setLevel(Math.min((value as Integer) * 10, 99))
			} else if (command == "level") {
				device.setLevel(Math.min((value as Integer) * 10, 99))


In other words … it’s definitely possible; and, indeed, of course, definitely possible to make a “simple” example that doesn’t involve the layers of Javascript required for the rich functionality of SmartTiles. :wink:

Got some chores tomorrow… But maybe I’ll try a very simple skeleton example. I’m sure dozens of Community folks could do it while they are sleeping; but parsing apart some complex code into a simple example is not a bad way to learn. The positive side effect is a better understanding of how SmartTiles is put together!