How to automate my awning (sunscreen)

Hi Marc,

It’s basic, but helps me with adjustment the settings for the perfect (I hope ever) control of my sunscreens :slight_smile:

See my config below.

###################################################################################
#   screens group sensor
#   @author         :   RKl
#   @last update    :   18/08/2019
#   @package        :   none
#   @description    :   Template sensor for sunscreen conditions states
#   @url            :   https://www.home-assistant.io/components/sensor.template/
###################################################################################

###################################################################################   
# Woonkamer down
################################################################################### 
  - platform: template
    sensors:
      wk_blokkering_button_display:       
        value_template: >-
          {% if is_state('input_boolean.disable_automatic_sunscreens', 'off') %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if is_state('input_boolean.disable_automatic_sunscreens', 'off') %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}

  - platform: template
    sensors:
      wk_sun_above_horizon:       
        value_template: >-
          {% if is_state('sun.sun', 'above_horizon') %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if is_state('sun.sun', 'above_horizon') %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}

  - platform: template
    sensors:
      wk_sun_above_horizon_time: 
        value_template: >-
          {% if (now().timestamp())|timestamp_custom('%H:%M') >= ( as_timestamp(state_attr('sensor.sunrise','today')) + (1.0*3600) )|timestamp_custom('%H:%M') %} True
          {% else %} False
          {% endif %}
        entity_id:
          - sensor.sunrise 
          - sensor.time 
        icon_template: >-
          {% if (now().timestamp())|timestamp_custom('%H:%M') >= ( as_timestamp(state_attr('sensor.sunrise','today')) + (1.0*3600) )|timestamp_custom('%H:%M') %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}        
        
#     als--> huidige tijd (custom gemaakt) groter of gelijk is dan sensor.sunrise attribute tijd 'today' + 7,5uur (custom gemaakt) dan true.      9u = groter/gelijk dan bv 7u+1u      
#      - condition: sun
#        after: sunrise
#        after_offset: '01:00:00'

  - platform: template
    sensors:
      wk_sun_below_horizon_time: 
        value_template: >-
          {% if (now().timestamp())|timestamp_custom('%H:%M') <= ( as_timestamp(state_attr('sensor.sunset','today')) - (3.5*3600) )|timestamp_custom('%H:%M') %} True
          {% else %} False
          {% endif %}
        entity_id:
        - sensor.sunset
        - sensor.time 
        icon_template: >-
          {% if (now().timestamp())|timestamp_custom('%H:%M') <= ( as_timestamp(state_attr('sensor.sunset','today')) - (3.5*3600) )|timestamp_custom('%H:%M') %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}


#     als--> huidige tijd (custom gemaakt) kleiner is dan sensor.sunset attribute tijd 'today' - 3,5uur (custom gemaakt) dan true.      15u = kleiner/gelijk dan bv 3,5u voor 21u 
#      - condition: sun  
#        before: sunset
#        before_offset: "-03:30:00"


  - platform: template
    sensors:
      wk_max_wind_gust:
      # Wind strenght - in km/h  (equeal as windkracht 7)    
        value_template: >-
          {% if states('sensor.br_arnhem_wind_gust') | int < 60 %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if states('sensor.br_arnhem_wind_gust') | float < 60 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}
          
  - platform: template
    sensors:
      wk_max_rain_next_hour:
      # Almost no rain in the next 60 minutes is predicted      
        value_template: >-
          {% if states('sensor.br_arnhem_precipitation_forecast_average') | int < 10 %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if states('sensor.br_arnhem_precipitation_forecast_average') | int < 10 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}        

  - platform: template
    sensors:
      wk_min_outdoor_temp:
      # Above the 16 degrees outsite temperature 
        value_template: >-
          {% if states('sensor.outdoor_temperature') | int > 16 %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if states('sensor.outdoor_temperature') | int > 16 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}   

  - platform: template
    sensors:
      wk_min_inside_temp:
      # Above the 20 degrees in Living room.    
        value_template: >-
          {% if states.climate.woonk_keuken.attributes.current_temperature > 20 %} True
          {% else %} False
          {% endif %}
        entity_id:
        - climate.woonk_keuken
        icon_template: >-
          {% if states.climate.woonk_keuken.attributes.current_temperature > 20 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}   
  
  - platform: template
    sensors:
      wk_outside_weather_summary_down_up:
      #If one of the sensor values (see screens_sensor.yaml) is True and therefore this sensor is down for 30 min the condition will be True.    
        value_template: >-
          {% if is_state('sensor.screen_woonkamer_down_by_clouds', 'down') %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if is_state('sensor.screen_woonkamer_down_by_clouds', 'down') %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}  

  - platform: template
    sensors:
      wk_min_ha_running:
      # Voorkomt dat automation na restart HA gelijk uitgevoerd wordt.   
        value_template: >-
          {% if states('sensor.ha_runtime_in_hours') | float > 0.05 %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if states('sensor.ha_runtime_in_hours') | float > 0.05 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}  


#datetime
#{{now()}}
#timestamp
#{{as_timestamp(now())}}
#add 1 hour (3600 seconds)
#{{as_timestamp(now())+ (1*60*60)}}
#display as local time
#{{(as_timestamp(now())+ (1*60*60))  | timestamp_local}}
#display just the hour
#{{(as_timestamp(now())+ (1*60*60))  | timestamp_custom("%H",true)}}
# {% as_timestamp(now().strftime("%H") >= "7") and (now().strftime("%H") <= "16") %} True 

  
  
  - platform: template
    sensors:
      wk_time_frame_for_execution:       
        value_template: >-
          {% if now().hour > 7 and now().hour < 16 %} true
          {% else %} False
          {% endif %}
        entity_id:
        - sensor.time         
        icon_template: >-
          {% if now().hour > 7 and now().hour < 16 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}


        
#      - condition: time
#        after: '07:00:00'
#        before: '16:00:00'


  - platform: template
    sensors:
      wk_months_for_execution:
      # Starting in Maart dus groter dan 2 (feb) en ending in oktober dus kleiner dan 10    
        value_template: >-
          {% if (now().month >= 3) and (now().month <= 9) %} True
          {% else %} False
          {% endif %}
        entity_id:
        - sensor.date           
        icon_template: >-
          {% if (now().month >= 3) and (now().month <= 9) %} 
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}

  - platform: template
    sensors:
      wk_last_execution_time:
      # prevents that automation is triggered multiple times in a short amount of time. Checks last time automation is triggered, if more then 2700 seconds (45min), condition becomes True    
        value_template: >-
          {% if (as_timestamp(now()) - as_timestamp(states.automation.sunscreen_woonkamer_down.attributes.last_triggered) | int > 2700) %} True
          {% else %} False
          {% endif %}
        entity_id:
        - sensor.time 
        icon_template: >-
          {% if (as_timestamp(now()) - as_timestamp(states.automation.sunscreen_woonkamer_down.attributes.last_triggered) | int > 2700) %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}

  - platform: template
    sensors:
      wk_down_last_execution_up_older_then_down:
      # can only be triggered if timestamp of last_triggered time UP is kleiner/gelijk than the timestamp of last_triggered time of the "screen down" automation.    
        value_template: >-
          {% if (as_timestamp(states.automation.sunscreen_woonkamer_down.attributes.last_triggered) | int <= as_timestamp(states.automation.sunscreen_woonkamer_up.attributes.last_triggered) | int) %} True
          {% else %} False
          {% endif %}
        entity_id:
          - sensor.time          
        icon_template: >-
          {% if (as_timestamp(states.automation.sunscreen_woonkamer_down.attributes.last_triggered) | int <= as_timestamp(states.automation.sunscreen_woonkamer_up.attributes.last_triggered) | int) %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}

###################################################################################   
# Keuken Down
################################################################################### 
  - platform: template
    sensors:
      keu_blokkering_button_display:       
        value_template: >-
          {% if is_state('input_boolean.disable_automatic_sunscreens', 'off') %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if is_state('input_boolean.disable_automatic_sunscreens', 'off') %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}

  - platform: template
    sensors:
      keu_sun_above_horizon:       
        value_template: >-
          {% if is_state('sun.sun', 'above_horizon') %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if is_state('sun.sun', 'above_horizon') %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}

  - platform: template
    sensors:
      keu_sun_above_horizon_time: 
        value_template: >-
          {% if (now().timestamp())|timestamp_custom('%H:%M') >= ( as_timestamp(state_attr('sensor.sunrise','today')) + (7.5*3600) )|timestamp_custom('%H:%M') %} True
          {% else %} False 
          {% endif %}
        entity_id:
          - sensor.sunrise
          - sensor.time     
        icon_template: >-
          {% if (now().timestamp())|timestamp_custom('%H:%M') >= ( as_timestamp(state_attr('sensor.sunrise','today')) + (7.5*3600) )|timestamp_custom('%H:%M') %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}

#     als--> huidige tijd (custom gemaakt) groter of gelijk is dan sensor.sunrise attribute tijd 'today' + 7,5uur (custom gemaakt) dan true.       15u = groter/gelijk dan bv 7u+7,5u
#      - condition: sun
#        after: sunrise
#        after_offset: '07:30:00'

  - platform: template
    sensors:
      keu_sun_below_horizon_time: 
        value_template: >-
          {% if (now().timestamp())|timestamp_custom('%H:%M') <= ( as_timestamp(state_attr('sensor.sunset','today')) - (1.5*3600) )|timestamp_custom('%H:%M') %} True
          {% else %} False
          {% endif %}
        entity_id:
          - sensor.sunset
          - sensor.time            
        icon_template: >-
          {% if (now().timestamp())|timestamp_custom('%H:%M') <= ( as_timestamp(state_attr('sensor.sunset','today')) - (1.5*3600) )|timestamp_custom('%H:%M') %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}

#     als--> huidige tijd (custom gemaakt) kleiner is dan sensor.sunset attribute tijd 'today' - 1,5uur (custom gemaakt) dan true.      15u = kleiner/gelijk dan bv 1,5u voor 21u 
#      - condition: sun  
#        before: sunset
#        before_offset: "-01:30:00"


  - platform: template
    sensors:
      keu_max_wind_gust:
      # Wind strenght - in km/h  (equeal as windkracht 7)    
        value_template: >-
          {% if states('sensor.br_arnhem_wind_gust') | int < 60 %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if states('sensor.br_arnhem_wind_gust') | float < 60 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}
          
  - platform: template
    sensors:
      keu_max_rain_next_hour:
      # Almost no rain in the next 60 minutes is predicted      
        value_template: >-
          {% if states('sensor.br_arnhem_precipitation_forecast_average') | int < 10 %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if states('sensor.br_arnhem_precipitation_forecast_average') | int < 10 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}        

  - platform: template
    sensors:
      keu_min_outdoor_temp:
      # Above the 16 degrees outsite temperature 
        value_template: >-
          {% if states('sensor.outdoor_temperature') | int > 16 %} True
          {% else %} False
          {% endif %}
        entity_id:
          - sensor.outdoor_temperature
        icon_template: >-
          {% if states('sensor.outdoor_temperature') | int > 16 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}   

  - platform: template
    sensors:
      keu_min_inside_temp:
      # Above the 20 degrees in Living room.    
        value_template: >-
          {% if states.climate.woonk_keuken.attributes.current_temperature > 20 %} True
          {% else %} False
          {% endif %}
        entity_id:
          - climate.woonk_keuken           
        icon_template: >-
          {% if states.climate.woonk_keuken.attributes.current_temperature > 20 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}   
  
  - platform: template
    sensors:
      keu_outside_weather_summary_down_up:
      #If one of the sensor values (see screens_sensor.yaml) is True and therefore this sensor is down for 30 min the condition will be True.    
        value_template: >-
          {% if is_state('sensor.screen_keuken_down_by_clouds', 'down') %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if is_state('sensor.screen_keuken_down_by_clouds', 'down') %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}  

  - platform: template
    sensors:
      keu_min_ha_running:
      # Voorkomt dat automation na restart HA gelijk uitgevoerd wordt.   
        value_template: >-
          {% if states('sensor.ha_runtime_in_hours') | float > 0.05 %} True
          {% else %} False
          {% endif %}
        icon_template: >-
          {% if states('sensor.ha_runtime_in_hours') | float > 0.05 %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}  


  - platform: template
    sensors:
      keu_time_frame_for_execution:       
        value_template: >-
          {% if now().hour > 12 and now().hour < 20 %} true
          {% else %}
            False
          {% endif %}
        entity_id:
          - sensor.time             
        icon_template: >-
          {% if now().hour > 12 and now().hour < 20 %} 
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}


#      - condition: time
#        after: '12:00:00'
#        before: '20:00:00'


  - platform: template
    sensors:
      keu_months_for_execution:
      # Starting in Maart dus groter dan 2 (feb) en ending in oktober dus kleiner dan 10    
        value_template: >-
          {% if (now().month >= 3) and (now().month <= 9) %} True
          {% else %} False
          {% endif %}
        entity_id:
          - sensor.date 
        icon_template: >-
          {% if (now().month >= 3) and (now().month <= 9) %} 
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}


  - platform: template
    sensors:
      keu_last_execution_time:
      # prevents that automation is triggered multiple times in a short amount of time. Checks last time automation is triggered, if more then 2700 seconds (45min), condition becomes True    
        value_template: >-
          {% if (as_timestamp(now()) - as_timestamp(states.automation.sunscreen_keuken_down.attributes.last_triggered) | int > 2700) %} True
          {% else %} False
          {% endif %}
        entity_id:
          - sensor.time          
        icon_template: >-
          {% if (as_timestamp(now()) - as_timestamp(states.automation.sunscreen_keuken_down.attributes.last_triggered) | int > 2700) %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}

  - platform: template
    sensors:
      keu_down_last_execution_up_older_then_down:
      # can only be triggered if timestamp of last_triggered time UP is kleiner/gelijk than the timestamp of last_triggered time of the "screen down" automation.    
        value_template: >-
          {% if (as_timestamp(states.automation.sunscreen_keuken_down.attributes.last_triggered) | int <= as_timestamp(states.automation.sunscreen_keuken_up.attributes.last_triggered) | int) %} True
          {% else %} False
          {% endif %}
        entity_id:
          - sensor.time          
        icon_template: >-
          {% if (as_timestamp(states.automation.sunscreen_keuken_down.attributes.last_triggered) | int <= as_timestamp(states.automation.sunscreen_keuken_up.attributes.last_triggered) | int) %}
            mdi:check-outline
          {% else %}
            mdi:alert-outline
          {% endif %}
############################
# Sunscreens
############################                 
    title: Sunscreens # Tooltip
    icon: mdi:projector-screen
    cards:
      - type: entities
        title: Sturing Screens
        show_header_toggle: false
        entities:
          - type: section
            label: "Woonkamer_DOWN"
          - type: entities
            entity: sensor.wk_blokkering_button_display
          - type: entities
            entity: sensor.wk_sun_above_horizon
          - type: entities
            entity: sensor.wk_sun_above_horizon_time
          - type: entities
            entity: sensor.wk_sun_below_horizon_time 
          - type: entities
            entity: sensor.wk_max_wind_gust
          - type: entities
            entity: sensor.wk_max_rain_next_hour
          - type: entities
            entity: sensor.wk_min_outdoor_temp
          - type: entities
            entity: sensor.wk_min_inside_temp
          - type: entities
            entity: sensor.wk_outside_weather_summary_down_up
          - type: entities
            entity: sensor.wk_min_ha_running
          - type: entities
            entity: sensor.wk_time_frame_for_execution
          - type: entities
            entity: sensor.wk_months_for_execution
          - type: entities
            entity: sensor.wk_last_execution_time
          - type: entities
            entity: sensor.wk_down_last_execution_up_older_then_down
            
         
          - type: section
            label: "Keuken_DOWN"
          - type: entities
            entity: sensor.keu_blokkering_button_display
          - type: entities
            entity: sensor.keu_sun_above_horizon
          - type: entities
            entity: sensor.keu_sun_above_horizon_time
          - type: entities
            entity: sensor.keu_sun_below_horizon_time             
          - type: entities
            entity: sensor.keu_max_wind_gust
          - type: entities
            entity: sensor.keu_max_rain_next_hour
          - type: entities
            entity: sensor.keu_min_outdoor_temp
          - type: entities
            entity: sensor.keu_min_inside_temp
          - type: entities
            entity: sensor.keu_outside_weather_summary_down_up
          - type: entities
            entity: sensor.keu_min_ha_running
          - type: entities
            entity: sensor.keu_time_frame_for_execution
          - type: entities
            entity: sensor.keu_months_for_execution
          - type: entities
            entity: sensor.keu_last_execution_time
          - type: entities
            entity: sensor.keu_down_last_execution_up_older_then_down 
3 Likes