1
0

sleep-timer.yaml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. blueprint:
  2. name: Sleep Timer
  3. description: Perform one or more actions after a sleep timer expires
  4. domain: automation
  5. input:
  6. input_number:
  7. name: Input Number
  8. description: The input number that determines how many minutes the sleep timer
  9. should last for
  10. selector:
  11. entity:
  12. domain: input_number
  13. timer:
  14. name: Timer
  15. description: The entity that represents the timer itself
  16. selector:
  17. entity:
  18. domain: timer
  19. timer_cancel_action:
  20. name: Action on Timer Cancel
  21. description: The action(s) to run when the timer is canceled
  22. default: []
  23. selector:
  24. action: {}
  25. timer_expire_action:
  26. name: Action on Timer Expire
  27. description: The action(s) to run when the timer expires
  28. default: []
  29. selector:
  30. action: {}
  31. timer_start_action:
  32. name: Action on Timer Start
  33. description: The action(s) to run when the timer starts
  34. default: []
  35. selector:
  36. action: {}
  37. source_url: https://community.home-assistant.io/t/sleep-timer/256463
  38. mode: restart
  39. variables:
  40. slider: !input 'input_number'
  41. slider_value: '{{ states(slider) | int * 60 }}'
  42. trigger:
  43. - platform: state
  44. entity_id: !input 'input_number'
  45. - platform: state
  46. entity_id: !input 'timer'
  47. to: idle
  48. action:
  49. choose:
  50. - conditions:
  51. - condition: template
  52. value_template: '{{ trigger.to_state.state == "idle" }}
  53. '
  54. sequence:
  55. - service: input_number.set_value
  56. data:
  57. entity_id: !input 'input_number'
  58. value: 0
  59. - choose: []
  60. default: !input 'timer_expire_action'
  61. - conditions:
  62. - condition: numeric_state
  63. entity_id: !input 'input_number'
  64. below: 1
  65. sequence:
  66. - service: timer.cancel
  67. data:
  68. entity_id: !input 'timer'
  69. - choose: []
  70. default: !input 'timer_cancel_action'
  71. - conditions:
  72. - condition: numeric_state
  73. entity_id: !input 'input_number'
  74. above: 0
  75. sequence:
  76. - service: timer.start
  77. data:
  78. entity_id: !input 'timer'
  79. duration: '{{ slider_value }}'
  80. - choose: []
  81. default: !input 'timer_start_action'