Hi,
I have Homebridge setup and successfully reading a temperature value from my Photon through homebridge on my phone. Works great!!
I am trying to get the Switch Function working so I can turn on my AC Unit.
I have cloud function on my Photon called" ACStatus" The firmware is all working well and the function can be called with a single 0 or 1 to turn off/on the switch, I have also added the option to have 1=0 as per the example. I have tested this through Particle Dev and it all works fine.
HomeBridge detects the Accessory and it successfully displayed on my iphone as a switch. My config.json is the following
"platform": "Particle",
"name": "Particle Devices",
"access_token": "XXXXXXXXXXXXXXXXX", //omitted for privacy
"cloudurl": "https://api.spark.io/v1/devices/",
"devices": [
{
"accessory": "Airconditioner",
"name": "Air Conditioner",
"deviceid": "XXXXXXX", //omitted for privacy
"type": "LIGHT",
"function_name": "setACStatus",
"args": "0={STATE}"
},
I have tried this with just {STATE} and as above but no differrence in the result. The function in my Photon firmware is
int controlAC (String command) {
//function called by Cloud Function to turn the AC on or OFF
if (command=="on" || command=="1=1" || command == "1") {
turnOnAirCon();
return 1;
}
else if (command=="off" || command=="1=0" || command =="0") {
turnOffAirCon ();
return 0;
}
}
When I select the Switch button on my iphone the following is shown on my screen running homebridge. and the Photon function is not called and the relay is not energised. I have omitted Photon device ID from post.
What am I doing wrong here? Thanks in advance
[12/20/2016, 10:26:22 PM] [Particle Devices] Getting current state...
[12/20/2016, 10:26:22 PM] [Particle Devices] URL: https://api.spark.io/v1/devices/
[12/20/2016, 10:26:22 PM] [Particle Devices] Device ID: xxxxxxxxxxx
[12/20/2016, 10:26:22 PM] [Particle Devices] Calling function: https://api.spark.io/v1/devices/xxxxxxxxxx/setACStatus
IncomingMessage {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: true,
endEmitted: true,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: false,
domain: null,
_events:
{ end: [ [Function: responseOnEnd], [Function], [Function], [Function] ],
close: [ [Function], [Function] ],
data: [Function],
error: [Function] },
_eventsCount: 4,
_maxListeners: undefined,
socket:
TLSSocket {
_tlsOptions:
{ pipe: null,
secureContext: [Object],
isServer: false,
requestCert: true,
rejectUnauthorized: true,
session: <Buffer 30 82 06 f6 02 01 01 02 02 03 03 04 02 c0 2f 04 20 ba cb 52 c4 4f 69 b6 43 19 4d e1 da fd ee 8f fa 4b 56 06 61 32 fb 83 94 c1 d5 54 ff 3d e6 a1 92 04 ... >,
NPNProtocols: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined },
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: null,
npnProtocol: undefined,
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events:
{ close: [Object],
end: [Object],
finish: [Function: onSocketFinish],
_socketEnd: [Function: onSocketEnd],
secure: [Function],
free: [Function: onFree],
agentRemove: [Function: onRemove],
drain: [Function: ondrain],
error: [Function: socketErrorListener] },
_eventsCount: 9,
connecting: false,
_hadError: false,
_handle: null,
_parent: null,
_host: 'api.spark.io',
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: [Object],
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: false,
domain: null,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
needDrain: false,
ending: true,
ended: true,
finished: true,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: true,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: false,
allowHalfOpen: false,
destroyed: true,
_bytesDispatched: 237,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 5,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedHeader: [Object],
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Circular],
connection: [Circular],
_header: 'POST /v1/devices/3xxxxxxxxxx/setACStatus HTTP/1.1\r\nhost: api.spark.io\r\ncontent-type: application/x-www-form-urlencoded\r\ncontent-length: 63\r\nConnection: close\r\n\r\n',
_headers: [Object],
_headerNames: [Object],
_onPendingData: null,
agent: [Object],
socketPath: undefined,
timeout: undefined,
method: 'POST',
path: '/v1/devices/xxxxxxxxxxx/setACStatus',
_ended: true,
parser: null,
res: [Circular] },
read: [Function],
_consuming: true,
_idleNext: null,
_idlePrev: null,
_idleTimeout: -1 },
connection:
TLSSocket {
_tlsOptions:
{ pipe: null,
secureContext: [Object],
isServer: false,
requestCert: true,
rejectUnauthorized: true,
session: <Buffer 30 82 06 f6 02 01 01 02 02 03 03 04 02 c0 2f 04 20 ba cb 52 c4 4f 69 b6 43 19 4d e1 da fd ee 8f fa 4b 56 06 61 32 fb 83 94 c1 d5 54 ff 3d e6 a1 92 04 ... >,
NPNProtocols: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined },
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: null,
npnProtocol: undefined,
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events:
{ close: [Object],
end: [Object],
finish: [Function: onSocketFinish],
_socketEnd: [Function: onSocketEnd],
secure: [Function],
free: [Function: onFree],
agentRemove: [Function: onRemove],
drain: [Function: ondrain],
error: [Function: socketErrorListener] },
_eventsCount: 9,
connecting: false,
_hadError: false,
_handle: null,
_parent: null,
_host: 'api.spark.io',
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: [Object],
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: false,
domain: null,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
needDrain: false,
ending: true,
ended: true,
finished: true,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: true,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: false,
allowHalfOpen: false,
destroyed: true,
_bytesDispatched: 237,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 5,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedHeader: [Object],
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Circular],
connection: [Circular],
_header: 'POST /v1/devices/xxxxxxxxxxxx/setACStatus HTTP/1.1\r\nhost: api.spark.io\r\ncontent-type: application/x-www-form-urlencoded\r\ncontent-length: 63\r\nConnection: close\r\n\r\n',
_headers: [Object],
_headerNames: [Object],
_onPendingData: null,
agent: [Object],
socketPath: undefined,
timeout: undefined,
method: 'POST',
path: '/v1/devices/xxxxxxxxxxxx/setACStatus',
_ended: true,
parser: null,
res: [Circular] },
read: [Function],
_consuming: true,
_idleNext: null,
_idlePrev: null,
_idleTimeout: -1 },
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers:
{ server: 'nginx',
date: 'Tue, 20 Dec 2016 11:26:25 GMT',
'content-type': 'application/json; charset=utf-8',
'content-length': '98',
connection: 'close',
'access-control-allow-origin': '*' },
rawHeaders:
[ 'Server',
'nginx',
'Date',
'Tue, 20 Dec 2016 11:26:25 GMT',
'Content-Type',
'application/json; charset=utf-8',
'Content-Length',
'98',
'Connection',
'close',
'Access-Control-Allow-Origin',
'*' ],
trailers: {},
rawTrailers: [],
upgrade: false,
url: '',
method: null,
statusCode: 200,
statusMessage: 'OK',
client:
TLSSocket {
_tlsOptions:
{ pipe: null,
secureContext: [Object],
isServer: false,
requestCert: true,
rejectUnauthorized: true,
session: <Buffer 30 82 06 f6 02 01 01 02 02 03 03 04 02 c0 2f 04 20 ba cb 52 c4 4f 69 b6 43 19 4d e1 da fd ee 8f fa 4b 56 06 61 32 fb 83 94 c1 d5 54 ff 3d e6 a1 92 04 ... >,
NPNProtocols: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined },
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: null,
npnProtocol: undefined,
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events:
{ close: [Object],
end: [Object],
finish: [Function: onSocketFinish],
_socketEnd: [Function: onSocketEnd],
secure: [Function],
free: [Function: onFree],
agentRemove: [Function: onRemove],
drain: [Function: ondrain],
error: [Function: socketErrorListener] },
_eventsCount: 9,
connecting: false,
_hadError: false,
_handle: null,
_parent: null,
_host: 'api.spark.io',
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: [Object],
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: false,
domain: null,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
needDrain: false,
ending: true,
ended: true,
finished: true,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: true,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: false,
allowHalfOpen: false,
destroyed: true,
_bytesDispatched: 237,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 5,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedHeader: [Object],
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Circular],
connection: [Circular],
_header: 'POST /v1/devices/xxxxxxxxxxxx/setACStatus HTTP/1.1\r\nhost: api.spark.io\r\ncontent-type: application/x-www-form-urlencoded\r\ncontent-length: 63\r\nConnection: close\r\n\r\n',
_headers: [Object],
_headerNames: [Object],
_onPendingData: null,
agent: [Object],
socketPath: undefined,
timeout: undefined,
method: 'POST',
path: '/v1/devices/xxxxxxxxxxxx/setACStatus',
_ended: true,
parser: null,
res: [Circular] },
read: [Function],
_consuming: true,
_idleNext: null,
_idlePrev: null,
_idleTimeout: -1 },
_consuming: true,
_dumped: false,
req:
ClientRequest {
domain: null,
_events:
{ socket: [Object],
response: [Function: bound ],
error: [Function: bound ],
drain: [Function],
prefinish: [Function: requestOnPrefinish] },
_eventsCount: 5,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedHeader: { 'content-length': false },
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket:
TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: null,
npnProtocol: undefined,
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object],
_eventsCount: 9,
connecting: false,
_hadError: false,
_handle: null,
_parent: null,
_host: 'api.spark.io',
_readableState: [Object],
readable: false,
domain: null,
_maxListeners: undefined,
_writableState: [Object],
writable: false,
allowHalfOpen: false,
destroyed: true,
_bytesDispatched: 237,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular],
read: [Function],
_consuming: true,
_idleNext: null,
_idlePrev: null,
_idleTimeout: -1 },
connection:
TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: null,
npnProtocol: undefined,
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object],
_eventsCount: 9,
connecting: false,
_hadError: false,
_handle: null,
_parent: null,
_host: 'api.spark.io',
_readableState: [Object],
readable: false,
domain: null,
_maxListeners: undefined,
_writableState: [Object],
writable: false,
allowHalfOpen: false,
destroyed: true,
_bytesDispatched: 237,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: null,
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular],
read: [Function],
_consuming: true,
_idleNext: null,
_idlePrev: null,
_idleTimeout: -1 },
_header: 'POST /v1/devices/xxxxxxxxxxxx/setACStatus HTTP/1.1\r\nhost: api.spark.io\r\ncontent-type: application/x-www-form-urlencoded\r\ncontent-length: 63\r\nConnection: close\r\n\r\n',
_headers:
{ host: 'api.spark.io',
'content-type': 'application/x-www-form-urlencoded',
'content-length': 63 },
_headerNames:
{ host: 'host',
'content-type': 'content-type',
'content-length': 'content-length' },
_onPendingData: null,
agent:
Agent {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object],
requests: {},
sockets: [Object],
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: [Object] },
socketPath: undefined,
timeout: undefined,
method: 'POST',
path: '/v1/devices/xxxxxxxxxxxx/setACStatus',
_ended: true,
parser: null,
res: [Circular] },
request:
Request {
domain: null,
_events:
{ error: [Function: bound ],
complete: [Function: bound ],
pipe: [Function],
data: [Function],
end: [Function] },
_eventsCount: 5,
_maxListeners: undefined,
uri:
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'api.spark.io',
port: 443,
hostname: 'api.spark.io',
hash: null,
search: null,
query: null,
pathname: '/v1/devices/xxxxxxxxxxxx/setACStatus',
path: '/v1/devices/xxxxxxxxxxxx/setACStatus',
href: 'https://api.spark.io/v1/devices/xxxxxxxxxxxx/setACStatus' },
callback: [Function],
method: 'POST',
readable: true,
writable: true,
explicitMethod: true,
_qs:
Querystring {
request: [Circular],
lib: [Object],
useQuerystring: undefined,
parseOptions: {},
stringifyOptions: {} },
_auth:
Auth {
request: [Circular],
hasAuth: false,
sentAuth: false,
bearerToken: null,
user: null,
pass: null },
_oauth: OAuth { request: [Circular], params: null },
_multipart:
Multipart {
request: [Circular],
boundary: 'db0c9677-6dbb-4cd0-8684-f78ff6545cf5',
chunked: false,
body: null },
_redirect:
Redirect {
request: [Circular],
followRedirect: true,
followRedirects: true,
followAllRedirects: false,
allowRedirect: [Function],
maxRedirects: 10,
redirects: [],
redirectsFollowed: 0,
removeRefererHeader: false },
_tunnel:
Tunnel {
request: [Circular],
proxyHeaderWhiteList: [Object],
proxyHeaderExclusiveList: [] },
headers:
{ 'content-type': 'application/x-www-form-urlencoded',
'content-length': 63 },
setHeader: [Function],
hasHeader: [Function],
getHeader: [Function],
removeHeader: [Function],
localAddress: undefined,
pool: {},
dests: [],
__isRequestRequest: true,
_callback: [Function],
proxy: null,
tunnel: true,
setHost: true,
originalCookieHeader: undefined,
_disableCookies: true,
_jar: undefined,
port: 443,
host: 'api.spark.io',
body: 'access_token=xxxxxxxxxxxx&args=1%7D',
path: '/v1/devices/xxxxxxxxxxxx7/setACStatus',
httpModule:
{ Server: [Object],
createServer: [Function],
globalAgent: [Object],
Agent: [Object],
request: [Function],
get: [Function] },
agentClass: { [Function: Agent] super_: [Object] },
agent:
Agent {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object],
requests: {},
sockets: [Object],
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
maxCachedSessions: 100,
_sessionCache: [Object] },
_started: true,
href: 'https://api.spark.io/v1/devices/xxxxxxxxxxxx/setACStatus',
req:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 5,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedHeader: [Object],
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Object],
connection: [Object],
_header: 'POST /v1/devices/xxxxxxxxxxxx/setACStatus HTTP/1.1\r\nhost: api.spark.io\r\ncontent-type: application/x-www-form-urlencoded\r\ncontent-length: 63\r\nConnection: close\r\n\r\n',
_headers: [Object],
_headerNames: [Object],
_onPendingData: null,
agent: [Object],
socketPath: undefined,
timeout: undefined,
method: 'POST',
path: '/v1/devices/xxxxxxxxxxxx/setACStatus',
_ended: true,
parser: null,
res: [Circular] },
ntick: true,
response: [Circular],
originalHost: 'api.spark.io',
originalHostHeaderName: 'host',
responseContent: [Circular],
_destdata: true,
_ended: true,
_callbackCalled: true },
toJSON: [Function: responseToJSON],
caseless:
Caseless {
dict:
{ server: 'nginx',
date: 'Tue, 20 Dec 2016 11:26:25 GMT',
'content-type': 'application/json; charset=utf-8',
'content-length': '98',
connection: 'close',
'access-control-allow-origin': '*' } },
read: [Function],
body: '{\n "id": "xxxxxxxxxxxx",\n "last_app": "",\n "connected": true,\n "return_value": 0\n}' }