mabunixda / node-red-contrib-alexa-home

MIT License
32 stars 10 forks source link

New bind to IP feature is not working correctly #62

Closed Sk4zz closed 4 years ago

Sk4zz commented 4 years ago

Thank you very much for implementing the "bind to IP" feature! I have updated alexa-home to the latest version and set Environment=ALEXA_IP=192.168.2.12 and Environment=ALEXA_PORT=80 using systemctl edit nodered.service

Upon restart, nodered reports the following:

Oct 01 15:22:57 raspberrypi Node-RED[11089]: 1 Oct 15:22:57 - [info] [alexa-home-controller:Alexa Controller] Using 192.168.2.12 to listing to alexa commands
Oct 01 15:22:57 raspberrypi Node-RED[11089]: 1 Oct 15:22:57 - [info] [alexa-home-controller:Alexa Controller] 0 - alexa-home - Starting SSDP
Oct 01 15:22:57 raspberrypi Node-RED[11089]: 1 Oct 15:22:57 - [info] [alexa-home-controller:Alexa Controller] 0 - announcing: http://*:60000/alexa-home/setup.xml

When I search for new devices in Alexa, I get

Oct 01 15:23:37 raspberrypi Node-RED[11089]: 1 Oct 15:23:37 - [info] [alexa-home-controller:Alexa Controller] 192.168.2.36-60000/GET -> /alexa-home/setup.xml
Oct 01 15:23:37 raspberrypi Node-RED[11089]: 1 Oct 15:23:37 - [info] [alexa-home-controller:Alexa Controller] 192.168.2.165-60000/GET -> /alexa-home/setup.xml

And no new devices turn up.

Am I doing something wrong or is there a bug in the new implementation?

Thanks in advance!

mabunixda commented 4 years ago

The ALEXA_PORT setting is just used on first/initial startup. As you have already deployed a node-red please adapt the configuration on the controller.

The controller now has a port property to easily modify the listening port without the need of iptables and env variables

Sk4zz commented 4 years ago

I hat the problem that node-red failed to bind to port 80 and crashed when I set Port 80 in the controller properties, reporting Error: listen EACCES: permission denied 192.168.2.12:80

The reason was that node-red was not running with root privileges but I found an answer here https://stackoverflow.com/questions/9164915/node-js-eacces-error-when-listening-on-most-ports

sudo apt-get install libcap2-bin
sudo setcap cap_net_bind_service=+ep `readlink -f \`which node\``

solved the problem. Thank you for your help, everything is working like a charm now.

mabunixda commented 4 years ago

Get all devices detected also? How many devices do you have configured?

Sk4zz commented 4 years ago

Hmm... Now that you mention it. I have two devices configured right now, but only one of them is discovered. I will have some time for further debugging in the afternoon.

Sk4zz commented 4 years ago

I did some digging but I could not come up with much. I now have 3 devices configured but only one device is found by Alexa. I have tried the following:

  1. remove the device from Alexa and search again
  2. remove the device from nodered and search again
  3. remove the controller node, deploy, add a new controller node and search again.

The results were as follows:

Oct 02 13:56:25 raspberrypi Node-RED[6331]: 2 Oct 13:56:25 - [info] [alexa-home-controller:Alexa Controller] 192.168.2.165-80/GET -> /alexa-home/setup.xml
Oct 02 13:56:25 raspberrypi Node-RED[6331]: 2 Oct 13:56:25 - [info] [alexa-home-controller:Alexa Controller] 192.168.2.165-80/GET -> /api/c6260f982b43a226b5542b967f612ce/lights
Oct 02 13:56:25 raspberrypi Node-RED[6331]: 2 Oct 13:56:25 - [info] [alexa-home-controller:Alexa Controller] 192.168.2.165-80/GET -> /api/c6260f982b43a226b5542b967f612ce/lights/ca52cac053bb38
Oct 02 13:56:25 raspberrypi Node-RED[6331]: 2 Oct 13:56:25 - [info] [alexa-home-controller:Alexa Controller] 192.168.2.36-80/GET -> /alexa-home/setup.xml
Oct 02 13:56:25 raspberrypi Node-RED[6331]: 2 Oct 13:56:25 - [info] [alexa-home-controller:Alexa Controller] 192.168.2.36-80/GET -> /api/c6260f982b43a226b5542b967f612ce/lights
Oct 02 13:56:25 raspberrypi Node-RED[6331]: 2 Oct 13:56:25 - [info] [alexa-home-controller:Alexa Controller] 192.168.2.36-80/GET -> /api/c6260f982b43a226b5542b967f612ce/lights/ca52cac053bb38

The content of /alexa-home/setup.xml is

<root xmlns="urn:schemas-upnp-org:device-1-0">
<style/>
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<URLBase>http://192.168.2.12</URLBase>
<device>
<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>
<friendlyName>Amazon-Echo-NodeRed-Bridge http://192.168.2.12</friendlyName>
<manufacturer>Royal Philips Electronics</manufacturer>
<manufacturerURL>https://nitram.at</manufacturerURL>
<modelDescription>Philips hue Personal Wireless Lighting</modelDescription>
<modelName>Philips hue bridge 2012</modelName>
<modelNumber>1100110011001100</modelNumber>
<modelURL>http://meethue.com</modelURL>
<serialNumber>93eadbeef14</serialNumber>
<UDN>uuid:f6543a06-da50-11ba-8d8f-da5ce2a568d56</UDN>
<serviceList>
<service>
<serviceType>(null)</serviceType>
<serviceId>(null)</serviceId>
<controlURL>(null)</controlURL>
<eventSubURL>(null)</eventSubURL>
<SCPDURL>(null)</SCPDURL>
</service>
</serviceList>
<presentationURL>index.html</presentationURL>
<iconList>
<icon>
<mimetype>image/png</mimetype>
<height>48</height>
<width>48</width>
<depth>24</depth>
<url>hue_logo_0.png</url>
</icon>
<icon>
<mimetype>image/png</mimetype>
<height>120</height>
<width>120</width>
<depth>24</depth>
<url>hue_logo_3.png</url>
</icon>
</iconList>
</device>
</root>

and the content of /api/c6260f982b43a226b5542b967f612ce is

{ "lights": 
{ "2233ac75673694": { "state": { "on": false, "bri": 254, "hue": 0, "sat": 254, "effect": "none", "xy": [ 0.0, 0.0 ], "ct": 199, "colormode": "ct", "reachable": true, "alert":"none", "mode":"homeautomation" }, "swupdate": { "state": "noupdates", "lastinstall": "2019-10-02T12:24:21" }, "type": "Dimmable light", "name": "Kaffeemaschine", "modelid": "LCT007", "manufacturername": "Philips", "productname": "Hue color lamp", "swversion": "5.105.0.21169", "uniqueid":"00:11:22:33:44:55:66:77-88" },
"e7db50857915": { "state": { "on": false, "bri": 254, "hue": 0, "sat": 254, "effect": "none", "xy": [ 0.0, 0.0 ], "ct": 199, "colormode": "ct", "reachable": true, "alert":"none", "mode":"homeautomation" }, "swupdate": { "state": "noupdates", "lastinstall": "2019-10-02T12:24:21" }, "type": "Extended color light", "name": "Abwesenheitsmodus", "modelid": "LCT007", "manufacturername": "Philips", "productname": "Hue color lamp", "swversion": "5.105.0.21169", "uniqueid":"00:11:22:33:44:55:66:77-88" }, 
"a6fae4510b55d8": { "state": { "on": false, "bri": 254, "hue": 0, "sat": 254, "effect": "none", "xy": [ 0.0, 0.0 ], "ct": 199, "colormode": "ct", "reachable": true, "alert":"none", "mode":"homeautomation" }, "swupdate": { "state": "noupdates", "lastinstall": "2019-10-02T12:24:21" }, "type": "Dimmable light", "name": "Stereoanlage", "modelid": "LCT007", "manufacturername": "Philips", "productname": "Hue color lamp", "swversion": "5.105.0.21169", "uniqueid":"00:11:22:33:44:55:66:77-88" },
"_emptyIteratorStopper": {} }, "config":{"name":"Philips hue","mac":"00:00:00:aa:bb:cc","dhcp":true,"ipaddress":"192.168.2.12","netmask":"0.0.0.0","gateway":"0.0.0.0","proxyaddress":"","proxyport":0,"UTC":"2019-10-02T12:24:21","whitelist":{ "c6260f982b43a226b5542b967f612ce":{"last use date":"2019-10-02T12:24:21","create date":"2019-10-02T12:24:21","name":"Echo" }},"swversion":"01003372","swupdate":{ "updatestate":0, "url":"", "text":"", "notify":false},"linkbutton":false,"portalservices":false }}

Weirdly, the device Stereoanlage is the only device being found. If I remove this device from the flow, no device is found and the log reports

Oct 02 14:31:15 raspberrypi Node-RED[6331]: 2 Oct 14:31:15 - [info] [alexa-home-controller:Alexa Controller] 192.168.2.165-80/GET -> /api/c6260f982b43a226b5542b967f612ce/lights/a6fae4510b55d8
Oct 02 14:31:15 raspberrypi Node-RED[6331]: 2 Oct 14:31:15 - [warn] unknown alexa node of type lights was requested: a6fae4510b55d8
mabunixda commented 4 years ago

the alexa discovery workflow has following steps

Do you see requests on /api/ in the logs? Can you review if each device in /api//lights is requested on the details?

You can use this viewer to review json data ...

Sk4zz commented 4 years ago

I have again tried removing the Stereoanlage node and reinserting it. Now, no devices are found by alexa. I can see the POST to /api and the GET to /api/lights but no further GET to the indivudual lights (before it was only requesting one light, although more were configured)

The json data of /api seems fine to me (thanks for the link!). The only point is that all lights have the same uniqueid namely 00:11:22:33:44:55:66:77-88

mabunixda commented 4 years ago

@Sk4zz are you using gen2 or gen3 alexa device? can you verify which device is doing the discovery? an IP should be listed in the logs ( and yes, at the moment there are massive logs :( )

Sk4zz commented 4 years ago

I have a gen.2 echo dot and a gen.3 echo. I am starting the discovery from the web UI or the alexa app and I can confirm that both devices are doing the discovery. Both devices are GETting the setup.xml, are POSTing to /api and again GETting from \api\xxxxxxx\lights. But the individual lights are not being requested. Attached is again my api-JSON this time properly formatted. I can't see any obvious reason as to why the lights are not discovered.

{
   "lights":{
      "2233ac75673694":{
         "state":{
            "on":false,
            "bri":254,
            "hue":0,
            "sat":254,
            "effect":"none",
            "xy":[
               0.0,
               0.0
            ],
            "ct":199,
            "colormode":"ct",
            "reachable":true,
            "alert":"none",
            "mode":"homeautomation"
         },
         "swupdate":{
            "state":"noupdates",
            "lastinstall":"2019-10-03T09:38:01"
         },
         "type":"Dimmable light",
         "name":"Kaffeemaschine",
         "modelid":"LCT007",
         "manufacturername":"Philips",
         "productname":"Hue color lamp",
         "swversion":"5.105.0.21169",
         "uniqueid":"00:11:22:33:44:55:66:77-88"
      },
      "e7db50857915":{
         "state":{
            "on":false,
            "bri":254,
            "hue":0,
            "sat":254,
            "effect":"none",
            "xy":[
               0.0,
               0.0
            ],
            "ct":199,
            "colormode":"ct",
            "reachable":true,
            "alert":"none",
            "mode":"homeautomation"
         },
         "swupdate":{
            "state":"noupdates",
            "lastinstall":"2019-10-03T09:38:01"
         },
         "type":"Extended color light",
         "name":"Abwesenheitsmodus",
         "modelid":"LCT007",
         "manufacturername":"Philips",
         "productname":"Hue color lamp",
         "swversion":"5.105.0.21169",
         "uniqueid":"00:11:22:33:44:55:66:77-88"
      },
      "21ba2ce7f0f744":{
         "state":{
            "on":false,
            "bri":254,
            "hue":0,
            "sat":254,
            "effect":"none",
            "xy":[
               0.0,
               0.0
            ],
            "ct":199,
            "colormode":"ct",
            "reachable":true,
            "alert":"none",
            "mode":"homeautomation"
         },
         "swupdate":{
            "state":"noupdates",
            "lastinstall":"2019-10-03T09:38:01"
         },
         "type":"Dimmable light",
         "name":"Stereoanlage",
         "modelid":"LCT007",
         "manufacturername":"Philips",
         "productname":"Hue color lamp",
         "swversion":"5.105.0.21169",
         "uniqueid":"00:11:22:33:44:55:66:77-88"
      },
      "_emptyIteratorStopper":{

      }
   },
   "config":{
      "name":"Philips hue",
      "mac":"00:00:00:aa:bb:cc",
      "dhcp":true,
      "ipaddress":"192.168.2.12",
      "netmask":"0.0.0.0",
      "gateway":"0.0.0.0",
      "proxyaddress":"",
      "proxyport":0,
      "UTC":"2019-10-03T09:38:01",
      "whitelist":{
         "":{
            "last use date":"2019-10-03T09:38:01",
            "create date":"2019-10-03T09:38:01",
            "name":"Echo"
         }
      },
      "swversion":"01003372",
      "swupdate":{
         "updatestate":0,
         "url":"",
         "text":"",
         "notify":false
      },
      "linkbutton":false,
      "portalservices":false
   }
}
Sk4zz commented 4 years ago

I have moved my node-red installation to my Pi4 which hosts my homeassistant installation (hassbian) because there is no conflict with port 80 and hence no need to use virtual network adapters.

Sadly, the problem persists. When Alexa is searching for devices, first setup.xml is polled, then api/ and finally api/xxxx/lights but it does not descent further to the individual lights and alexa ends up finding no new devices.

I would be thankful for any advice.

mabunixda commented 4 years ago

any updates after those multiple firmware updates of alexa devices?

Sk4zz commented 4 years ago

I changed my whole setup a couple of days ago. I moved my homeassistant from hassbian to hass.io on hassos. With the node-red plugin comes a pre-installed and un-uninstallable alexa-skill-module, so I was not able to install your alexa-home. So I moved my nodered back to my second raspi and the first alexa-node was discovered by alexa but not the second one. I ended up adding a handful more alex nodes and about 50% of them were discovered by alexa. I am now using the ones that were discovered and it's working fine. Nevertheless, this solution is just a workaround and there seems something wrong somewhere. But I can't figure out, where.

leouzz commented 4 years ago

Hi, i Have the same problem, just 1 device discovered, orangepi + home assistant + node-red echo dot gen3 node-red run by sudoers user

mabunixda commented 4 years ago

@leouzz @Sk4zz still fighting those problem or already fixed/moved? ;-)

Sk4zz commented 4 years ago

I have moved on. I am now using the homeassistant cloud for my Alexa integration. When I find the time, I will check if the problem still persists.

mabunixda commented 4 years ago

ok - closing it now .. just reopen it - or create a new one