xangin

Notify every 2 mins while door open

Jul 6th, 2021 (edited)
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.51 KB | None | 0 0
  1. input_number:
  2.   mins_count:
  3.     name: mins_count
  4.     initial: 0
  5.     min: 0
  6.     max: 60
  7.     step: 2
  8.    
  9. automation:
  10.   alias: Notify every 2 mins while door open
  11.   trigger:
  12.     - entity_id: binary_sensor.your_door
  13.       platform: state
  14.       to: 'on'    
  15.       for:
  16.         minutes: 2
  17.   mode: single
  18.   action:
  19.    #reset count
  20.     - service: input_number.set_value
  21.       target:                
  22.         entity_id: input_number.mins_count    
  23.       data:
  24.         value: 0    
  25.     - repeat:
  26.         while:
  27.           - condition: state
  28.             entity_id: binary_sensor.your_door
  29.             state: 'on'
  30.           # Don't do it too many times
  31.           - condition: template
  32.             value_template: "{{ repeat.index <= 30 }}"  
  33.         sequence:      
  34.           #mins + 2
  35.           - service: input_number.increment
  36.             target:                
  37.               entity_id: input_number.mins_count
  38.           - service: notify.line_notify
  39.             data:
  40.               message: 門已開了{{ states.input_number.mins_count.state|int }}分鐘了,趕快關!
  41.           # Wait for sensor to change to 'off' up to 2 minutes before continuing to execute
  42.           - wait_template: "{{ is_state('binary_sensor.your_door', 'off') }}"
  43.             timeout: "00:02:00"
  44.     #if repeat>30 make sure notify won't send
  45.     - condition: state
  46.       entity_id: binary_sensor.your_door
  47.       state: 'off'
  48.     - service: notify.line_notify
  49.       data:
  50.         message: 門已關              
  51.  
  52.  
Add Comment
Please, Sign In to add comment