photo64

Check Doors

Jul 22nd, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. alias: Check Doors Are Locked
  2. description: ""
  3. triggers:
  4. - trigger: state
  5. entity_id:
  6. - input_button.test_button
  7. conditions: []
  8. actions:
  9. - variables:
  10. unlocked_doors: |
  11. {% set unlocked = namespace(lst=[]) %}
  12. {% for lock_entity in states.lock %}
  13. {% if state_attr(lock_entity.entity_id, 'lock_state') == 'unlocked' or states(lock_entity.entity_id) == 'unlocked' %}
  14. {% set unlocked.lst = unlocked.lst + [state_attr(lock_entity.entity_id, 'friendly_name') | default(lock_entity.entity_id.split('.')[1] | replace('_', ' ') | title)] %}
  15. {% endif %}
  16. {% endfor %}
  17. {{ unlocked.lst }}
  18.  
  19. - choose:
  20. - conditions:
  21. - condition: template
  22. value_template: "{{ unlocked_doors | length > 0 }}"
  23. sequence:
  24. - action: assist_satellite.ask_question
  25. metadata: {}
  26. data:
  27. question: |
  28. {% if unlocked_doors | length == 1 %}
  29. It looks like the {{ unlocked_doors[0] }} is unlocked. Would you like me to lock it?
  30. {% else %}
  31. It looks like these doors are unlocked: {{ unlocked_doors | join(', ') }}. Would you like me to lock them?
  32. {% endif %}
  33. preannounce: true
  34. entity_id: assist_satellite.seeed_respeaker_satellite2_assist_satellite
  35. answers:
  36. - id: yes_lock
  37. sentences:
  38. - "yes"
  39. - please lock them
  40. - lock them
  41. - yeah
  42. - affirmative
  43. - id: no_dont_lock
  44. sentences:
  45. - "no"
  46. - don't lock them
  47. - leave them
  48. - negative
  49. response_variable: door_lock_response
  50. continue_on_error: true
  51. - choose:
  52. - conditions:
  53. - condition: template
  54. value_template: "{{ door_lock_response.id == 'yes_lock' }}"
  55. sequence:
  56. - action: lock.lock
  57. metadata: {}
  58. data: {}
  59. target:
  60. entity_id: >
  61. {% set lock_entities = [] %} {% for door_name in
  62. unlocked_doors %}
  63. {% for entity_id in states.lock %}
  64. {% if state_attr(entity_id, 'friendly_name') == door_name or entity_id.split('.')[1] | replace('_', ' ') | title == door_name %}
  65. {% set lock_entities = lock_entities + [entity_id] %}
  66. {% endif %}
  67. {% endfor %}
  68. {% endfor %} {{ lock_entities }}
  69. - action: assist_satellite.announce
  70. metadata: {}
  71. data:
  72. message: "\"Okay, I'm locking the doors.\""
  73. preannounce: true
  74. target:
  75. entity_id: >-
  76. assist_satellite.seeed_respeaker_satellite2_assist_satellite
  77. - conditions:
  78. - condition: template
  79. value_template: "{{ door_lock_response.id == 'no_dont_lock' }}"
  80. sequence:
  81. - action: assist_satellite.announce
  82. metadata: {}
  83. data:
  84. message: Understood. I will not lock them.
  85. preannounce: true
  86. target:
  87. entity_id: >-
  88. assist_satellite.seeed_respeaker_satellite2_assist_satellite
  89. - conditions:
  90. - condition: template
  91. value_template: "{{ door_lock_response.id is none }}"
  92. sequence:
  93. - action: assist_satellite.announce
  94. metadata: {}
  95. data:
  96. message: I didn't catch that. Please check your doors.
  97. preannounce: true
  98. target:
  99. entity_id: >-
  100. assist_satellite.seeed_respeaker_satellite2_assist_satellite
  101. default:
  102. - action: assist_satellite.announce
  103. metadata: {}
  104. data:
  105. message: All doors are currently locked
  106. preannounce: true
  107. target:
  108. entity_id: assist_satellite.seeed_respeaker_satellite2_assist_satellite
  109. mode: single
Advertisement
Add Comment
Please, Sign In to add comment