Advertisement
Guest User

Untitled

a guest
Jan 6th, 2023
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.26 KB | None | 0 0
  1. 3.
  2. - platform: template
  3.   sensors:
  4.     person1_destination:
  5.       friendly_name: "Person 1 Destination"
  6.       value_template: "{{ state_attr('calendar.person1_gmail_com', 'location') }}"
  7.  
  8. 5.
  9. - platform: template
  10.   sensors:
  11.     timetoleaveperson1:
  12.       friendly_name: Time Person1 needs to leave
  13.       value_template: >-
  14.         {{
  15.         ((as_timestamp(state_attr('calendar.person1_gmail_com','start_time'))
  16.         - (state_attr('sensor.person1_to_calendar','duration')|int) * 60)|timestamp_custom()) | default(now)
  17.         }}
  18.  
  19. 6.
  20. type: markdown
  21. content: |-
  22.   {% set timeleft =
  23.                                   ((as_timestamp(states.sensor.timetoleaveperson1.state)
  24.                                   - as_timestamp(now())) / 60) | int %}
  25.   {% if (states.person.person1.state == 'home') %}
  26.     {% if ((((as_timestamp(state_attr('calendar.person1_gmail_com', 'start_time')) - as_timestamp(now())) / 60) | int) >= -60) %}
  27.       {% if timeleft < 120 %} {#Home and less than 2h to leave #}
  28.         {%- if timeleft > 0 %} {#Person 1 is home and not late#}
  29.           Person1, to make it to  
  30.           **{{states.calendar.person1_gmail_com.attributes.message}}**
  31.           you need to leave at **{{((as_timestamp(states.sensor.timetoleaveperson1.state))|timestamp_custom("%H:%M"))}}**
  32.           so you have **{{timeleft}}** minutes
  33.         {%- elif timeleft <0 %} {#Home and late #}
  34.           Person 1, you're late for **{{states.calendar.person1_gmail_com.attributes.message}}**!!
  35.         {%- endif -%}
  36.       {%- else -%} {#Home and more than 2 hours to the next meeting#}
  37.       Person 1 has nothing planned soon
  38.       {%- endif -%} {#Home and at least hour after person1 was supposed to leave -> either back from work or never went#}
  39.     {%- endif -%}
  40.   {%- else -%} {#Not home#}
  41.     {% if timeleft < 15 %} {#Less than 15 minutes to when person1 is suposed to leave, probably left already#}
  42.     Person 1 is expected back around **{{(as_timestamp(states.calendar.person1_gmail_com.attributes.end_time) + (states.sensor.person1_to_home.attributes.duration * 60 | int)) |timestamp_custom ("%H:%M")}}**
  43.     {%- else -%} {#Not home but still plenty of time to next meeting, probably out and about#}
  44.     {# Message for when Person 1is not home#}
  45.   {%- endif -%}
  46.   {%- endif -%}
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement