-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautomation_house_and_garage_movement.yaml
executable file
·73 lines (68 loc) · 3.88 KB
/
automation_house_and_garage_movement.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
automation:
- id: house_or_garage_movement
alias: 'House or Garage Movement Notification'
mode: single
description: >
Telegram message about house or garage movement
trigger:
- platform: state
id: 'movement'
entity_id:
- input_boolean.house_motion_detected
- input_boolean.garage_motion_detected
to: ~
- platform: time_pattern
id: 'every15'
minutes: "/15"
- platform: homeassistant
id: 'start'
event: start
- platform: event
id: 'reload'
event_type: automation_reloaded
action:
- choose:
# Movement and message already sent
- conditions: "{{ (is_state('input_boolean.house_motion_detected','on') or is_state('input_boolean.garage_motion_detected','on')) and (states('input_text.house_garage_movement_message_id'))|int(0) != 0 }}"
sequence:
- service: telegram_bot.delete_message
data:
message_id: "{{ states('input_text.house_garage_movement_message_id') }}"
chat_id: !secret telegram_chat_id_bruce
- service: telegram_bot.send_message
data:
message_tag: house_garage_movement
target: !secret telegram_chat_id_bruce
title: "{% if is_state('input_boolean.house_motion_detected','on') and is_state('input_boolean.garage_motion_detected','on') %}Movement in the House and Garage{% elif is_state('input_boolean.house_motion_detected','on') %}Movement in the House{% else %}Movement in the Garage{% endif %}"
message: "Latest movement: {{ states('input_text.recently_active_alarm_sensor')}}"
inline_keyboard:
- 'Clear Alert:/clear_movement_alert'
- 'OK:/remove_keyboard'
# Movement - First Message
- conditions: "{{ (is_state('input_boolean.house_motion_detected','on') or is_state('input_boolean.garage_motion_detected','on')) and ((states('input_text.house_garage_movement_message_id')|int(0)) == 0) }}"
sequence:
- service: telegram_bot.send_message
data:
message_tag: house_garage_movement
target: !secret telegram_chat_id_bruce
title: "{% if is_state('input_boolean.house_motion_detected','on') and is_state('input_boolean.garage_motion_detected','on') %}Movement in the House and Garage{% elif is_state('input_boolean.house_motion_detected','on') %}Movement in the House{% else %}Movement in the Garage{% endif %}"
message: "Latest movement: {{ states('input_text.recently_active_alarm_sensor')}}"
inline_keyboard:
- 'Clear Alert:/clear_movement_alert'
- 'OK:/remove_keyboard'
# Movement Cleared - Message previously Sent
- conditions: "{{ (is_state('input_boolean.house_motion_detected','off') and is_state('input_boolean.garage_motion_detected','off')) and (states('input_text.house_garage_movement_message_id')|int(0)) != 0 }}"
sequence:
- service: telegram_bot.delete_message
data:
message_id: "{{ states('input_text.house_garage_movement_message_id') }}"
chat_id: !secret telegram_chat_id_bruce
- service: telegram_bot.send_message
data:
target: !secret telegram_chat_id_bruce
message: "Movement alert Cleared"
- service: input_text.set_value
target:
entity_id: input_text.house_garage_movement_message_id
data:
value: ''