Advertisement
diyfuturism

DIYFUTURISM.COM - USEFUL SENSOR - META MOTION SENSOR

Dec 15th, 2017
1,953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.50 KB | None | 0 0
  1. #
  2. # DIYFUTURISM.COM
  3. #
  4. # USEFUL SENSOR: META MOTION SENSOR, MOTION LAST SEEN
  5. #
  6.  
  7. #
  8. # in configuration.yaml
  9. #
  10. binary_sensor: !include binary_sensor.yaml
  11. variable:
  12.   last_motion:
  13.     value: 'Unknown'
  14.     restore: true
  15.     attributes:
  16.       icon: mdi:map-marker
  17.       name: "Last Motion"
  18. #
  19. # in automation.yaml
  20. #
  21. # Update Last Motion variable
  22. - alias: "Update Last Motion"
  23.   trigger:
  24.     - platform: state
  25.       entity_id: binary_sensor.bathroom_motion, binary_sensor.closet_motion, binary_sensor.entry_motion_meta, binary_sensor.dining_motion_meta, binary_sensor.kitchen_motion_meta, binary_sensor.livingroom_motion_meta, binary_sensor.office_motion
  26.       to: 'on'
  27.   action:
  28.     - service: variable.set_variable
  29.       data:
  30.         variable: last_motion
  31.         attributes_template: >
  32.            {
  33.               "history_1": "{{ variable.state }}",
  34.               "history_2": "{{ variable.attributes.history_1 }}",
  35.               "history_3": "{{ variable.attributes.history_2 }}"
  36.             }
  37.       data_template:
  38.         value: "{{ trigger.to_state.attributes.friendly_name }}"
  39. #
  40. # in binary_sensor.yaml
  41. #
  42.     kitchen_motion_meta:
  43.       friendly_name: 'Kitchen Motion'
  44.       device_class: motion
  45.       value_template: >-
  46.         {%- if is_state("binary_sensor.kitchen_motion", "on")
  47.         or is_state("binary_sensor.fridge_motion", "on")
  48.         or is_state("binary_sensor.crawl_space_door", "on")
  49.           -%}
  50.         True
  51.         {%- else -%}
  52.         False
  53.         {%- endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement