Re: Fibaro api

316 views
Skip to first unread message
Message has been deleted

Jarrod Bell

unread,
Apr 11, 2015, 7:01:32 PM4/11/15
to comman...@googlegroups.com
Maybe it needs HTTP/1.1 , not HTTP/1.0 (some services will ignore 1.0 requests).

You also have a slash before '\Authorization' which shouldn't be there.

Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


On 12/04/2015 1:39 am, Pratik Malhotra wrote:

Anyone tried linking Fibaro api with command fusion?


Not able to carry out the first basic get command to turn on a relay. 


http://192.168.1.5/api/callAction?deviceID=168&name=turnOff


I created a command and this is my command value

GET /api/callAction?deviceID=168&name=turnOn HTTP/1.0\x0D\x0AHOST: 192.168.1.5\x0D\x0A\Authorization: Basic YWRtaW46YWRtaW4=\x0D\x0A\x0D\x0A


command: http://i.imgur.com/bofS0mP.png

system properties: http://i.imgur.com/3u5zBHO.png

button properties: http://i.imgur.com/lXWMHLg.png


Don't know what is wrong. Can someone point me in the right direction?

--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Jarrod Bell

unread,
Apr 11, 2015, 10:10:22 PM4/11/15
to comman...@googlegroups.com
All we have is as shown in that gist - that was a simple example to help someone else.


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


On 12/04/2015 11:55 am, Pratik Malhotra wrote:
Thanks Jarrod, removing the slash did it. 

By the way, do you happen to have the sample project for fibaro?

I see that you have the js for feedback from the system. 
Message has been deleted

Jarrod Bell

unread,
Apr 12, 2015, 7:21:05 PM4/12/15
to comman...@googlegroups.com
Not sure, but your value assignment looks incorrect:
var switchstatus = data.properties.value

This should be:
var switchstatus = data.properties[0].value;
or
var switchstatus = data.properties[1].value;
etc

Paste the results into this web service and hit validate to get a clearer understanding of the response:
http://jsonlint.com/

Also, if the value is just true or false, you should use an if statement, not a switch statement.


Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


On 13/04/2015 2:59 am, Pratik Malhotra wrote:
So..I modified some things and got working the basic toggle functionality..here is the updated js

// Map a Fibaro device ID to a join number
// The join number should be prefixed by the join type (a = analog, d = digital, s = serial, etc)
var joinIDMap = {
"168": "d1002",
"1": "a1015",
"45": "a1043",
"23": "a1008"
};
// Eg. doCommand("callAction", 168, "turnOn");
// function doCommand(method, deviceId, speed) {
// CF.request("http://192.168.1.5/api/"+method+"?deviceID="+deviceId+"&name=setValue&arg1="+speed, {"Authorization": "Basic YWRtaW46YWRtaW4="}, processResponse);
// CF.log("Fibaro : to here");
// }

function doCommand(method, deviceId) {
CF.request("http://192.168.1.5/"+method+"/devices?ID="+deviceId, {"Authorization": "Basic YWRtaW46YWRtaW4="}, processResponse);
}

 // function doCommand(deviceId) {
// CF.request("http://192.168.1.5/api/devices?"+deviceId, {"Authorization": "Basic YWRtaW46YWRtaW4="}, processResponse);
// }
function processResponse (status, headers, body) {
if (status == 200) {
var data = JSON.parse(body);
CF.log("Request succeeded (HTTP 200 OK). Body received: " + body);
var switchstatus = data.properties.value
switch (switchstatus)
{
case "true":
CF.request("http://192.168.1.5/api/callAction?deviceID=168&name=turnOff", {"Authorization": "Basic YWRtaW46YWRtaW4="}, callback);
CF.log("Fibaro : Command Send OK, Devices Returned: " + switchstatus);
//CF.setJoin("d123", 0);
break;
case "false":
CF.request("http://192.168.1.5/api/callAction?deviceID=168&name=turnOn", {"Authorization": "Basic YWRtaW46YWRtaW4="}, callback);
CF.log("Fibaro : Command Send OK, Devices Returned: " + switchstatus);
//CF.setJoin("d123", 1);
}
}
else {
CF.log("Fibaro : Command Send ERROR");
}
function callback(status, headers, body) {
if (status == 202) {
// extract information from body here
CF.log("Request succeeded (HTTP 200 OK). Body received: " + body);
}
else {
// an error occurred, display the returned status code
CF.log("Error: returned status code " + status);
}
}
};

As you can see, I tried to update the digital join of the button here but then commented the lines because it caused delay in execution of code. The lights were turning on and off after a short moment's gap. Can you please recommend the best way of updating the status at all times?

Pasting here the json array of the device..the value needed for feedback is xxxx.properties.value (you can find it using "value":"true")

{"id":168,"name":"COB 1","roomID":3,"type":"com.fibaro.binarySwitch","baseType":"com.fibaro.actor","enabled":true,"visible":true,"isPlugin":false,"parentId":167,"remoteGatewayId":0,"interfaces":["light","power","zwave","zwaveAssociation","zwaveConfiguration","zwaveFirmwareUpdate"],"properties":{"parameters":[{"id":1,"lastSetValue":255,"size":1,"value":255},{"id":3,"lastSetValue":0,"size":1,"value":0},{"id":4,"lastSetValue":0,"size":2,"value":0},{"id":5,"lastSetValue":0,"size":2,"value":0},{"id":6,"lastSetValue":0,"size":1,"value":0},{"id":7,"lastSetValue":0,"size":1,"value":0},{"id":13,"lastSetValue":0,"size":1,"value":0},{"id":14,"lastSetValue":1,"size":1,"value":1},{"id":15,"lastSetValue":0,"size":1,"value":0},{"id":16,"lastSetValue":1,"size":1,"value":1},{"id":30,"lastSetValue":0,"size":1,"value":0},{"id":31,"lastSetValue":0,"size":1,"value":0},{"id":32,"lastSetValue":0,"size":1,"value":0},{"id":33,"lastSetValue":0,"size":1,"value":0},{"id":39,"lastSetValue":600,"size":2,"value":600},{"id":40,"lastSetVa lue":0,"size":1,"value":0},{"id":41,"lastSetValue":0,"size":1,"value":0},{"id":42,"lastSetValue":0,"size":1,"value":0},{"id":43,"lastSetValue":0,"size":1,"value":0}],"associationSet":[{"devices":[1],"groupID":1},{"devices":[1],"groupID":2},{"devices":[1],"groupID":3}],"associationView":[{"devices":[1],"groupID":1},{"devices":[1],"groupID":2},{"devices":[1],"groupID":3}],"zwaveCompany":"Fibargroup","zwaveInfo":"3,3,42","zwaveVersion":"2.1","pollingTimeSec":0,"configured":"true","dead":"false","deviceControlType":"2","deviceIcon":"1","emailNotificationID":"0","emailNotificationType":"0","endPointId":"0","isLight":"true","liliOffCommand":"","liliOnCommand":"","log":"","logTemp":"","manufacturer":"","markAsDead":"false","model":"","nodeId":"17","parametersTemplate":"214","power":"9.00","powerConsumption":"9","productInfo":"1,15,2,0,16,10,2,1","pushNotificationID":"0","pushNotificationType":"0","remoteGatewayId":"0","saveLogs":"true","showEnergy":"true","smsNotificationID":"0","smsNotifica tionType":"0","useTemplate":"true","userDescription":"","value":"true"},"actions":{"associationGet":1,"associationSet":2,"getParameter":1,"reconfigure":0,"setParameter":2,"turnOff":0,"turnOn":0,"updateFirmware":1},"created":1428802979,"modified":1428802979,"sortOrder":6}

Jarrod Bell

unread,
Apr 12, 2015, 8:19:36 PM4/12/15
to comman...@googlegroups.com, jar...@commandfusion.com
Sorry my mistaked, data.properties.value is correct, so your if statement should just be:
if (switchstatus) {
 // stuff
} else {
 // other stuff
}

Don't use "true" in quotes, the response is a boolean, not a string, after you parse it using JSON.parse.

Jarrod
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusion+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages