Page 9 of 36
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Saturday 08 October 2016 17:35
by deennoo
blackdog65 wrote:From what I can see there is no immediate plan to roll out into Europe.
There is currently no way to get notifications, even simple reminders are just a sound with no clue as to what you are being reminded of.
No IFTTT, no shopping, no true calendar/to-do integration. Only really ready for US market.
Mine is now boxed up ready for return. I'll wait for Google Home.
Ok thx for your input, will wait for google home too.
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Tuesday 11 October 2016 16:38
by Madgeni
hi -
so the code's been neatened, and now allows control of temperature.
I have this working via my Echo, and can set temperature/turn lights & groups On/Off.
https://github.com/madgeni/alexa_domo
Dimming is still a challenge, but that's tied to the Domoticz API, rather than my code (yet!).
Re: Notifications - push notifications are coming to Alexa soon, which *might* allow querying of devices - i'll look at that, when it's made available.
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Friday 14 October 2016 11:02
by amz4u2nv
Madgeni wrote:hi -
so the code's been neatened, and now allows control of temperature.
I have this working via my Echo, and can set temperature/turn lights & groups On/Off.
https://github.com/madgeni/alexa_domo
Dimming is still a challenge, but that's tied to the Domoticz API, rather than my code (yet!).
Re: Notifications - push notifications are coming to Alexa soon, which *might* allow querying of devices - i'll look at that, when it's made available.
Hi Madgeni, does this fix the issues with some devices not showing up on the alexa app?
Thanks for your work on this..
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Friday 14 October 2016 11:18
by Madgeni
Hi -
yes i believe it does - but over to you guys for testing

Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Saturday 15 October 2016 17:30
by renerene
I've heard that the Echo is
coming to the UK and it got my attention when
reading about it's possibilities. Gonna keep a close watch on this thread. A connection to Domoticz would be great.
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Sunday 16 October 2016 1:22
by amz4u2nv
Hey madgeni, how difficult would it be to only include devices that are part of a room so I can filter what Alexa can control. Deleting unnecessary devices from Alexa manually works but they come back again after a while as I assume that Alexa auto discovers frequently.
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Sunday 16 October 2016 8:38
by gizmocuz
amz4u2nv wrote:Hey madgeni, how difficult would it be to only include devices that are part of a room so I can filter what Alexa can control. Deleting unnecessary devices from Alexa manually works but they come back again after a while as I assume that Alexa auto discovers frequently.
Thats a great idea, this is what is done for the current homebridge implementation
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Sunday 16 October 2016 9:14
by Madgeni
should be doable, presumably a room has a list of devices in the domoticz.db, which should be accessible via the API somehow - i'll take a look
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Monday 17 October 2016 16:14
by amz4u2nv
Had a go adding the room id -
Code: Select all
function getDevs(context, callback) {
var headers = {
namespace: 'Alexa.ConnectedHome.Discovery',
name: 'DiscoverAppliancesResponse',
payloadVersion: '2'
};
api.getRoomDevices({
filter: 'all',
used: true,
order: 'Name',
roomid: '3'
}, function (error, devices) {
var devArray = devices.results;
var i = devArray.length;
lupus(0, devArray.length, function (n) {
var device = devArray[n];
var devType = device.type;
var setswitch = device.switchType;
i--;
console.log('device type '+devType + 'and device is '+device);
if (devType == 0) {
var appliancename = {
applianceId: device.idx,
manufacturerName: device.name,
modelName: device.name,
version: 1,
friendlyName: device.name,
friendlyDescription: ".",
isReachable: true,
actions: [
"incrementPercentage",
"decrementPercentage",
"setPercentage",
"turnOn",
"turnOff"
],
additionalApplianceDetails: {
switchis: setswitch,
WhatAmI: "light"
}
};
appliances.push(appliancename);
}
//else if (devType == 'Temp') {
// appliancename = {
// applianceId: device.idx,
// manufacturerName: device.hardwareName,
// modelName: device.subType,
// version: device.idx,
// friendlyName: device.name,
// friendlyDescription: ".",
// isReachable: true,
// actions: [
// "setTargetTemperature"
// ],
// additionalApplianceDetails: {
// WhatAmI: "temp"
// }
// };
// appliances.push(appliancename);
//}
else if (devType == '1') {
var elid = parseInt(device.idx) + 2000;
appliancename = {
applianceId: elid,
manufacturerName: device.name,
modelName: device.name,
version: 1,
friendlyName: device.name.replace('[Scene] ',''),
friendlyDescription: ".",
isReachable: true,
actions: [
"turnOn",
"turnOff"
],
additionalApplianceDetails: {
WhatAmI: "group"
}
};
appliances.push(appliancename);
}
if (i == 0) {
console.log ('appliances '+appliances);
var payloads = {
discoveredAppliances: appliances
};
// log(appliances);
var result = {
header: headers,
payload: payloads
};
callback(result);
}
})
})
}
/**
* Get all the room devices
* @param callback
*/
Domoticz.prototype.getRoomDevices = function (_params, callback) {
var params = {
filter: 'all', // Can also be `light`, `weather`, `temperature`, `utility`
used: true,
order: 'Name'
};
params = extend(params, _params);
var url = this._getUrl();
url.addSearch("type", "command");
url.addSearch("param", "getplandevices");
// Add potential filters
params["filter"] != undefined && _.isString(params["filter"]) ? _.contains(['all', 'light', 'weather', 'temperature', 'utility'], params["filter"]) ? url.addSearch("filter", params["filter"]) : this : this;
params["used"] != undefined && _.isBoolean(params["used"]) ? params["used"] ? url.addSearch("used", 'true') : url.addSearch("used", 'false') : this;
params["order"] != undefined && _.isString(params["order"]) ? url.addSearch("order", params["order"]) : this;
params["roomid"] != undefined && _.isString(params["roomid"]) ? url.addSearch("idx", params["roomid"]) : this;
params["roomid"] != undefined && _.isString(params["roomid"]) ? url.addSearch("param", 'getplandevices') : this;
this._request(url, callback);
};
the api returns different values back when going via the room id, so had to change the switch code - Just a hacky attempt, but maybe it will help.
I dont have any temperature setters in the house, so no idea what to put in the switch case.
Cheers,
Amz
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Monday 17 October 2016 17:18
by amz4u2nv
this should help out with dimming -
changed in domoticz.js
Code: Select all
Domoticz.prototype.changeSwitchState = function (params, callback) {
var url = this._getUrl();
url.addSearch("type", "command");
url.addSearch("idx", params.idx);
params.type === 'switch' ? url.addSearch("param", 'switchlight') : this;
// params.type === 'dimmable' ? params.state = 'Set Level' : this;
params.state === 'toggle' ? params.state = 'Toggle' : this;
params.state === 'on' ? params.state = 'On' : this;
params.state === 'off' ? params.state = 'Off' : this;
if (params.type == 'dimmable')
{
url.addSearch("level", parseInt((parseInt(params.state) / 100) * 16));
url.addSearch("switchcmd", 'Set Level');
url.addSearch("param", 'switchlight');
}
else
{
url.addSearch("switchcmd", params.state);
}
console.log('URL called ' +url);
this._request(url, callback);
};
change in domapi.js
Code: Select all
function handleControl(event, context) {
var state;
var idx;
log("what's the event?", event);
var accessToken = event.payload.accessToken;
var what = event.payload.appliance.additionalApplianceDetails.WhatAmI;
var message_id = event.header.messageId;
var switchtype = event.payload.appliance.additionalApplianceDetails.switchis;
var applianceId = event.payload.appliance.applianceId;
var confirmation;
var funcName;
switch (what) {
case "light":
var dimmable = 'N';
if (event.header.name == "TurnOnRequest") {
confirmation = "TurnOnConfirmation";
funcName = "On";
}
else if (event.header.name == "TurnOffRequest") {
confirmation = "TurnOffConfirmation";
funcName = "Off";
}
else if (event.header.name == "SetPercentageRequest") {
confirmation = "SetPercentageConfirmation";
dimmable = 'Y';
funcName = event.payload.percentageState.value;
console.log('percent '+funcName);
}
var headers = {
namespace: 'Alexa.ConnectedHome.Control',
name: confirmation,
payloadVersion: '2',
messageId: message_id
};
if (dimmable == 'N')
{
ctrlLights(applianceId, funcName, function (callback) {
var result = {
header: headers,
payload: callback
};
context.succeed(result);
});
}
else if (dimmable == 'Y')
{
ctrlLightsDim(applianceId, funcName, function (callback) {
var result = {
header: headers,
payload: callback
};
context.succeed(result);
});
}
break;
case "group":
var AppID = parseInt(event.payload.appliance.applianceId) - 2000;
if (event.header.name == "TurnOnRequest") {
confirmation = "TurnOnConfirmation";
funcName = "On";
}
else if (event.header.name == "TurnOffRequest") {
confirmation = "TurnOffConfirmation";
funcName = "Off";
}
headers = {
namespace: 'Alexa.ConnectedHome.Control',
name: confirmation,
payloadVersion: '2',
messageId: message_id
};
ctrlScene(AppID, funcName, function (callback) {
var result = {
header: headers,
payload: callback
};
context.succeed(result);
}); break;
case "temp":
var temp = event.payload.targetTemperature.value;
applianceId = event.payload.appliance.applianceId;
if (event.header.name == "SetTargetTemperatureRequest") {
confirmation = "SetTargetTemperatureConfirmation";
// flVal = parseFloat(temp);
}
headers = {
namespace: 'Alexa.ConnectedHome.Control',
name: confirmation,
payloadVersion: '2',
messageId: message_id
};
ctrlTemp(applianceId, temp, function (callback) {
var result = {
header: headers,
payload: callback
};
context.succeed(result);
});
break;
default:
log("error - not hit a device type");
}
}
function ctrlLightsDim(applianceId, func, sendback) {
console.log('func ' +func);
api.changeSwitchState({
type: "dimmable",
idx: applianceId,
state: func
}, function (params, callback) {
console.log(params, callback);
var payloads = {};
sendback(payloads)
});
}
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Tuesday 18 October 2016 19:38
by Madgeni
Thanks for the dimmer bit, that really helped.
I'd done most of the room plan bit, but hopefully neat and efficient - please test it and let me know.
NB - if you want devices discovered now, they need to be in a Room Plan.
https://github.com/madgeni/alexa_domo
release note:
Dimmers and Room Plan control for device discovery now working 18/10
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Friday 21 October 2016 15:56
by nigels0
I've just got myself an Echo Dot in the UK, but rather puzzled as to get this to work - I've cloned the GitHub and opened the readme - but there doesn't seem to be clear step-by-step instructions (or maybe it's just me...). Is there any chance of a wiki?
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Friday 21 October 2016 17:11
by Madgeni
Hi nigels0 -
is the word doc not clear? Let me know which bit you're struggling with, and i'll help

It's basically: Create Smart Home Skill;Create Lambda function for Smart Home - copy in application ID from smart home skill, zip the node_modules folder, domapi.js & package.json, then upload them to the Lambda. Fill in the oauth bit as per the doc in the Smart Home Skill, and test (Basically!).
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Friday 21 October 2016 18:22
by gizmocuz
@Madgeni, send you a PM a few days ago, i am making a new word document with some more screenshots,instructions, but i am stuck at a certain point
A wiki would be great if the document is approved
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Friday 21 October 2016 18:44
by nigels0
Hi Madgeni,
Edit,
well I found the app - you need to link the echo to the developer account - and that meant logging out and then logging back in again. Nonetheless, while I can now access the skill and link to it, I'm not finding any devices to control and yes - I have room plans.
Looking forward to gizmocuz's writeup too - but any help would be appreciated!
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Friday 21 October 2016 21:04
by renerene
I'm in the Amazon queue for an Echo Dot. Will be installing soon.
So, yes please, a wiki page! Or share the word doc as a Google doc untill then?
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Saturday 22 October 2016 2:07
by nigels0
Trying out one of the tests - the switch off one - i get an error returned.
the command is:
http://<user>:<password>@<ipaddress>:8080/json.htm?type=command&idx=47&switchcmd=Off
Shouldn't this be:
http://<user>:<password>@<ipaddress>:8080/json.htm?type=command¶m=switchlight&idx=47&switchcmd=Off
If there is a problem parsing the json, then maybe that explains why I'm not getting any devices
The discovery test works though.... why am I not getting any appearing as Devices in the app though? Puzzling!
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Saturday 22 October 2016 13:29
by Madgeni
certainly shouldn't be an issue for discovery, but yes, there's a line missing from the light switch statement:
case "light":
//missing the line below;
var switchtype = "switch";
//missing the line above;
if (event.header.name == "TurnOnRequest")
Will also make a start on a comprehensive wiki
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Saturday 22 October 2016 14:38
by nigels0
Thought so. By the way, I'm really thankful that you have built this! I'm planning to get the 6-pack of dots and distribute them around the house if the single one works.
Still not clear though about why I'm not getting all devices - maybe I have too many? (I have about 200).
Note that it's probably better to put the Lambda creation before the skill creation as you can get the ARN for the location you want to use (in my case - Ireland) with the correct Lambda function - mine was arn:aws:lambda:eu-west-1:638591532178:function:Domoticz. That was my problem; I blindly copied your ARN which of course was not the correct name of the function. Fixing that, I got 38 devices - exactly the same number that the discovery test code finds.....Still not enough, but a good start.
By adding the missing line in domapi.js, the devices that are found are working now!
Re: Amazon Echo to Domoticz Bridge: switches, sensors & more
Posted: Saturday 22 October 2016 15:35
by nigels0
amz4u2nv wrote:I am getting the same issues where the devices are not found.
I checked the url used and it brings back whole the devices via the browser.
But for some reason I think via lambda it only brings back a certain amount of devices. I had to make some of my devices and scenes hidden using $ in front of the device name and re-run the alexa discover devices, it then picks up the missing devices.
I can't see anything in the code that would put a limit of how many devices should be discovered. Tried up - ing the timeout and memory allocated, didn't make any effect.
So as a workaround you can hide the devices and incrementally discover them on alexa.
Let me know if you find a better solution.
I have the same issue - seems to discover in units of 19! Painful to have to do the same thing with a couple of hundred devices! Not sure whether it is a Domoticz problem or an a Lambda problem - I suspect it is Lambda as Domoticz does report all the devices from the browser using the same JSON.