Spark Core Projects?

I am planning to use my Spark to detect when a room is empty.

I already own some Philips Hue smart lights and have gotten a pretty nice PHP library setup that I can send simple requests to, such as http://server/hue/flashDesk.php?color=red to flash the desk lamp once with colour red.

I also have XBMC set to dim the lights and perform ambilight functions whilst watching movies and shows. The next thing I want to do is have it so the lights turn off if I am not in that room and turn them on when a person walks in the room, as long as there is nothing currently playing on the XBMC machine.

I plan to do most of the work from my home server, but want to use the Spark to do the motion sense / presence monitoring side of this project.

There is a JSON API in XBMC that I can use to get the current playing status, combining this with the “wifi connected presence sensor” I plan to make the Spark in to I should be able to have lots of fun :slight_smile:

Just need to decide how to do the presence detection, I have a couple of ultrasonic distance sensors left over from an Arduino robotics project that I could poll frequently for changes or I may purchase some new motion sensors.

I have ordered from the next batch of Spark, hopefully I will get it promptly :slight_smile:

edit:

Just did a bit of shopping brought 2 Parallax PIR modules, now i just need to wait for the Spark to arrive, est delivery March 2014

2 Likes

Great tutorial.I just expanded this and now have 4 individual devices setup in SmartThing, connected via the app to Spark Core. The Core is mounted to the Relay Shield. This enables me to control 4 light circuits in my kitchen.. The whole experience of getting this working through SmartThings, proves to be a very nice solution for front end control of your Spark Core by way of a fully configurable App.

A Question Please,

I want to read a spark.function exposed value from the core and place it into the SmartThing App, but can't get the code working, i think the problem is httpGet call and then shifting that data to label value in SmartThing Icon.

Any help would be appreciated

preferences {
input("deviceId", "text", title: "Device ID")
input("token", "text", title: "Access Token")

}

I'm trying to pass the value into ($currentValue) below !!

  // for the UI
metadata {

// tile definitions
tiles {
valueTile("temp_raw", "device.temp_raw", width: 3, height: 3) {
state("temp_raw", label:'Outside{$currentValue}°Temp', unit:"F",
backgroundColors:[color: "#153591"],
)
}
valueTile("temperature", "device.temperature", width: 2, height: 1) {
state("temperature", label:"{$currentValue}°Temp", unit:"F",
backgroundColors:[
[value: 31, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
)
}
standardTile("dryerIcon", "device.dryerIcon", width: 1, height: 1, decoration: "flat") {
state "default", icon:"st.custom.wuk.tstorms", label: "{$temp_raw}"
}

    main "temperature"
  details(["temperature", "temp_raw", "dryerIcon"]
     )

}

 //def temp_raw =50
private put(temp_raw) {
//Spark Core API Call

This is where this first problem is, i think. I may not be calling the variable temp_raw correctly, and i may not be parsing the data correctly to the Icon label (Value Display)**

httpGet "https://api.spark.io/v1/devices/xxx/temp_raw?access_token=xxx, temp_raw",
)
sendEvent( name: "temp_raw", )

}

Yes the problem is the httpGet.

Here is an example on how to get the http content.
httpGet(uri: url) {response -> tempraw = response.data.data}
sendEvent( name: “temp_raw”, value = tempraw)

1 Like

SmartThing won't let me compile this. I'm struggling, have tried 5 dozen different syntax. I must be missing something stupid and simple, so that makes me blind.

It has to be something around the get statement.

('result' is where the value sits in the returned json request)

Any help appreciated.

preferences {
input("deviceId", "text", title: "Device ID")
input("token", "text", title: "Access Token")
}

// for the UI
metadata {
// tile definitions

tiles {
  valueTile("temp_raw", "device.tempraw", width: 3, height: 3) {
  	state("temp_raw", label:'Outside${currentValue}°Temp', unit:"F",
        backgroundColors:[color: "#153591"],
  	)
  }
    valueTile("temperature", "device.temperature", width: 2, height: 1) {
  	state("temperature", label:'${currentValue}°Temp', unit:"F",
  		backgroundColors:[
                [value: 31, color: "#153591"],
                [value: 44, color: "#1e9cbb"],
                [value: 59, color: "#90d2a7"],
                [value: 74, color: "#44b621"],
                [value: 84, color: "#f1d801"],
                [value: 95, color: "#d04e00"],
                [value: 96, color: "#bc2323"]
  		]
  	)
  }
    standardTile("dryerIcon", "device.dryerIcon", width: 1, height: 1, decoration: "flat") {

state "default", icon:"st.custom.wuk.tstorms", label: '${temp_raw}'
}

    main "temperature"
  details(["temperature", "tempraw", "dryerIcon"])

}

//command
def poll() {

    httpGet(uri:"https://api.spark.io/v1/devices/${deviceId}/temp_raw", contentType:"application/json", body: [access_token: token])
    {resp ->
    	(result = resp.data.data) {
        }
    sendEvent(name: "tempraw", value = 'result')

}
}

BusterSpark, I was able to compile with a few mods. Of course, you have to do the testing! Let me know how it goes. I really want to get my Spark to be a “thing” but I haven’t had the time yet. :smile:

/**
 *  SparkTemp
 *
 *  Author: pkourany@hotmail.com
 *  Date: 2014-03-05
 */
preferences {
	input("deviceId", "text", title: "Device ID")
	input("token", "text", title: "Access Token")
}

// for the UI
metadata {
// tile definitions
	simulator {
		// TODO: define status and reply messages here
	}

tiles {
	valueTile("temp_raw", "device.tempraw", width: 3, height: 3) {
		state("temp_raw", label:'Outside${currentValue}°Temp', unit:"F",
        backgroundColors:[color: "#153591"])
	}
    valueTile("temperature", "device.temperature", width: 2, height: 1) {
		state("temperature", label:'${currentValue}°Temp', unit:"F",
			backgroundColors:[
                [value: 31, color: "#153591"],
                [value: 44, color: "#1e9cbb"],
                [value: 59, color: "#90d2a7"],
                [value: 74, color: "#44b621"],
                [value: 84, color: "#f1d801"],
                [value: 95, color: "#d04e00"],
                [value: 96, color: "#bc2323"]
				]
		)
	}
    standardTile("dryerIcon", "device.dryerIcon", width: 1, height: 1, decoration: "flat") {
	state "default", icon:"st.custom.wuk.tstorms", label: '${temp_raw}'
	}

    main "temperature"
	details(["temperature", "tempraw", "dryerIcon"])
	}
}

// parse events into attributes
def parse(String description) { 

}

//command
def poll() {
	log.debug "Executing 'poll'"
    httpGet(uri:"https://api.spark.io/v1/devices/${deviceId}/temp_raw", contentType:"application/json", body: [access_token: token])
    { resp -> (result = resp.data.data) {
        }
    sendEvent(name: "tempraw", value = 'result')
	}
}
1 Like

Spark Firefly

  • A control server (another Spark, a Raspberry Pi, a PC…)
  • Spark Core + RGB LED + IR Sensor + A nice, simple case = Spark Firefly
  • A bunch of Spark Fireflies
  • A house by night
  • Using the control server to manage profiles, enable/disable the sensors at certain periods in the day
  • The Fireflies exchange sensor trigger data with the server, in a collaborative sort of way

What I’m hoping to achieve:

  • Smart light trails around the house, based on my current position
  • No more bumping into things for that midnight snack, or for going to the bathroom at night
1 Like

Hi! I just discovered that you can switch to a developer account by clicking your email account in the upper right corner. Then there is a button to add developer account. You click it and I instantly you get access granted.

I still think you are getting some privileged access because you bought a base station. Here’s my view from the support page, which is the only page I see a SIGN IN and this BUTTON:

BDub, that is correct. You have to have a registered base station to get a developer account and develop stuff.

That doesn’t look like the IDE.
Try this URL https://graph.api.smartthings.com/login/

That works:

But now what? :smile: That other page you link before still doesn’t give me access:
http://graph.api.smartthings.com/ide/devices

Hi dermotos, did you accomplish this project? The only thing that I hate about Lifx is that I always need to have my smartphone with me to control the lights. I would love to switch the bulbs off by just tapping on the regular light switch (just like you mentioned in your post). Would love to hear about the end results of your idea.

Hi Tibursio!

I have completed this project (more or less… is a hobby project ever really finished? :smile:) I switched over to philips hue instead of Lifx however. About a 1/3rd of my lifx lights failed, and I never liked the whites they created. On top of that they had too many empty promises of features and bug fixes that 18 months later didn’t seem to be happening. Switched to Hue and haven’t looked back. Currently have 12 bulbs and growing :wink:

Anyway, my approach was to use a raspberry pi running a node.js server which communicates with the philips hue bridge. Each wall switch has a spark core in it, which maintains a TCP connection with the Pi. I made several switches which are scattered around the house. Some have PIR sensors in them, some have potentiometers for fading brightness and all of them have between 2 and 4 tactile buttons. Each button also has an LED in it, that can be controlled by the raspberry pi. It can be on, off, flashing or breathing. It can also have a max brightness set. This is useful, as it gives feedback of the current mode the lights might be in, or have a gentle breathing light to help find the light switch at night.

Each button supports 3 types of presses. A standard press, a long press and a double press. To keep the functionality easy to remember, the long press and double press are generally overloaded versions of the functionality of the standard press. eg: on the bedside switch, pressing button 1 turns off my bedside lamp. Double pressing it turns off all bedroom lights and long press turns off all house lights (super handy when you’re already in bed!).

It took me a while to get things stable, but they’ve been running 24/7 for probably about 6 weeks now without any issues, so I’m confident i’ve ironed out all the bugs.

One issue I found is that both channels of the TCP connections need to be kept alive by sending data regularly. Both the raspberry Pi and the cores ping each other with a simple keep-alive packet every 30 seconds. I had these pings going one way initially, but ended up with some half-open TCP connections (which were horrible to debug!).

While I was able to directly control the hue with the core, I found having a central controller to be a much better solution. It can make it easier to do more complex actions, and makes it easier to integrate with other systems.

I did get a similar setup working with Lifx, but it was unreliable, like the bulbs.

I plan to upload the code sometime in the next month or so, will post back here when I do :slight_smile:

3 Likes

Sounds like you were ahead of your time on this. Did you ever do it?