###################################
## Tornados are no Joke.
###################################

- alias: 'High Wind Speed Notification'
  hide_entity: True
  trigger:
    - platform: numeric_state
      entity_id: sensor.dark_sky_wind_speed
      above: 24
    - platform: numeric_state
      entity_id: sensor.dark_sky_wind_speed
      above: 40
    - platform: numeric_state
      entity_id: sensor.dark_sky_wind_speed
      above: 60

  condition:
    - condition: template
      value_template: >
        {%- if states.automation.high_wind_speed_notification.attributes.last_triggered -%}
          {{ (as_timestamp(now()) - as_timestamp(states.automation.high_wind_speed_notification.attributes.last_triggered)) > 3600 }}
        {%- else -%}
          true
        {%- endif -%}
        
  action:
    - service: script.notify_engine
      data_template:
        value1: 'VERY HIGH WINDS:'
        value2: "{{ states('sensor.dark_sky_wind_speed')}}"

    - service: input_boolean.turn_on
      entity_id: input_boolean.alert_mode

    - service: script.speech_engine
      data_template:
        value1: >
          {% set windspeed = states.sensor.dark_sky_wind_speed.state | round %}
          {% if ( windspeed > 25 ) and ( windspeed <= 40 ) %}
             HEAVY WINDS!!! Current Wind Speed is : {{windspeed}} mph! Be VERY careful outdoors!
          {% elif ( windspeed > 40 ) and ( windspeed <= 60 ) %}
             Warning! Wind speed is {{windspeed}} MPH. FIND SHELTER IMMEDIATELY!
          {% elif ( windspeed > 60 ) %}
             HURRICANE WINDS. FIND SHELTER, AND STAY INDOORS!
          {% endif %}
        call_window_check: 1
        call_garage_check: 1

    - service: script.emergency

    - service: script.tweet_engine
      data_template:
        tweet: >
          {% set windspeed = states.sensor.dark_sky_wind_speed.state | round %}
          {% if ( windspeed > 25 ) and ( windspeed <= 40 ) %}
             HEAVY WINDS!!! Current Wind Speed is : {{windspeed}} mph! Be VERY careful outdoors! #Florida #Weather (http://amzn.to/2jQLpVQ)
          {% elif ( windspeed > 40 ) and ( windspeed <= 60 ) %}
             Current Wind Speed is : {{windspeed}} mph! Warning! #Florida #Weather (http://amzn.to/2jQLpVQ) FIND SHELTER IMMEDIATELY! #Florida #Weather (http://amzn.to/2jQLpVQ)
          {% elif ( windspeed > 60 ) %}
             Current Wind Speed is : {{windspeed}} mph! HURRICANE WINDS. FIND SHELTER, AND STAY INDOORS! #Florida #Weather (http://amzn.to/2jQLpVQ)
          {% endif %}