datech / node-red-contrib-amazon-echo

Alexa controlled Node-Red nodes supporting latest Amazon Echo devices. NO Alexa Skills required. NO cloud dependencies.
MIT License
137 stars 43 forks source link

Enable/Disable of device nodes #17

Open datech opened 5 years ago

datech commented 5 years ago

Add feature to enable/disable device nodes.

If device node is disabled, Alexa will not be able to:

All disabled devices that are already discovered will show an error: "Server is not responsive" or |Device malfunction" in the Alexa app

Barabba11 commented 5 years ago

thank you dear friend, because I just tried to create a new flow and insert there the new devices, disabled the first flow, but the scond Alexa found me instead all devices of the first flow..

Barabba11 commented 5 years ago

My friend, thinking about it I think the solution (which is welcome!! For different reasons) do not solve the problem with 2 Alexa into the same network. You can disable and discover, but there will be the unlucky day that you or someone else says "Alexa find new peripherals", it will add the other items configured in node red..

This you have a flat with 2 floors, in everyone you put an echo plus, in both apartments you have light of bathroom, ventilation, etc etc, you would be tempted to use the same names.. and after there will be conflict or undesidered switch on. I would like to ask you to add in HUB a field for IP address of Alexa, the hub will share all the modules connected to it which should operate with Alexa1 only, the others may be connected to another hub, with the IP of the Alexa2, but with the same TCP port (so we need only none Philips server . Shorty, the hub will communicate only with that IP, and the other Alexa can't more never recognizes or communicate with items not connected to that hub. Is it possible? Very useful, we can say under the same LAN, in two different floors, switch off the living room (thee is one in first floor and another in second floor).. the same command without interferes if names are similar. Thanks!!!

datech commented 5 years ago

Enable/disable functionality has to be sufficient to cover this case, as the devices are identified by ID. The device name is used only for voice commands, which are later translated to API calls using device ID instead of name.

Barabba11 commented 5 years ago

Frankly I have to say you that's not, unfortunately, I thought about it later, in experimental way yes.. I have about 40 nodes, a bit long to open all of them and disable, recognise the new ones on the second Alexa, and enable all 40 again, but in the reality.. can be for a mistake I say Alexa "find new devices" and all this effort with be lost.. Yes I can maybe delete manually by the app, but not the best solution. If it is possible to introduce a filter in hub (IP or MAC) we can not worry about this more, o my the devices connected to that hub signed by Alexa IP/mac can be recognised and used by that Alexa. I'll try today to have a look in the code and guess if it is possible to add easily a filter on the http server.. Thank you!

datech commented 5 years ago

@Barabba11 May be #22 could be a good solution?

Barabba11 commented 5 years ago

Thanks again, I don't think so because in this way I can't avoid the second Alexa to recognize the devices of the Alexa1, and there will be the same names, Ican't use the same name twice: think about you have a flat with 2 floors, one wifi, one electric cabinet with Node red, dimmers and all wires there.. You enter in first floor and say: "alexa open shutters", "alexa switch on the soft light".. Then you move to the second floor, you will say "alexa open shutters", "alexa switch on the soft light" (the second Alexa there will listen). I mean, in the second floor you are not going to say "Alexa open blinds", or "shutters of the second floor".. you would have the things easy, so we need to use the easiest names. Do you think that to filter in the http server the IP or MAC of Alexa (or any other way to exclude it) is hard to implement? Maybe it would be enough to enter just small part of code to check the source IP address? Thank you

Barabba11 commented 5 years ago

Mate I tried to open your script to try to help you, but there I cannot find the http server code, am I wrong? I think we need to work on it, so it can output too the IP address of Echo. Thanks for help!

Barabba11 commented 5 years ago

I'm back on this again after another work I finished, I would analize the http server and try to change it somehow.. to see if it is possible to filter the alexa by IP or mac address.. But I can't find the sources of http server. Maybe it is using system's libraries for that? May you help me, to help you? :) Thank you

datech commented 5 years ago

I had an idea of sub-hubs that might resolve your issue. I will try to implement it for the next version.

Barabba11 commented 5 years ago

Hi my friend! Do you have any news here? Can I help you somehow? Thank you!

Barabba11 commented 5 years ago

Hi mate, I really need your help, any progress about this? Can I help you? I really would like to help! Thank you

Barabba11 commented 5 years ago

I'm kindly wait for your help, I hope all is ok with you and you can support us in future! PLease let us know, thank you! As you see here a friend found the type of command told to Alexa in your object: https://github.com/datech/node-red-contrib-amazon-echo/issues/33 It would be nice to have it as an output. There is present also the source IP address of Alexa, so it would be great to add to the device module http window the chance to enable the IP filter, and type the IP of Alexa where the device should be associated (if we need to associate to more Alexas then we'll double the node in the flow, or to associate to all Alexas simply disable the filter). If the filter is enbled only that IP/Alexa can find that device. A chance to edit the ID of the node, and save it in the flow export, so we can import a backuped flow without the need to delete all devices of Alexa and search for the same ones (with new ID created by NR).

Thank you a lot!

Barabba11 commented 5 years ago

Very interesting post that can help:

No library. Everything is contained in the author's module. The server is defined in the file index.js. In the following lines:

        var httpServer = stoppable(http.createServer(app), graceMilliseconds);

        httpServer.on('error', function(error) {
          hubNode.status({fill:"red", shape:"ring", text:"Unable to start on port " + port});
          RED.log.error(error);
          return;
        });

to see the traffic, you can add the line hubNode.warn(req) in the area of the code that process requests from the Echo (commented here):

       app.put('/api/:username/lights/:id/state', function (req, res) {

  //hubNode.warn(req);
        setDeviceAttributes(req.params.id, req.body, hubNode.context().flow);

        var template = fs.readFileSync(__dirname + '/api/hue/templates/lights/set-state.json', 'utf8').toString();

        var data = getDeviceAttributes(req.params.id, hubNode.context().flow);

        var output = Mustache.render(template, data);
        output = JSON.parse(output);

        res.json(output);

        payloadHandler(hubNode, req.params.id, req.body);
      });

Hope this helps get you started.