Advertisement
Guest User

Evening Routine: Lock Doors and Turn Off Lights

a guest
Jun 6th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. alias: "Evening Routine: Lock Doors and Turn Off Lights"
  2. description: >-
  3. This automation locks only unlocked doors at 10:00 PM, turns off lights and
  4. switches that are on at 11:00 PM, and turns off specific lights at 12:00 AM if
  5. they are on. It also sends notifications when doors are locked.
  6. trigger:
  7. - platform: time
  8. at: "22:00:00"
  9. id: lock_doors
  10. - platform: time
  11. at: "23:00:00"
  12. id: lights_off
  13. - platform: time
  14. at: "00:00:00"
  15. id: midnight_lights_off
  16. condition: []
  17. action:
  18. - choose:
  19. - conditions:
  20. - condition: trigger
  21. id: lock_doors
  22. sequence:
  23. - variables:
  24. unlocked_doors: >-
  25. {{ expand([
  26. "lock.bedroom_closet_door_lock",
  27. "lock.front_door_lock",
  28. "lock.laundry_room_door_lock",
  29. "lock.rear_door_lock",
  30. "lock.sunroom_door_lock"
  31. ]) | selectattr('state', 'eq', 'unlocked') |
  32. map(attribute='entity_id') | list }}
  33. door_names: >-
  34. {{ unlocked_doors | map('device_id') | map('device_attr',
  35. 'name') | list | join(', ') }}
  36. - condition: template
  37. value_template: "{{ unlocked_doors | length > 0 }}"
  38. - service: lock.lock
  39. target:
  40. entity_id: "{{ unlocked_doors }}"
  41. - service: notify.mobile_app_pixel_9
  42. data:
  43. title: Door Lock Notification
  44. message: >-
  45. {% if unlocked_doors | length > 0 %}
  46. Locked doors: {{ door_names }}
  47. {% else %}
  48. All doors were already locked.
  49. {% endif %}
  50. - service: media_player.play_media
  51. enabled: false
  52. target:
  53. entity_id: media_player.ha_group
  54. data:
  55. media_content_id: >-
  56. media-source://tts/cloud?message=All+unlocked+doors+have+been+locked&language=en-US&voice=JennyNeural
  57. media_content_type: provider
  58. metadata:
  59. title: All unlocked doors have been locked
  60. thumbnail: https://brands.home-assistant.io/_/cloud/logo.png
  61. media_class: app
  62. navigateIds:
  63. - {}
  64. - media_content_type: app
  65. media_content_id: media-source://tts
  66. - media_content_type: provider
  67. media_content_id: >-
  68. media-source://tts/cloud?message=All+unlocked+doors+have+been+locked&language=en-US&voice=JennyNeural
  69. - conditions:
  70. - condition: trigger
  71. id: lights_off
  72. sequence:
  73. - variables:
  74. all_entities: >-
  75. {{ expand([
  76. "switch.hall_light",
  77. "switch.office_light",
  78. "switch.attic_hallway_light",
  79. "switch.hall_bath_exhaust_fan",
  80. "switch.foyer_light",
  81. "switch.sunroom_ceiling_light",
  82. "switch.sunroom_ceiling_fan",
  83. "switch.dining_room_light",
  84. "switch.kitchen_light",
  85. "switch.kitchen_sink_light",
  86. "switch.kitchen_pantry_light",
  87. "switch.laundry_room_light",
  88. "switch.garage_lights",
  89. "switch.bedroom_2_ceiling_fan",
  90. "switch.bedroom_2_lights",
  91. "switch.attic_garage_light",
  92. "switch.bathroom_mirror",
  93. "switch.hall_bath_light",
  94. "switch.landscape_lighting",
  95. "switch.office_ceiling_light",
  96. "switch.bills_desk",
  97. "switch.office_lamps",
  98. "light.hue_ambiance_lamp_1",
  99. "light.floor_lamps_group",
  100. "light.living_room",
  101. "light.office_lamp_1",
  102. "light.office_lamp_2",
  103. "light.bedroom_fado_lamp",
  104. "light.foyer_lamp",
  105. "light.bedroom_bedside_lamps_group",
  106. "light.bedroom_reading_lamp",
  107. "light.bedroom_dresser_lamp",
  108. "light.sunroom_lamp",
  109. "light.sofa_backlight",
  110. "light.govee_h612f",
  111. "light.office_lamps"
  112. ]) | selectattr('state', 'eq', 'on') |
  113. map(attribute='entity_id') | list }}
  114. - condition: template
  115. value_template: "{{ all_entities | length > 0 }}"
  116. - service: homeassistant.turn_off
  117. target:
  118. entity_id: "{{ all_entities }}"
  119. - delay:
  120. seconds: 5
  121. - service: scene.turn_on
  122. target:
  123. entity_id: scene.outside_lights_off
  124. - conditions:
  125. - condition: trigger
  126. id: midnight_lights_off
  127. sequence:
  128. - variables:
  129. midnight_lights: >-
  130. {{ expand([
  131. "light.light_bars_1",
  132. "light.bed_lights",
  133. "light.bedroom_dresser_under_light"
  134. ]) | selectattr('state', 'eq', 'on') |
  135. map(attribute='entity_id') | list }}
  136. - condition: template
  137. value_template: "{{ midnight_lights | length > 0 }}"
  138. - service: homeassistant.turn_off
  139. target:
  140. entity_id: "{{ midnight_lights }}"
  141. mode: single
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement