NorthernMan54 / homebridge-alexa

Expose your homebridge controlled devices to Amazon Alexa.
https://www.homebridge.ca
453 stars 69 forks source link

Doorbell Support #353

Closed tylerdorazio closed 4 years ago

tylerdorazio commented 4 years ago

Will this plugin support doorbell devices? Specifically, I have a unifi G4 doorbell that is defined properly as a doorbell in HomeBridge (using the homebridge-unifi-protect2 package).

NorthernMan54 commented 4 years ago

Are you thinking of this?

https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-doorbelleventsource.html

Implementing the door bell event should be straight forward, but not the video feed.

I don’t have my doorbell integrated into homebridge yet, so I would not be able to test this, but if you have the ability to provide testing support it could be done.

To start I would need a homebridge accessory dump for your doorbell service. If you can share that we can look at implementing

tylerdorazio commented 4 years ago

That's exactly what I was looking at! Just the doorbell event is what i'm looking for honestly so it can announce when someone is at the door. Not worried about the video stream. I'd be more than happy to test this out!

Attached is the accessory dump for the doorbell. doorbell.txt

NorthernMan54 commented 4 years ago

This is what is currently being passed to Alexa for your doorbell

{
  "event": {
    "header": {
      "namespace": "Alexa.Discovery",
      "name": "Discover.Response",
      "payloadVersion": "3",
      "messageId": "1bd5d003-31b9-476f-ad03-71d471922820"
    },
    "payload": {
      "endpoints": [
        {
          "endpointId": "Q0M6MjI6M0Q6RTM6Q0U6MzAtcGFyc2VUZXN0LVViaXF1aXRpIE5ldHdvcmtzLVVWQyBHNCBEb29yYmVsbCA3NTY1LTAwMDAwMDQ5LTAwMDAtMTAwMC04MDAwLTAwMjZCQjc2NTI5MQ==",
          "friendlyName": "UVC G4 Doorbell 7565",
          "description": "parseTest UVC G4 Doorbell 7565 Switch",
          "manufacturerName": "Ubiquiti Networks",
          "displayCategories": [
            "SWITCH"
          ],
          "cookie": {
            "TurnOn": "{\"deviceID\":\"CC:22:3D:E3:CE:30\",\"aid\":3,\"iid\":14,\"value\":1}",
            "TurnOff": "{\"deviceID\":\"CC:22:3D:E3:CE:30\",\"aid\":3,\"iid\":14,\"value\":0}",
            "ReportState": "[{\"interface\":\"Alexa.PowerController\",\"deviceID\":\"CC:22:3D:E3:CE:30\",\"aid\":3,\"iid\":14}]"
          },
          "capabilities": [
            {
              "type": "AlexaInterface",
              "interface": "Alexa",
              "version": "3"
            },
            {
              "type": "AlexaInterface",
              "interface": "Alexa.PowerController",
              "version": "3",
              "properties": {
                "supported": [
                  {
                    "name": "powerState"
                  }
                ],
                "proactivelyReported": false,
                "retrievable": true
              }
            }
          ]
        },
        {
          "endpointId": "Q0M6MjI6M0Q6RTM6Q0U6MzAtcGFyc2VUZXN0LVViaXF1aXRpIE5ldHdvcmtzLVVWQyBHNCBEb29yYmVsbCA3NTY1LTAwMDAwMDg1LTAwMDAtMTAwMC04MDAwLTAwMjZCQjc2NTI5MQ==",
          "friendlyName": "UVC G4 Doorbell 7565",
          "description": "parseTest UVC G4 Doorbell 7565 Motion Sensor",
          "manufacturerName": "Ubiquiti Networks",
          "displayCategories": [
            "MOTION_SENSOR"
          ],
          "cookie": {
            "ReportState": "[{\"interface\":\"Alexa.MotionSensor\",\"deviceID\":\"CC:22:3D:E3:CE:30\",\"aid\":3,\"iid\":11}]"
          },
          "capabilities": [
            {
              "type": "AlexaInterface",
              "interface": "Alexa",
              "version": "3"
            },
            {
              "type": "AlexaInterface",
              "interface": "Alexa.MotionSensor",
              "version": "3",
              "properties": {
                "supported": [
                  {
                    "name": "detectionState"
                  }
                ],
                "proactivelyReported": true,
                "retrievable": true
              }
            }
          ]
        },
        {
          "endpointId": "Q0M6MjI6M0Q6RTM6Q0U6MzAtcGFyc2VUZXN0LVViaXF1aXRpIE5ldHdvcmtzLVVWQyBHNCBEb29yYmVsbCA3NTY1LTAwMDAwMTEwLTAwMDAtMTAwMC04MDAwLTAwMjZCQjc2NTI5MQ==",
          "friendlyName": "UVC G4 Doorbell 7565",
          "description": "parseTest UVC G4 Doorbell 7565 undefined",
          "manufacturerName": "Ubiquiti Networks",
          "displayCategories": [
            "OTHER"
          ],
          "cookie": {
            "TurnOn": "{\"deviceID\":\"CC:22:3D:E3:CE:30\",\"aid\":3,\"iid\":28,\"value\":1}",
            "TurnOff": "{\"deviceID\":\"CC:22:3D:E3:CE:30\",\"aid\":3,\"iid\":28,\"value\":0}",
            "ReportState": "[{\"interface\":\"Alexa.PowerController\",\"deviceID\":\"CC:22:3D:E3:CE:30\",\"aid\":3,\"iid\":28}]"
          },
          "capabilities": [
            {
              "type": "AlexaInterface",
              "interface": "Alexa",
              "version": "3"
            },
            {
              "type": "AlexaInterface",
              "interface": "Alexa.PowerController",
              "version": "3",
              "properties": {
                "supported": [
                  {
                    "name": "powerState"
                  }
                ],
                "proactivelyReported": false,
                "retrievable": true
              }
            }
          ]
        },
        {
          "endpointId": "Q0M6MjI6M0Q6RTM6Q0U6MzAtcGFyc2VUZXN0LVViaXF1aXRpIE5ldHdvcmtzLVVWQyBHNCBEb29yYmVsbCA3NTY1LTAwMDAwMTEyLTAwMDAtMTAwMC04MDAwLTAwMjZCQjc2NTI5MQ==",
          "friendlyName": "UVC G4 Doorbell 7565",
          "description": "parseTest UVC G4 Doorbell 7565 Microphone",
          "manufacturerName": "Ubiquiti Networks",
          "displayCategories": [
            "OTHER"
          ],
          "cookie": {
            "AdjustVolume": "{\"deviceID\":\"CC:22:3D:E3:CE:30\",\"aid\":3,\"iid\":20}",
            "SetVolume": "{\"deviceID\":\"CC:22:3D:E3:CE:30\",\"aid\":3,\"iid\":20}",
            "ReportState": "[{\"interface\":\"Alexa.Speaker\",\"deviceID\":\"CC:22:3D:E3:CE:30\",\"aid\":3,\"iid\":20}]"
          },
          "capabilities": [
            {
              "type": "AlexaInterface",
              "interface": "Alexa",
              "version": "3"
            },
            {
              "type": "AlexaInterface",
              "interface": "Alexa.Speaker",
              "version": "3",
              "properties": {
                "supported": [
                  {
                    "name": "volume"
                  }
                ],
                "proactivelyReported": false,
                "retrievable": true
              }
            }
          ]
        }
      ]
    }
  }
}

And this is current defined as an event source

{
  endpointId: 'Q0M6MjI6M0Q6RTM6Q0U6MzAtcGFyc2VUZXN0LVViaXF1aXRpIE5ldHdvcmtzLVVWQyBHNCBEb29yYmVsbCA3NTY1LTAwMDAwMDg1LTAwMDAtMTAwMC04MDAwLTAwMjZCQjc2NTI5MQ==',
  friendlyName: 'UVC G4 Doorbell 7565',
  description: 'parseTest UVC G4 Doorbell 7565 Motion Sensor',
  manufacturerName: 'Ubiquiti Networks',
  displayCategories: [ 'MOTION_SENSOR' ],
  cookie: {
    ReportState: '[{"interface":"Alexa.MotionSensor","deviceID":"CC:22:3D:E3:CE:30","aid":3,"iid":11}]'
  },
  capabilities: [
    { type: 'AlexaInterface', interface: 'Alexa', version: '3' },
    {
      type: 'AlexaInterface',
      interface: 'Alexa.MotionSensor',
      version: '3',
      properties: [Object]
    }
  ]
}
tylerdorazio commented 4 years ago

It seems like the Programmable Switch Event acts as the doorbell in Homebridge. The Home app treats it as such as well with the ability to alert on doorbell notifications. I wonder if that can trigger the DoorbellPress event.

Screen Shot 2020-08-19 at 12 55 20 PM
NorthernMan54 commented 4 years ago

I looked at the HomeKit spec, and it is the programmable switch. Just need to do some plumbing to the service and configure events. Give me a week or so

NorthernMan54 commented 4 years ago

This is taking longer than I expected, as getting the interface to the physical doorbell to work is taking longer. I ordered some parts based on this

https://hackaday.com/2020/06/01/the-easiest-way-to-put-your-doorbell-on-the-internet/

But I ordered the wrong ones, so a bit longer

NorthernMan54 commented 4 years ago

My doorbell in now complete and working, now for Alexa integration.

https://github.com/NorthernMan54/Doorbell

NorthernMan54 commented 4 years ago

Success, give me a couple of hours to publish and we are good to go

image

NorthernMan54 commented 4 years ago

The last little bit was really straight forward and this is now ready for testing. Support for the doorbell is included in the Beta branch and can be installed with this command.

sudo npm install -g homebridge-alexa@beta

After you install the beta, please ensure routines is set to true in the config.json as well. Then discovery devices again and then go into the Amazon Alexa App to configure your Doorbell and let Alexa know which devices to announce the pressing of the doorbell.

For the testing of this I used the plugin homebridge-camera-ffmpeg, so YMMV with other plugins.

tylerdorazio commented 4 years ago

This is awesome! I will test a bit later and report back. Super fast turnaround here :)

srector13 commented 4 years ago

I tried updating my plugin using home bridge on my raspberry pi and it gave an error that it could not find the homebridge-alexa JSON file and crashed Homebridge. I am running Homebridge Config UI and did the update using the built in terminal in that. Any ideas what the issue could be? When I ran 'sudo npm install -g homebridge-alexa' it downgraded and everything has returned to normal. I was going to test this with the Skybell Plugin. I have been trying to breathe new life into Skybell because my parents bought it for me as a housewarming gift but it is not supported by any platforms.

NorthernMan54 commented 4 years ago

Can you share the error message ?

As the downgrade worked I'm a little bit stumped

Are you running undo sudo mode or not ?

https://github.com/oznu/homebridge-config-ui-x#sudo-mode

If not then the install command would be

npm install homebridge-alexa@beta
srector13 commented 4 years ago

I'm using sudo mode with config ui and using the sudo keyword at the start of the command to up the permissions.

[9/11/2020, 15:34:52] [Alexa] alexaDiscovery - returned 6 devices [9/11/2020, 15:34:52] Error: ENOENT: no such file or directory, open './Desktop/alexa.json' at Object.openSync (fs.js:458:3) at Object.writeFileSync (fs.js:1279:35) at Object. (/usr/local/lib/node_modules/homebridge-alexa/lib/alexaActions.js:133:8) at HAPNodeJSClient.HAPaccessories (/usr/local/lib/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:206:3) at Object.alexaDiscovery (/usr/local/lib/node_modules/homebridge-alexa/lib/alexaActions.js:95:14) at HAPNodeJSClient. (/usr/local/lib/node_modules/homebridge-alexa/lib/alexaActions.js:36:20) at HAPNodeJSClient.emit (events.js:310:20) at HAPNodeJSClient. (/usr/local/lib/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:115:10) at Timeout._onTimeout (/usr/local/lib/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:189:7) at listOnTimeout (internal/timers.js:549:17) at processTimers (internal/timers.js:492:7) [9/11/2020, 15:34:52] Got SIGTERM, shutting down

NorthernMan54 commented 4 years ago

Tks, that's a oops on my part, give me 10 minutes

I was saving the Alexa discovery response to my desktop while coding this up and left the saving of the file behind

[9/11/2020, 15:34:52] Error: ENOENT: no such file or directory, open './Desktop/alexa.json'

NorthernMan54 commented 4 years ago

Fixed in the latest beta, v0.5.10

srector13 commented 4 years ago

Thanks! Can I just say "hats off to you". I have never had a developer respond and fix an issue so quickly before.

NorthernMan54 commented 4 years ago

You caught me at the right moment, sitting with my laptop open and an easy fix. It took all of 10 seconds to comment out the two lines causing the issue. At other times, who knows

PS The error message really help as it pointed out the exact line with the issue.

NorthernMan54 commented 4 years ago

Closing this as a successful implementation. For a sample here is my Door Bell being rang.

And to detect my doorbell being rung I had to build this as I couldn't find an easy way to interface Homebridge and my doorbell without either buying a new doorbell or major wiring in my home.