xangin

Check door open & notify

Apr 27th, 2022 (edited)
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.24 KB | None | 0 0
  1. automation:
  2.   - id: check_door_status
  3.     alias: check_door_status
  4.     description: 定時檢查門
  5.     trigger:
  6.       - platform: time
  7.         at: '10:00'
  8.       - platform: time
  9.         at: '12:00'
  10.       - platform: time
  11.         at: '15:00'
  12.     action:
  13.       - service: notify.line_notify
  14.         data:
  15.           message: >        
  16.             {% if states.sensor.door_open.state != '0' %}
  17.               {{ state_attr("sensor.door_open","attribute") }}開著
  18.             {%- else -%}
  19.               門都關好了!
  20.             {%- endif %}
  21.  
  22. template:          
  23.   - sensor:
  24.       - name: "door_open"
  25.         unique_id: door_open
  26.         icon: mdi:door
  27.         state: >
  28.          {% set doors = [ 'binary_sensor.door_mainbath_contact',
  29.                             'binary_sensor.door_toolbox_contact',
  30.                             'binary_sensor.door_mainroom_contact',
  31.                             'binary_sensor.door_kidsroom_contact',
  32.                             'binary_sensor.door_guestroom_contact',
  33.                             'binary_sensor.door_backyard_contact',
  34.                             'binary_sensor.door_bathroom_contact',
  35.                             'binary_sensor.door_window_sensor_158d000106e9b5',
  36.                             'binary_sensor.door_window_sensor_158d0000f81711',
  37.                           ] %}
  38.           {{ expand(doors) | selectattr('state','eq','on') | list | count }}
  39.         attributes:
  40.           attribute: >
  41.            {% set doors = [ 'binary_sensor.door_mainbath_contact',
  42.                               'binary_sensor.door_toolbox_contact',
  43.                               'binary_sensor.door_mainroom_contact',
  44.                               'binary_sensor.door_kidsroom_contact',
  45.                               'binary_sensor.door_guestroom_contact',
  46.                               'binary_sensor.door_backyard_contact',
  47.                               'binary_sensor.door_bathroom_contact',
  48.                               'binary_sensor.door_window_sensor_158d000106e9b5',
  49.                               'binary_sensor.door_window_sensor_158d0000f81711',
  50.                           ] %}        
  51.             {{ expand(doors) | selectattr('state','eq','on') | map(attribute='name') | list | join('、') }}
Add Comment
Please, Sign In to add comment