Advertisement
JLindvig

crazy_shit

Feb 9th, 2021 (edited)
1,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 6.10 KB | None | 0 0
  1.  automation:
  2.     - id: 8b9b876269874ef7ba2dae67366e68ea
  3.       alias: Flagdage, scrape og aktioner
  4.       description: samlet automation
  5.       initial_state: true
  6.       mode: single
  7.       trigger:
  8.         - platform: time
  9.           at:
  10.            - "05:00"
  11.         - platform: homeassistant
  12.           event: start
  13.  
  14.         - platform: template
  15.           value_template: "{{ states('sensor.time') == state_attr('sensor.next_flag_day', 'flag_up_time') }}"
  16.         - platform: template
  17.           value_template: "{{ states('sensor.time') == state_attr('sensor.next_flag_day', 'half_mast') }}"
  18.  
  19.         - platform: sun
  20.           event: sunset
  21.           offset:
  22.             minutes: "-10"
  23.  
  24.       action:
  25.         - variables:
  26.             platform: "{{ trigger.platform }}"
  27.             flag_day: "{{ ( state_attr('sensor.next_flag_day', 'days') | int ) == 0 }}"
  28.             half_mast_all_day: "{{ state_attr('sensor.flagdays_dk', 'half_mast_all_day') }}"
  29.             half_mast_end_time: "{{ state_attr('sensor.flagdays_dk', 'half_mast_end_time') }}"
  30.             half_mast_end_time_trigger: "{{ (trigger.to_state.state) if platform == 'template' else '' }}"
  31.             half_mast_option: "{{ state_attr('input_select.flag_position', 'options')[1]) }}"
  32.             full_mast_option: "{{ state_attr('input_select.flag_position', 'options')[2]) }}"
  33.             time_out: "{{ (trigger.offset[1:] | int) if platform == 'sun' else 600 }}"
  34.  
  35.         - choose:
  36.            # IT IS A FLAGDAY AND IT IS MORNING OR END OF HALF MAST
  37.             - conditions: "{{ platform == 'template' and flag_day }}"
  38.               sequence:
  39.                 - choose:
  40.                    # FROM HALF MAST TO THE TOP
  41.                     - conditions: "{{ half_mast_end_time_trigger == state_attr('sensor.next_flag_day', 'half_mast') }}"
  42.                       sequence:
  43.                         - service: script.flag_notification
  44.                           data:
  45.                             message: "Det er nu tid til at flaget skal helt til tops."
  46.                             time_offset: "{{ time_out }}"
  47.                             actions:
  48.                               - action_title: "OK, flaget er hejst til tops"
  49.                                 action_name: "flag_ok_half_mast"
  50.                               - action_title: "Annullér"
  51.                                 action_name: "flag_cancel"
  52.                
  53.                         - wait_for_trigger:
  54.                             - platform: event
  55.                               event_type: mobile_app_notification_action
  56.                               event_data:
  57.                                 action: "flag_ok_half_mast"
  58.                           timeout:
  59.                             seconds: "{{ time_out }}"
  60.                           continue_on_timeout: false
  61.  
  62.                         - service: input_select.select_last
  63.                           data:
  64.                             entity_id: input_select.flag_position
  65.  
  66.                   # HOIST THE FLAG
  67.                   default:
  68.                     - service: script.flag_notification
  69.                       data:
  70.                         message: |
  71.                          Husk at hejse flaget i anledning af {{ state_attr('sensor.next_flag_day', 'friendly_name') }}.
  72.                           {%- if not is_state_attr('sensor.next_flag_day', 'half_mast', 'false') %}
  73.                             <br><br><b>HUSK</b>: Flaget skal være på halv {{ 'hele dagen.' if is_state_attr('sensor.next_flag_day', 'half_mast', 'true') else 'indtil ' + state_attr('sensor.next_flag_day', 'half_mast') + ' hvorefter det skal hejses til tops.' }}
  74.                           {% endif %}
  75.                         actions:
  76.                           - action_title: "OK, flaget er hejst"
  77.                             action_name: "flag_toggle"
  78.                           - action_title: "Annullér"
  79.                             action_name: "flag_cancel"
  80.  
  81.                     - wait_for_trigger:
  82.                       - platform: event
  83.                         event_type: mobile_app_notification_action
  84.                         event_data:
  85.                           action: "flag_toggle"
  86.                       timeout:
  87.                         seconds: "{{ time_out }}"
  88.                       continue_on_timeout: false
  89.  
  90.                     # HOW HIGH MUST WE HOIST THE FLAG, HALF OR TO THE TOP
  91.                     - service: input_select.select_option
  92.                       data:
  93.                         entity_id: input_select.flag_position
  94.                         option: "{{ half_mast_option if half_mast_all_day or half_mast_end_time else full_mast_option }}"
  95.  
  96.                 - service: script.flag_clear_notification
  97.  
  98.             # IT IS TIME TO TAKE THE FLAG DOWN
  99.             - conditions: "{{ platform == 'sun' and flag_day }}"
  100.               sequence:
  101.                 - service: script.flag_notification
  102.                   data:
  103.                     message: |
  104.                      Husk at tage flaget ned. Solen går ned kl. {{ state_attr('sensor.next_flag_day', 'flag_down_time') }}.
  105.                       {{ '<b>OBS</b>: Hejs først flaget helt til tops inden det tages ned.' if is_state('input_select.flag_position', half_mast_option) }}
  106.                     time_offset: "{{ time_out }}"
  107.                     actions:
  108.                       - action_title: "OK, flaget er taget ned"
  109.                         action_name: "flag_toggle"
  110.                       - action_title: "Annullér"
  111.                         action_name: "flag_cancel"
  112.        
  113.                 - wait_for_trigger:
  114.                     - platform: event
  115.                       event_type: mobile_app_notification_action
  116.                       event_data:
  117.                         action: "flag_toggle"
  118.                   timeout:
  119.                     seconds: "{{ time_out * 60 }}"
  120.                   continue_on_timeout: false
  121.  
  122.                 - service: input_select.select_first
  123.                   data:
  124.                     entity_id: input_select.flag_position
  125.  
  126.                 - service: script.flag_clear_notification
  127.  
  128.           default:
  129.             - service: shell_command.flagdays_update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement