RaZberry + Lifx?

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
janeja
Posts: 2
Joined: 09 Mar 2014 21:04

RaZberry + Lifx?

Post by janeja »

Hi.

Is it possible to use the following API: https://www.npmjs.org/package/lifx with RaZberry?
It would be awesome to use the Lifx bulbs together with Z-way :)
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RaZberry + Lifx?

Post by PoltoS »

Only if you can do it with HTTP requests. But anyway the npm will not run on RaZberry as is - you will need to rewrite the code a bit (not really much)
janeja
Posts: 2
Joined: 09 Mar 2014 21:04

Re: RaZberry + Lifx?

Post by janeja »

How can I send a request from Z-way? I'm trying with xmlhttp, but I cannot create a new xmlhttp object.
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RaZberry + Lifx?

Post by PoltoS »

There is http.request({url: <URL>, method: "POST" | "GET", ...})
Sparkacus
Posts: 24
Joined: 26 Nov 2015 16:19

Re: RaZberry + Lifx?

Post by Sparkacus »

I don't suppose someone could explain how you would go about setting up the http request? - I'm new to programming and z-way :(

I would use the HTTP request app in z-way, but I need to add an authentication header.

Basically I want to POST to:

https://api.lifx.com/v1/lights/SELECTOR/toggle

with the header:

"Authorization: Bearer TOKENID"


I did get this to work using xmlhttp in a browser console and thought I could just port that into the Javascript Code app in z-way, but that fails as I believe the xmlhttp object (maybe I said that wrong) is not available. I believe that object is built into my browser, which is why that works.

I tried to install xmlhttp via npm, but that didn't help.


I then tried the following code, but it doesn't work:

var options = {
url: 'api.lifx.com/v1/lights/SELECTOR/toggle,
port: 443,
method: 'POST',
headers: {
'Authorization': 'Bearer TOKENID'
}
};

http.request(options);



Any suggestions?
Sparkacus
Posts: 24
Joined: 26 Nov 2015 16:19

Re: RaZberry + Lifx?

Post by Sparkacus »

OK I got it to work with:


var options = {
url: 'https://api.lifx.com/v1/lights/SELECTOR/toggle',
method: 'POST',
headers: {
'Authorization': 'Bearer TOKENID'
}
};

http.request(options);





Is the above bad coding? i.e am I supposed to close the request some how?
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: RaZberry + Lifx?

Post by PoltoS »

no, it will close itself.
Sparkacus
Posts: 24
Joined: 26 Nov 2015 16:19

Re: RaZberry + Lifx?

Post by Sparkacus »

Ok great, thanks for that :)


Although this is off topic, I also have a Particle Photon which controls my driveway lights. The problem I had when using the JS code above was that no other z-wave device would work until the request had returned something. My driveway lights dance for 10 seconds, hence my issue.

I found out that I could use command line via javascript using JS system(), so I ended up using curl as I knew I could use the '--max-time' option to force curl into closing the connection after x seconds:


system('curl --max-time 1 https://api.particle.io/v1/devices/DEVICECODE/FUNCTION -d arg=\'ARGUMENT\' -d access_token="ACCESS_TOKEN"');


I could change the code on my Photon to return a value immediately before executing a task (assuming I have the skillz), but I was too lazy to look :)
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: RaZberry + Lifx?

Post by pz1 »

@spartacus
Don't go off topic!! Start a new thread for your new problem.
Post Reply