Advertisement
rootiest

tempate examples

Nov 22nd, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 4.40 KB | None | 0 0
  1. template:
  2. # These first few combine several binary sensors into a single entity that reflects the state of all the sensors
  3. # I also add each sensor as an attribute so that the individual states are visible under more info.
  4.  
  5. # This sensor returns the aggregated states of all the contact sensors
  6.   - binary_sensor:
  7.       - unique_id: ingress_points_group
  8.         name: Ingress Points
  9.         device_class: safety
  10.         state: >
  11.          {% set sensors = [states.binary_sensor.front_door_sensor,
  12.                             states.binary_sensor.kitchen_window_north,
  13.                             states.binary_sensor.side_window,
  14.                             states.binary_sensor.living_room_window_north] %}
  15.           {{ sensors | selectattr('state','eq','on') | list | count > 0 }}
  16.         attributes:
  17.           Front Door: >
  18.            {{ states('binary_sensor.front_door_sensor') }}
  19.           Kitchen North Window: >
  20.            {{ states('binary_sensor.kitchen_window_north') }}
  21.           Living Room Side Window: >
  22.            {{ states('binary_sensor.side_window') }}
  23.           Living Room North Window: >
  24.            {{ states('binary_sensor.living_room_window_north') }}
  25.  
  26. # This sensor returns the aggregated states of all the motion sensors
  27.   - binary_sensor:
  28.       - unique_id: motion_group
  29.         device_class: motion
  30.         name: Motion Sensors
  31.         state: >
  32.          {% set sensors = [states.binary_sensor.kitchen_motion,
  33.                             states.binary_sensor.living_room_motion,
  34.                             states.binary_sensor.pir_sensor] %}
  35.           {{ sensors | selectattr('state','eq','on') | list | count > 0 }}
  36.         attributes:
  37.           Living Room Motion: >
  38.            {{ states('binary_sensor.living_room_motion') }}
  39.           Kitchen Motion: >
  40.            {{ states('binary_sensor.kitchen_motion') }}
  41.           Hall Motion: >
  42.            {{ states('binary_sensor.pir_sensor') }}
  43.  
  44. # This sensor returns the aggregated states of all the contact and motion sensors
  45.   - binary_sensor:
  46.       - unique_id: door_motion_group
  47.         device_class: safety
  48.         name: Doors and Motion Sensors
  49.         state: >
  50.          {% set sensors = [states.binary_sensor.kitchen_motion,
  51.                             states.binary_sensor.living_room_motion,
  52.                             states.binary_sensor.front_door_sensor,
  53.                             states.binary_sensor.kitchen_window_north,
  54.                             states.binary_sensor.side_window,
  55.                             states.binary_sensor.living_room_window_north,
  56.                             states.binary_sensor.pir_sensor] %}
  57.           {{ sensors | selectattr('state','eq','on') | list | count > 0 }}
  58.         attributes:
  59.           Living Room Motion: >
  60.            {{ states('binary_sensor.living_room_motion') }}
  61.           Kitchen Motion: >
  62.            {{ states('binary_sensor.kitchen_motion') }}
  63.           Hall Motion: >
  64.            {{ states('binary_sensor.pir_sensor') }}
  65.           Front Door: >
  66.            {{ states('binary_sensor.front_door_sensor') }}
  67.           Kitchen North Window: >
  68.            {{ states('binary_sensor.kitchen_window_north') }}
  69.           Living Room Side Window: >
  70.            {{ states('binary_sensor.side_window') }}
  71.           Living Room North Window: >
  72.            {{ states('binary_sensor.living_room_window_north') }}
  73.  
  74.  
  75. # This last sensor I included as an example of a sensor that returns a text value rather than a binary.
  76.  
  77. # This sensor returns a text representation of the current time of day
  78.   - sensor:
  79.       - unique_id: period_of_day
  80.         name: Period of the day
  81.         state: >
  82.          {% if (as_timestamp(state_attr('sun.sun','next_dusk'))) -
  83.                 (as_timestamp(state_attr('sun.sun','next_setting'))) < 0 %}
  84.             Dusk
  85.           {% elif (as_timestamp(state_attr('sun.sun','next_rising'))) -
  86.                   (as_timestamp(state_attr('sun.sun','next_dawn'))) < 0 %}
  87.             Dawn
  88.           {% elif (state_attr('sun.sun', 'elevation')) < 0 %}
  89.             Night
  90.           {% else %}
  91.             Day
  92.           {% endif %}
  93.         icon: >
  94.          {% set period = states('sensor.period_of_day') %}
  95.           {% if period == 'Dusk' %} mdi:weather-sunset-down
  96.           {% elif period == 'Dawn' %} mdi:weather-sunset-up
  97.           {% elif period == 'Night' %}  mdi:weather-night
  98.           {% else %} mdi:weather-sunny
  99.           {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement