Advertisement
Guest User

ha-variable-automation

a guest
Jul 17th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 7.06 KB | None | 0 0
  1.  
  2. ## https://github.com/rogro82/hass-variables
  3.  
  4.  
  5. variable:
  6.   last_arrive_dwmip:
  7.     value: 'Never'
  8.     restore: true
  9.   last_depart_dwmip:
  10.     value: 'Never'
  11.     restore: true
  12.   last_arrive_jlwip:
  13.     value: 'Never'
  14.     restore: true
  15.   last_depart_jlwip:
  16.     value: 'Never'
  17.     restore: true
  18.   last_motion_location:
  19.     value: 'None'
  20.     restore: true
  21.   last_door_location:
  22.     value: 'None'
  23.     restore: true
  24.   last_motion_time:
  25.     value: 'None'
  26.     restore: true
  27.   last_alarm_location:
  28.     value: 'None'
  29.     restore: true
  30.   last_alarm_time:
  31.     value: 'None'
  32.     restore: true
  33.   last_living_room_51_20:
  34.     value: 'Never'
  35.     restore: true
  36.   last_kitchen_52_20:
  37.     value: 'Never'
  38.     restore: true
  39.   last_bedroom_53_20:
  40.     value: 'Never'
  41.     restore: true
  42.   last_office_56_20:
  43.     value: 'Never'
  44.     restore: true
  45.   last_garage_57_20:
  46.     value: 'Never'
  47.     restore: true
  48.   last_porch_54_20:
  49.     value: 'Never'
  50.     restore: true
  51.   last_guestroom_55_20:
  52.     value: 'Never'
  53.     restore: true
  54.   last_baby_58_20:
  55.     value: 'Never'
  56.     restore: true
  57.   last_living_room_occupancy:
  58.     value: 'Never'
  59.     restore: true
  60.   last_kitchen_occupancy:
  61.     value: 'Never'
  62.     restore: true
  63.   last_bedroom_occupancy:
  64.     value: 'Never'
  65.     restore: true
  66.   last_guest_room_occupancy:
  67.     value: 'Never'
  68.     restore: true
  69.   last_office_occupancy:
  70.     value: 'Never'
  71.     restore: true
  72.   last_dining_occupancy:
  73.     value: 'Never'
  74.     restore: true
  75.   last_door_81_1:
  76.     value: 'Never'
  77.     restore: true
  78.   last_door_82_1:
  79.     value: 'Never'
  80.     restore: true
  81.   last_porch_54_44:
  82.     value: 'Never'
  83.     restore: true
  84.   last_garage_57_25:
  85.     value: 'Never'
  86.     restore: true
  87.  
  88.  
  89. automation:
  90.   - alias: "Motion Update"
  91.     trigger:
  92.       - platform: state
  93.         entity_id: binary_sensor.living_room_51_20
  94.         to: 'on'
  95.       - platform: state
  96.         entity_id: binary_sensor.kitchen_52_20
  97.         to: 'on'
  98.       - platform: state
  99.         entity_id: binary_sensor.bedroom_53_20
  100.         to: 'on'
  101.       - platform: state
  102.         entity_id: binary_sensor.porch_54_20
  103.         to: 'on'
  104.       - platform: state
  105.         entity_id: binary_sensor.guestroom_55_20
  106.         to: 'on'
  107.       - platform: state
  108.         entity_id: binary_sensor.office_56_20
  109.         to: 'on'
  110.       - platform: state
  111.         entity_id: binary_sensor.garage_57_20
  112.         to: 'on'
  113.       - platform: state
  114.         entity_id: binary_sensor.baby_58_20
  115.         to: 'on'
  116.       - platform: state
  117.         entity_id: binary_sensor.living_room_occupancy
  118.         to: 'on'
  119.       - platform: state
  120.         entity_id: binary_sensor.bedroom_occupancy
  121.         to: 'on'
  122.       - platform: state
  123.         entity_id: binary_sensor.kitchen_occupancy
  124.         to: 'on'
  125.       - platform: state
  126.         entity_id: binary_sensor.guest_room_occupancy
  127.         to: 'on'
  128.       - platform: state
  129.         entity_id: binary_sensor.office_occupancy
  130.         to: 'on'
  131.       - platform: state
  132.         entity_id: binary_sensor.dining_occupancy
  133.         to: 'on'
  134.       # - platform: state
  135.       #   entity_id: binary_sensor.door_81_1
  136.       #   to: 'on'
  137.       # - platform: state
  138.       #   entity_id: binary_sensor.door_82_1
  139.       #   to: 'on'
  140.       # - platform: state
  141.       #   entity_id: binary_sensor.porch_54_44
  142.       #   to: 'on'
  143.     action:
  144.       - service: variable.set_variable
  145.         data_template:
  146.           variable: '{{ "last_" + trigger.entity_id.split(".")[1] }}'
  147.           value: '{{ as_timestamp(now()) | timestamp_custom("%b %d %-I:%M %p") }}'
  148.           attributes_template: >
  149.            {
  150.               "history_1": "{{ states('variable.last_' + trigger.entity_id.split('.')[1]) }}",
  151.               "history_2": "{{ state_attr('variable.last_' + trigger.entity_id.split('.')[1],'history_1') }}",
  152.               "history_3": "{{ state_attr('variable.last_' + trigger.entity_id.split('.')[1],'history_2') }}"
  153.             }
  154.       - service: variable.set_variable
  155.         data_template:
  156.           variable: 'last_motion_location'
  157.           value: '{{ trigger.to_state.attributes.friendly_name }} @ {{ as_timestamp(now()) | timestamp_custom("%b %d %-I:%M %p") }}'
  158.           attributes_template: >
  159.            {
  160.               "entity_id": "{{ trigger.entity_id }}",
  161.               "friendly_name": "{{ trigger.to_state.attributes.friendly_name }}",
  162.               "time": "{{ as_timestamp(now()) | timestamp_custom('%b %d %-I:%M %p') }}",
  163.               "history_1": "{{ states('variable.last_motion_location') }}",
  164.               "history_2": "{{ state_attr('variable.last_motion_location','history_1') }}",
  165.               "history_3": "{{ state_attr('variable.last_motion_location','history_2') }}"
  166.             }
  167.       ### Add alarm condition update here
  168.  
  169.   - alias: "Door Update"
  170.     trigger:
  171.       - platform: state
  172.         entity_id: binary_sensor.door_81_1
  173.         to: 'on'
  174.       - platform: state
  175.         entity_id: binary_sensor.door_82_1
  176.         to: 'on'
  177.       - platform: state
  178.         entity_id: binary_sensor.porch_54_44
  179.         to: 'on'
  180.       - platform: state
  181.         entity_id: cover.garage_57_25
  182.         to: 'open'
  183.     action:
  184.       - service: variable.set_variable
  185.         data_template:
  186.           variable: '{{ "last_" + trigger.entity_id.split(".")[1] }}'
  187.           value: '{{ as_timestamp(now()) | timestamp_custom("%b %d %-I:%M %p") }}'
  188.           attributes_template: >
  189.            {
  190.               "history_1": "{{ states('variable.last_' + trigger.entity_id.split('.')[1]) }}",
  191.               "history_2": "{{ state_attr('variable.last_' + trigger.entity_id.split('.')[1],'history_1') }}",
  192.               "history_3": "{{ state_attr('variable.last_' + trigger.entity_id.split('.')[1],'history_2') }}"
  193.             }
  194.       - service: variable.set_variable
  195.         data_template:
  196.           variable: 'last_door_location'
  197.           value: '{{ trigger.to_state.attributes.friendly_name }} @ {{ as_timestamp(now()) | timestamp_custom("%b %d %-I:%M %p") }}'
  198.           attributes_template: >
  199.            {
  200.               "entity_id": "{{ trigger.entity_id }}",
  201.               "friendly_name": "{{ trigger.to_state.attributes.friendly_name }}",
  202.               "time": "{{ as_timestamp(now()) | timestamp_custom('%b %d %-I:%M %p') }}",
  203.               "history_1": "{{ states('variable.last_door_location') }} @ {{ state_attr('variable.last_door_location','at') }}",
  204.               "history_2": "{{ state_attr('variable.last_door_location','history_1') }}",
  205.               "history_3": "{{ state_attr('variable.last_door_location','history_2') }}"
  206.             }
  207.       ### Add alarm condition update here
  208.       - service: notify.pushbullet
  209.         data_template:
  210.           title: >
  211.            {{trigger.to_state.attributes.friendly_name }} door opened at house.
  212.           message: >
  213.            {{ trigger.entity_id }} opened at
  214.             {{ as_timestamp(now()) |timestamp_custom("%b %d %-I:%M %p") }} last opened at
  215.             {{ states('variable.last_' + trigger.entity_id.split('.')[1]) }}.      
  216.  
  217. homeassistant:
  218.   customize_glob:
  219.     "variable.last_*":
  220.       friendly_name: "Last"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement