├── hacs.json ├── README.md ├── apps └── alexa_doorbell.py └── LICENSE /hacs.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Alexa (& Friends) Doorbell 🐔", 3 | "content_in_root" : "false", 4 | "render_readme": "true", 5 | "domains": ["media_player", "binary_sensor", "switch"] 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Alexa (& Friends) Doorbell :chicken: 2 | 3 | [![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs) 4 | 5 | ## New in v1.0.9 : Master Doorbell Switch Override :) 6 | 7 | ### For Sonos, set announce_bell:false (thanks to @5and0) 8 | 9 | Alexa and other smart speakers will notify you like a doorbell, (thus the name, so creative isn't it!) based on a motion sensor placed on your doorway. Ever since we've set this up in our home, we always get praises and surprised looks from our guests when they come. Your home suddenly gets a voice, something like Jarvis ... Awesome! 10 | 11 | You can also :- 12 | - add a door sensor (like the [Ecolink Door Sensor](https://www.amazon.com/Aeotec-Window-Contact-sensors-Battery/dp/B07PDDX3K6/ref=sr_1_16?dchild=1&keywords=eco+wave+door+sensor&qid=1587791320&s=electronics&sr=1-16) or any other) to only ring the bell if the door is currently closed, and has been closed for at least the last 30 seconds. This is so that the bell only rings when someone arrives at your door and not when you step out. 13 | - add an outdoor Alexa (or other smart speaker) to greet your guest with a pleasant message based on the time of day 14 | - add a doorbell (like the [Aeotec Doorbell](https://aeotec.com/z-wave-doorbell/) or any other) to ring when a guest arrives outside your door 15 | 16 | Please ⭐ this repo if you like my work and also check out my other repos like 17 | - [Home Assistant 'STEROIDS' Configuration](https://github.com/UbhiTS/ha-config-ataraxis) 18 | - [Alexa (& Friends) Talking Clock](https://github.com/UbhiTS/ad-alexatalkingclock) 19 | - [Alexa (& Friends) Doorbell](https://github.com/UbhiTS/ad-alexadoorbell) 20 | - [Alexa (& Friends) Door/Window Announce](https://github.com/UbhiTS/ad-alexadoorwindowannounce) 21 | - [Alexa (& Friends) Smart Talking Thermostat](https://github.com/UbhiTS/ad-alexasmarttalkingthermostat) 22 | - [Auto 'Crappy Internet' Rebooter](https://github.com/UbhiTS/ad-autointernetrebooter) 23 | 24 | Also, if you want to see a walkthrough of my Home Assistant configuration, I have my video walkthrough on youtube below 25 | - [Home Automation on 'STEROIDS' : Video Walkthrough](https://youtu.be/qqktLE9_45A) 26 | 27 | ## Installation 28 | **Needs the [Alexa Media Player or Sonos](https://github.com/custom-components/alexa_media_player) integration** 29 | 30 | Use [HACS](https://github.com/custom-components/hacs) or [download](https://github.com/UbhiTS/ad-alexadoorbell) the `alexa_doorbell.py` from inside the `apps` directory to your local `apps` directory, and add the configuration to enable the app. 31 | 32 | ### Basic Config (config/appdaemon/apps/apps.yaml) 33 | ```yaml 34 | alexa_doorbell: 35 | module: alexa_doorbell 36 | class: AlexaDoorbell 37 | door: 38 | motion_sensor: binary_sensor.main_door_motion 39 | home: 40 | alexa: media_player.kitchen_alexa 41 | announce_bell: True # optional, set to False for SONOS 42 | time: 43 | start: "07:00:00" 44 | end: "22:00:00" 45 | ``` 46 | 47 | ### Advanced Config 48 | ```yaml 49 | alexa_doorbell: 50 | module: alexa_doorbell 51 | class: AlexaDoorbell 52 | door: 53 | motion_sensor: binary_sensor.main_door_motion 54 | sensor: binary_sensor.main_door # optional 55 | alexa: media_player.entryway_alexa # optional 56 | announce_bell: False # optional 57 | bell_switch: switch.doorbell_switch # optional 58 | home: 59 | alexa: media_player.kitchen_alexa 60 | doorbell: switch.living_room_doorbell # optional 61 | announce_bell: False # optional 62 | time: 63 | start: "07:00:00" 64 | end: "22:00:00" 65 | debug: false 66 | ``` 67 | 68 | key | optional | type | default | description 69 | -- | -- | -- | -- | -- 70 | `module` | **False** | string | alexa_doorbell | The module name of the app. 71 | `class` | **False** | string | AlexaDoorbell | The name of the Class. 72 | `door\|motion_sensor` | **False** | motion_sensor | | The motion sensor to trigger the app. 73 | `door\|sensor` | True | binary_sensor | | Set to trigger based on door status 74 | `door\|alexa` | True | media_player | | Set your Alexa (or other Smart Speaker) to greet your guest with a pleasant greeting 75 | `door\|announce_bell` | True | bool | False | Prefix bell sound before announcement. Set to false for SONOS 76 | `door\|bell_switch` | True | switch | | Set to a switch to override all checks and ring the doorbell when it's pressed 77 | `home\|alexa` | **False** | media_player | | The Alexa (or other smart speaker) to notify inside the house 78 | `home\|announce_bell` | True | bool | False | Prefix bell sound before announcement. Set to false for SONOS 79 | `home\|doorbell` | True | switch | | Set to ring this doorbell (or switch on a light) 80 | `time\|start` | True | time | 07:00:00 | The time to enable the service. (24h format) 81 | `time\|end` | True | time | 22:00:00 | The time to disable the service. (24h format) 82 | `debug` | True | bool | False | if True, outputs messages to the AppDaemon Log 83 | 84 | ## Thank you! :raised_hands: 85 | This app wouldn't be possible without the amazing work done by the developers and community at **[Home Assistant](https://www.home-assistant.io/)** 86 | 87 | A very special thanks to **Keaton Taylor** and **Alan Tse** whose work on **[Alexa Media Player](https://github.com/custom-components/alexa_media_player)** was the basis of my inspiration and my work to code all the above listed apps! 88 | 89 | If you like my work and feel gracious, you can buy me a beer below ;) 90 | 91 | 92 | Buy Me A Beer 95 | 96 | 97 | # License 98 | [Apache-2.0](LICENSE). By providing a contribution, you agree the contribution is licensed under Apache-2.0. This is required for Home Assistant contributions. 99 | -------------------------------------------------------------------------------- /apps/alexa_doorbell.py: -------------------------------------------------------------------------------- 1 | import appdaemon.plugins.hass.hassapi as hass 2 | from datetime import datetime, time 3 | # 4 | # Alexa Doorbell Controller App 5 | # Developed by @UbhiTS on GitHub 6 | # 7 | # Args: 8 | #alexa_doorbell: 9 | # module: alexa_doorbell 10 | # class: AlexaDoorbell 11 | # door: 12 | # motion_sensor: binary_sensor.main_door_motion 13 | # sensor: binary_sensor.main_door # optional 14 | # alexa: media_player.entryway_alexa # optional 15 | # announce_bell: False # optional 16 | # bell_switch: switch.doorbell_switch # optional 17 | # home: 18 | # alexa: media_player.kitchen_alexa 19 | # doorbell: switch.living_room_doorbell # optional 20 | # announce_bell: False # optional 21 | # time: 22 | # start: "07:00:00" # optional, default 7 AM 23 | # end: "22:00:00" # optional, default 10 PM 24 | # debug: false 25 | 26 | class AlexaDoorbell(hass.Hass): 27 | 28 | def initialize(self): 29 | 30 | self.debug = True; 31 | self.door_motion_sensor = self.args["door"]["motion_sensor"] if "motion_sensor" in self.args["door"] else None 32 | self.door_sensor = self.args["door"]["sensor"] if "sensor" in self.args["door"] else None 33 | self.door_alexa = self.args["door"]["alexa"] if "alexa" in self.args["door"] else None 34 | self.door_alexa_bell = self.args["door"]["announce_bell"] if "announce_bell" in self.args["door"] else False 35 | self.door_bell_switch = self.args["door"]["bell_switch"] if "bell_switch" in self.args["door"] else None 36 | self.home_alexa = self.args["home"]["alexa"] if "alexa" in self.args["home"] else None 37 | self.home_alexa_bell = self.args["home"]["announce_bell"] if "announce_bell" in self.args["home"] else True 38 | self.home_doorbell = self.args["home"]["doorbell"] if "doorbell" in self.args["home"] else None 39 | 40 | self.listen_state(self.evaluate_and_ring_doorbell, self.door_motion_sensor, attribute = "state") 41 | 42 | if self.door_bell_switch: 43 | self.listen_state(self.doorbell_override, self.door_bell_switch, attribute = "state", old = "off", new = "on") 44 | 45 | self.time_start = datetime.strptime("07:00:00", '%H:%M:%S').time() 46 | self.time_end = datetime.strptime("22:00:00", '%H:%M:%S').time() 47 | 48 | if "time" in self.args: 49 | self.time_start = datetime.strptime(self.args["time"]["start"], '%H:%M:%S').time() if "start" in self.args["time"] else self.time_start 50 | self.time_end = datetime.strptime(self.args["time"]["end"], '%H:%M:%S').time() if "end" in self.args["time"] else self.time_end 51 | 52 | self.debug_log(f"\n**** INIT - ALEXA DOORBELL ****\n START {self.time_start.strftime('%H:%M:%S')}\n END {self.time_end.strftime('%H:%M:%S')}\n") 53 | 54 | self.debug = bool(self.args["debug"]) if "debug" in self.args else self.debug 55 | 56 | def evaluate_and_ring_doorbell(self, entity, attribute, old, new, kwargs): 57 | # IF MOTION DETECTED 58 | # CHECK DOOR IS CURRENTLY CLOSED (IF DEFINED) 59 | # CHECK DOOR WAS LAST CLOSED AT LEAST 30 SECONDS AGO 60 | # CHECK TIME IS BETWEEN START TIME AND END TIME 61 | if new == "on": 62 | door_closed = True if self.door_sensor is None else self.get_state(self.door_sensor) == "off" 63 | last_door_closed_seconds = 60 if self.door_sensor is None else datetime.now().timestamp() - self.convert_utc(self.get_state(self.door_sensor, attribute = 'last_changed')).timestamp() 64 | time_okay = self.is_time_okay(self.time_start, self.time_end) 65 | 66 | if door_closed and last_door_closed_seconds > 30: 67 | guest_notify_delay = 5 68 | if time_okay: 69 | if self.home_doorbell is not None: self.run_in(self.doorbell_ring, 0) 70 | self.run_in(self.notify_home, 0) 71 | else: 72 | guest_notify_delay = 0 73 | self.debug_log("OUTSIDE TIME RANGE") 74 | 75 | if self.door_alexa is not None: 76 | self.run_in(self.notify_guest, guest_notify_delay, message = self.guest_greeting(time_okay)) 77 | else: 78 | if not door_closed: 79 | self.debug_log("DOOR IS OPEN") 80 | elif last_door_closed_seconds < 30: 81 | self.debug_log("DOOR CLOSED < 30 SECS AGO") 82 | 83 | 84 | def guest_greeting(self, time_okay): 85 | 86 | hour = datetime.now().hour 87 | 88 | if (not time_okay) or (22 <= hour and hour <= 23) or (0 <= hour and hour <= 4): 89 | greeting = "Hi, Welcome. Please ring the bell if you want to notify the family inside." 90 | elif 5 <= hour and hour <= 11: 91 | greeting = "Good morning. Welcome. I've notified the family. Someone will be at the door shortly." 92 | elif 12 <= hour and hour <= 16: 93 | greeting = "Good afternoon. Welcome. I've notified the family. Someone will be at the door shortly." 94 | elif 17 <= hour and hour <= 21: 95 | greeting = "Good evening. Welcome. I've notified the family. Someone will be at the door shortly." 96 | 97 | return greeting 98 | 99 | 100 | def doorbell_override(self, entity, attribute, old, new, kwargs): 101 | self.call_service("switch/turn_off", entity_id = self.door_bell_switch) 102 | if self.home_doorbell is not None: self.run_in(self.doorbell_ring, 0) 103 | self.run_in(self.notify_home, 0) 104 | self.debug_log("DOORBELL OVERRIDE SWITCH") 105 | 106 | 107 | def doorbell_ring(self, kwargs): 108 | self.call_service("switch/turn_on", entity_id = self.home_doorbell) 109 | self.debug_log("DOORBELL RING") 110 | 111 | 112 | def notify_home(self, kwargs): 113 | self.call_service("notify/alexa_media", data = {"type": "announce" if self.home_alexa_bell else "tts", "method": "all"}, target = self.home_alexa, title = "Home Assistant: Alexa Doorbell", message = "Your attention please. There is someone at the door!") 114 | self.debug_log("NOTIFY HOME") 115 | 116 | 117 | def notify_guest(self, kwargs): 118 | self.call_service("notify/alexa_media", data = {"type": "announce" if self.door_alexa_bell else "tts", "method": "all"}, target = self.door_alexa, title = "Home Assistant: Alexa Doorbell", message = kwargs["message"]) 119 | self.debug_log("NOTIFY GUEST") 120 | 121 | 122 | def is_time_okay(self, start, end): 123 | current_time = datetime.now().time() 124 | if (start < end): 125 | return start <= current_time and current_time <= end 126 | else: 127 | return start <= current_time or current_time <= end 128 | 129 | def debug_log(self, message): 130 | if self.debug: 131 | self.log(message) 132 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------