Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- automation:
- - id: 8b9b876269874ef7ba2dae67366e68ea
- alias: Flagdage, scrape og aktioner
- description: samlet automation
- initial_state: true
- mode: single
- trigger:
- - platform: time
- at:
- - "05:00"
- - platform: homeassistant
- event: start
- - platform: template
- value_template: "{{ states('sensor.time') == state_attr('sensor.next_flag_day', 'flag_up_time') }}"
- - platform: template
- value_template: "{{ states('sensor.time') == state_attr('sensor.next_flag_day', 'half_mast') }}"
- - platform: sun
- event: sunset
- offset:
- minutes: "-10"
- action:
- - variables:
- platform: "{{ trigger.platform }}"
- flag_day: "{{ ( state_attr('sensor.next_flag_day', 'days') | int ) == 0 }}"
- half_mast_all_day: "{{ state_attr('sensor.flagdays_dk', 'half_mast_all_day') }}"
- half_mast_end_time: "{{ state_attr('sensor.flagdays_dk', 'half_mast_end_time') }}"
- half_mast_end_time_trigger: "{{ (trigger.to_state.state) if platform == 'template' else '' }}"
- half_mast_option: "{{ state_attr('input_select.flag_position', 'options')[1]) }}"
- full_mast_option: "{{ state_attr('input_select.flag_position', 'options')[2]) }}"
- time_out: "{{ (trigger.offset[1:] | int) if platform == 'sun' else 600 }}"
- - choose:
- # IT IS A FLAGDAY AND IT IS MORNING OR END OF HALF MAST
- - conditions: "{{ platform == 'template' and flag_day }}"
- sequence:
- - choose:
- # FROM HALF MAST TO THE TOP
- - conditions: "{{ half_mast_end_time_trigger == state_attr('sensor.next_flag_day', 'half_mast') }}"
- sequence:
- - service: script.flag_notification
- data:
- message: "Det er nu tid til at flaget skal helt til tops."
- time_offset: "{{ time_out }}"
- actions:
- - action_title: "OK, flaget er hejst til tops"
- action_name: "flag_ok_half_mast"
- - action_title: "Annullér"
- action_name: "flag_cancel"
- - wait_for_trigger:
- - platform: event
- event_type: mobile_app_notification_action
- event_data:
- action: "flag_ok_half_mast"
- timeout:
- seconds: "{{ time_out }}"
- continue_on_timeout: false
- - service: input_select.select_last
- data:
- entity_id: input_select.flag_position
- # HOIST THE FLAG
- default:
- - service: script.flag_notification
- data:
- message: |
- Husk at hejse flaget i anledning af {{ state_attr('sensor.next_flag_day', 'friendly_name') }}.
- {%- if not is_state_attr('sensor.next_flag_day', 'half_mast', 'false') %}
- <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.' }}
- {% endif %}
- actions:
- - action_title: "OK, flaget er hejst"
- action_name: "flag_toggle"
- - action_title: "Annullér"
- action_name: "flag_cancel"
- - wait_for_trigger:
- - platform: event
- event_type: mobile_app_notification_action
- event_data:
- action: "flag_toggle"
- timeout:
- seconds: "{{ time_out }}"
- continue_on_timeout: false
- # HOW HIGH MUST WE HOIST THE FLAG, HALF OR TO THE TOP
- - service: input_select.select_option
- data:
- entity_id: input_select.flag_position
- option: "{{ half_mast_option if half_mast_all_day or half_mast_end_time else full_mast_option }}"
- - service: script.flag_clear_notification
- # IT IS TIME TO TAKE THE FLAG DOWN
- - conditions: "{{ platform == 'sun' and flag_day }}"
- sequence:
- - service: script.flag_notification
- data:
- message: |
- Husk at tage flaget ned. Solen går ned kl. {{ state_attr('sensor.next_flag_day', 'flag_down_time') }}.
- {{ '<b>OBS</b>: Hejs først flaget helt til tops inden det tages ned.' if is_state('input_select.flag_position', half_mast_option) }}
- time_offset: "{{ time_out }}"
- actions:
- - action_title: "OK, flaget er taget ned"
- action_name: "flag_toggle"
- - action_title: "Annullér"
- action_name: "flag_cancel"
- - wait_for_trigger:
- - platform: event
- event_type: mobile_app_notification_action
- event_data:
- action: "flag_toggle"
- timeout:
- seconds: "{{ time_out * 60 }}"
- continue_on_timeout: false
- - service: input_select.select_first
- data:
- entity_id: input_select.flag_position
- - service: script.flag_clear_notification
- default:
- - service: shell_command.flagdays_update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement