From 49f5fa88d1e8bbf8b635840780d068bb2519732b Mon Sep 17 00:00:00 2001 From: Nathan Gardiner Date: Sat, 9 May 2020 21:03:06 +1000 Subject: [PATCH 1/4] Update home_assistant.md - Removed the static not_home location from the device_tracker definition which fixes #695 - Added Garage Door automation - Added automation for doors and windows open which would address #698 (for HomeAssistant users at least) --- website/docs/integrations/home_assistant.md | 137 +++++++++++++++++++- 1 file changed, 136 insertions(+), 1 deletion(-) diff --git a/website/docs/integrations/home_assistant.md b/website/docs/integrations/home_assistant.md index 40edb787ab..ffc9272d1b 100644 --- a/website/docs/integrations/home_assistant.md +++ b/website/docs/integrations/home_assistant.md @@ -42,7 +42,6 @@ The following provides an automation to update the location of the `device_track - service: device_tracker.see data_template: dev_id: tesla_location - location_name: not_home gps: [ "{{ states.sensor.tesla_latitude.state }}", @@ -366,3 +365,139 @@ The below is the Lovelace UI configuration used to make the example screenshot a - entity: proximity.home_tesla name: Distance to Home ``` + +## Useful Automations + +The below automations leverage TeslaMate MQTT topics to provide some useful automations + +### Garage Door Automation based on Tesla location + +This automation triggers when the Tesla transitions from not_home to home. This means that the vehicle would have had to have been outside of the home zone previously, and returned home. You may want to add conditions here to improve accuracy, such as time of day. + +``` +- alias: Open garage if car returns home + initial_state: on + trigger: + - platform: state + entity_id: switch.garage_door_switch + from: 'not_home' + to: 'home' + action: + - service: switch.turn_off + entity_id: switch.garage_door_switch +``` + +### Notification for Doors and Windows left open + +The following set of automations and scripts will detect when a Tesla door, frunk, trunk or window is left open. The script will notify you after the defined time period (by default, 5 minutes). If you would like to customize how the notification is performed, you can edit the ```notify_tesla_open``` script which is called by all of the four notifications. + +By default, the script will repeatedly notify every 5 minutes. Remove the recursive ```script.turn_on``` sequence in the ```notify_tesla_open``` script if you'd only like to be informed once. + +We add the random 30 second interval after each notification to avoid clobbering the notification script when we have multiple things open at once. For example, opening the door will open the door and the window. If we don't delay the calls, we will only get a message about the window (as it is the last call to the script) and if we then close the window, we won't get notifications about other things left open. This results in more notifications but less chance on missing out on knowing something was left open. + +#### automation.yaml + +``` +- alias: Set timer if teslamate reports something is open to alert us + initial_state: on + trigger: + - platform: mqtt + topic: teslamate/cars/1/windows_open + payload: 'true' + - platform: mqtt + topic: teslamate/cars/1/doors_open + payload: 'true' + - platform: mqtt + topic: teslamate/cars/1/trunk_open + payload: 'true' + - platform: mqtt + topic: teslamate/cars/1/frunk_open + payload: 'true' + action: + - service: script.turn_on + data_template: + entity_id: script.notify_tesla_{{trigger.topic.split('/')[3]}} + +- alias: Cancel notification if said door/window is closed + initial_state: on + trigger: + - platform: mqtt + topic: teslamate/cars/1/windows_open + payload: 'false' + - platform: mqtt + topic: teslamate/cars/1/doors_open + payload: 'false' + - platform: mqtt + topic: teslamate/cars/1/trunk_open + payload: 'false' + - platform: mqtt + topic: teslamate/cars/1/frunk_open + payload: 'false' + action: + - service: script.turn_off + data_template: + entity_id: script.notify_tesla_{{trigger.topic.split('/')[3]}} +``` + +#### script.yaml + +``` +notify_tesla_open: + alias: "Notify when something on the tesla is left open" + sequence: + - service: notify.notify_group + data_template: + title: "Tesla Notification" + message: "You have left the {{ whatsopen }} open on the Tesla!" + - service: script.turn_on + data_template: + entity_id: script.notify_tesla_{{ whatsopen }}_open + +notify_tesla_doors_open: + sequence: + - delay: + minutes: 5 + - delay: + seconds: "{{ range(0, 30)|random|int }}" + - service: script.turn_on + entity_id: script.notify_tesla_open + data: + variables: + whatsopen: "doors" + +notify_tesla_frunk_open: + sequence: + - delay: + minutes: 5 + - delay: + seconds: "{{ range(0, 30)|random|int }}" + - service: script.turn_on + entity_id: script.notify_tesla_open + data: + variables: + whatsopen: "frunk" + +notify_tesla_trunk_open: + sequence: + - delay: + minutes: 5 + - delay: + seconds: "{{ range(0, 30)|random|int }}" + - service: script.turn_on + entity_id: script.notify_tesla_open + data: + variables: + whatsopen: "trunk" + +notify_tesla_windows_open: + sequence: + - delay: + minutes: 5 + - delay: + seconds: "{{ range(0, 30)|random|int }}" + - service: script.turn_on + entity_id: script.notify_tesla_open + data: + variables: + whatsopen: "windows" +``` From 1f37d14acd0572b39eea5ce17cdfe35957e967df Mon Sep 17 00:00:00 2001 From: Adrian Kumpf Date: Tue, 19 May 2020 19:30:38 +0200 Subject: [PATCH 2/4] Enalbe syntax highlighting --- website/docs/integrations/home_assistant.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/integrations/home_assistant.md b/website/docs/integrations/home_assistant.md index ffc9272d1b..e3b04123b8 100644 --- a/website/docs/integrations/home_assistant.md +++ b/website/docs/integrations/home_assistant.md @@ -397,7 +397,7 @@ We add the random 30 second interval after each notification to avoid clobbering #### automation.yaml -``` +```yml title="automation.yaml" - alias: Set timer if teslamate reports something is open to alert us initial_state: on trigger: From 19146b896b4c6dc392d1537e501ce805ac8a5585 Mon Sep 17 00:00:00 2001 From: Adrian Kumpf Date: Tue, 19 May 2020 19:30:51 +0200 Subject: [PATCH 3/4] Enalbe syntax highlighting --- website/docs/integrations/home_assistant.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/integrations/home_assistant.md b/website/docs/integrations/home_assistant.md index e3b04123b8..6078c38469 100644 --- a/website/docs/integrations/home_assistant.md +++ b/website/docs/integrations/home_assistant.md @@ -374,7 +374,7 @@ The below automations leverage TeslaMate MQTT topics to provide some useful auto This automation triggers when the Tesla transitions from not_home to home. This means that the vehicle would have had to have been outside of the home zone previously, and returned home. You may want to add conditions here to improve accuracy, such as time of day. -``` +```yml title="automation.yaml" - alias: Open garage if car returns home initial_state: on trigger: From 705be86983dca6d388f49ed413e5e6496d17a70a Mon Sep 17 00:00:00 2001 From: Adrian Kumpf Date: Tue, 19 May 2020 19:30:58 +0200 Subject: [PATCH 4/4] Enalbe syntax highlighting --- website/docs/integrations/home_assistant.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/integrations/home_assistant.md b/website/docs/integrations/home_assistant.md index 6078c38469..1625647ea5 100644 --- a/website/docs/integrations/home_assistant.md +++ b/website/docs/integrations/home_assistant.md @@ -441,7 +441,7 @@ We add the random 30 second interval after each notification to avoid clobbering #### script.yaml -``` +```yml title="script.yaml" notify_tesla_open: alias: "Notify when something on the tesla is left open" sequence: