How to automate my awning (sunscreen)

Hi, I just set up hassio on a Pi3, got Z-Wave up and running, and created my first automation for switching off my kitchen boiler at night. Very happy so far! Now my challenge is to automate the awning (or in Dutch: zonnescherm / sunscreen).

Automating it would probably involve things like:

  • temperature (the awning only needs to be extended at higher temperatures)
  • wind speed (the awning should not be blown through the window glass)
  • rain forecast (I’d like to keep the awning dry)
  • UV (at lower UV values the house probably doesn’t need to be shielded from the sunlight)
  • opened/closed status of the awning

I’ve found I can use weather resources like Buienradar and WeatherUnderground to get sensor values. But how do I connect the sensor values in a practical way? Are there resources or example scripts available?

Any pointers would be appreciated.

2 Likes

You’re going to need templates that look at the weather sensors (and possibly time/sunrise), and based on a combination of their readings decide whether the awning should be out.

I have two such template sensors in my setup, one works out whether it is dark enough that the lights should be on/off, and one works out if the weather conditions are likely to delay my journey.

Hopefully it will give you some clues to get you started…

link removed

That sure gives some clues at how to approach the challenge. Thanks!

I am hoping someone might already have a relevant template set up for opening and closing an awning. That would give me a great headstart, not having to figure out the correct combinations.

1 Like

A bayesien sensor would seem to fit the bill :slight_smile:

A bayesian sensor could work nice, but be careful about how you incorporate wind speed, because the awning should close if the wind is high. That seems like the “most important” sensor.

I don’t know if a template is the right thing for this, perhaps just a whole bunch of triggers, and two automations?

For example:

open awning:

triggers: temperature above 25 C, wind speed drops below 5 km/h for thirty minutes, rain likelihood above 90%, UV above… 7.
conditions: wind speed below 5 km/h

close awning:

triggers: temperature below 22, wind speed above 5 km/h for two minutes, UV below… 6
conditions: not raining or wind above 5.

That’s three directions to try out: template, bayesian binary sensor and a bunch of triggers.

I feel like I still have a lot to learn :slight_smile:

When I get a working solution I’ll report back!

1 Like

I think I’ve put together an automation that I hope might work. I’m curious what you guys think about this approach, should this work as expected? In automations.yaml:

- alias: 'Roll down awning'
  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state.attributes.azimuth }}'
    above: 150  #sun light starts to hit the window
    below: 275  #275 is about West, where the sun sets
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: switch.fibaro_system_roller_shutter_controller_switch
        state: 'on'  #ON means awning is all the way up
        for:
          hours: 1
      - condition: numeric_state
        entity_id: sun.sun
        value_template: '{{ state.attributes.elevation }}'
        above: 0  #above the horizon
      - condition: numeric_state
        entity_id: sensor.br_temperature_1d
        above: 15 #predicted max temp today
      - condition: numeric_state
        entity_id: sensor.pws_uv
        above: 2  #predicted UV-index around noon (1-10)
      - condition: numeric_state
        entity_id: sensor.pws_wind_kph
        below: 6 #1-5 is a mild breeze
      - condition: numeric_state
        entity_id: sensor.pws_wind_gust_kph
        below: 15 #15 is still a light breeze
      - condition: numeric_state
        entity_id: sensor.br_precipitation_forecast_total
        below: 0.5 #rain less than 0.5 mm/h in the next 20 minutes
      - condition: template
        value_template: '{{ now().month > 1 }}' #starting February
      - condition: template
        value_template: '{{ now().month < 10 }}' #ending September
      - condition: numeric_state
        entity_id: sensor.br_irradiance
        above: 300 #up to 300 no sun shielding is necessary (cloudy)
  action:
    service: light.turn_on  # for testing purposes; will eventually be 'roll out awning'
    entity_id: light.yeelight_rgb
    data:
      color_name: blue
      brightness: 255

Of course what is missing is something comparable for ‘roll up awning’, working on that :slight_smile:

I would like to borrow your code. Doed it work like expected? i am using the exact same setup. Fibaro Shutter and Buienradar sensor.

Hi Martin, I’ve tuned the configuration further since the posting above. I’ll add the relevant bits here. I have to say I have not thorougly tested it. It’s basically working, but I’m waiting for springtime to put it to the test :slight_smile:

automations.yaml

- alias: Roll down awning
  trigger:
    platform: state
    entity_id: sun.sun
  condition:
    condition: and
    conditions:
    - condition: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.azimuth }}'
      above: 150  ## This is the position where the sunlight starts hitting the window
      below: 235  ## This is about west, sun down
    - condition: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      above: 0  ## Sun should be above the horizon, not below
    - condition: state
      entity_id: cover.fibaro_system_fgr221_roller_shutter_controller_switch
      state: open
      for:
        minutes: 30  ## Trying to prevent a crazy repetitive up-and-down action
    - condition: sun
      before: sunset
      before_offset: -00:45:00  ## Some time before sunset, there's no point in rolling out anymore
    - condition: numeric_state
      entity_id: sensor.br_temperature_1d
      above: 16   ## Expected highest temperature for the day should be over 16
    - condition: numeric_state
      entity_id: sensor.pws_uv
      above: 1   ## Expected UV index at noon should at least be above 1, but perhaps it needs to be higher
    - condition: numeric_state
      entity_id: statistics.wind_kph_avg
      below: 7   ## I still have to tune this value 
    # - condition: numeric_state
    #   entity_id: sensor.pws_wind_gust_kph
    #   below: 25    ## I removed this one because I think wind speed should be enough
    - condition: numeric_state
      entity_id: sensor.br_precipitation_forecast_total
      below: 0.1  ## Almost no rain in the next 20 minutes
    - condition: template
      value_template: '{{ now().month > 2 }}'  ## Starting March 
    - condition: template
      value_template: '{{ now().month < 10 }}' ## Ending October
    - condition: numeric_state
      entity_id: statistics.irradiance_avg
      above: 300  ## This indicates direct sunlight on my location (as in: not cloudy)
    - condition: state
      entity_id: input_boolean.vacation_mode
      state: 'off'  ## When we are on vacation, the awning does not need to move
  action:
    service: cover.close_cover
    entity_id: cover.fibaro_system_fgr221_roller_shutter_controller_switch
    
- alias: Roll up awning
  trigger:
  - platform: sun
    event: sunset
    offset: -00:45:00
  - platform: numeric_state
    entity_id: statistics.wind_kph_avg
    above: 7
  # - platform: numeric_state
  #   entity_id: sensor.pws_wind_gust_kph
  #   above: 19
  - platform: numeric_state
    entity_id: sensor.br_precipitation_forecast_total
    above: 0.2
  - platform: numeric_state
    entity_id: statistics.irradiance_avg
    below: 100
  condition:
    condition: state
    entity_id: cover.fibaro_system_fgr221_roller_shutter_controller_switch
    state: closed
    for:
      seconds: 30  ## The screen takes some time to fully roll up or down, I don't want it changing direction half way
  action:
    service: cover.open_cover
    entity_id: cover.fibaro_system_fgr221_roller_shutter_controller_switch

configuration.yaml

sensor:

  - platform: wunderground
    api_key: xxxx
    monitored_conditions:
    # - precip_today_metric
      - temp_c
      - wind_kph
    # - wind_gust_kph
      - UV
    scan_interval: 10
  - platform: buienradar
    timeframe: 20
    monitored_conditions:
      - symbol
      - conditiondetailed
      - temperature
      - windspeed
      - precipitation_forecast_average
      - precipitation_forecast_total
      - temperature_1d
      - irradiance
  - platform: template
    sensors:
      solar_elevation:
        friendly_name: "Sun elevation"
        unit_of_measurement: 'degrees'
        value_template: "{{ states.sun.sun.attributes.elevation }}"
      solar_azimuth:
        friendly_name: "Sun azimuth"
        unit_of_measurement: 'degrees'
        value_template: "{{ states.sun.sun.attributes.azimuth }}"
  - platform: statistics  ## For smoothing out spikes
    name: wind_kph_avg
    entity_id: sensor.pws_wind_kph
    sampling_size: 3 #Measures every 15 minutes
    max_age:
      minutes: 65
  - platform: statistics
    name: irradiance_avg   ## For smoothing out spikes
    entity_id: sensor.br_irradiance
    sampling_size: 3  #Measures every 10 minutes
    max_age:
      minutes: 40
3 Likes

Ok Thanks for you code. a few markups:

  • why not using only Buienradar?
  • aren’t those precipitation for the next day?
  • it look likes you cover close and cover open are reversed?
  • those are a lot of conditions. Isn’t a little to much?

Thanks again

  1. Because Buienradar does not have the UV index. More importantly, I believe the wind speed from Buienradar is measured at their own location(s?) (for me: De Bilt). Weather Underground provides a wind speed that is measured by a neighbour of mine a couple 100 meters away, so way more local.

  2. No I don’t think so. At least, that’s how I read the documentation on the Buienradar component. But if I made a mistake I’d love to hear about it so I can correct it.

  3. I know it seems that way, but it is correct for my situation. It depends on how your cover is set up, what it considers ‘on’ or ‘off’, ‘open’ or ‘closed’. I just took the correct state from the Developer Tools / States.

  4. Yes I agree. I put together a lot of conditions that seem relevant. You can just delete what you deem irrelevant I guess :). I think the important ones I’d hold on to are irradiance, predicted temperature, azimuth/elevation, wind speed, rain.

I’d like to hear your experiences, share tips.

Today i have setup your code. I skipped a couple of statistics sensors and changed some other variables. Just to know there is a simple way for the above_horizon, then your value_template, just use:

    - condition: state
      entity_id: sun.sun
      state: 'above_horizon'

secondly you made up a trigger sun.sun, but i don’t fully understand the completeness of this trigger. Isn’t missing something?

Thanks for posting back. Above-horizon sounds easier indeed.

I think I got the sun trigger from an example I found somewhere in the forums. I thought it was missing something too, but it seems to be working as expected. I wanted to find a trigger that would keep checking the conditions throughout the day when it’s light out. This does that. If you find something more efficient I’d be glad to hear it.

Edit: your post triggered me to read some more about the sun trigger. Perhaps the below topic is related, I think I might have made a similar mistake at the very beginning. If I remember correctly, I started out with azimuth above 150 and below 275 in the trigger. It seems this is not correct, perhaps I should add azimuth above 150 as a trigger and azimuth below 275 as a condition. For fine tuning :slight_smile:

i have made up the following code now:

- alias: Sunscreen down
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: sun.sun
  condition:
    condition: and
    conditions:
    - condition: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      above: 0  ## Sun should be above the horizon, not below
    - condition: state
      entity_id: cover.level
      state: closed
      for:
        minutes: 30  ## Trying to prevent a crazy repetitive up-and-down action
    - condition: sun
      before: sunset
      before_offset: -00:45:00  ## Some time before sunset, there's no point in rolling out anymore
    - condition: numeric_state
      entity_id: sensor.br_wind_force
      below: 7   ## I still have to tune this value 
    - condition: numeric_state
      entity_id: sensor.br_precipitation_forecast_total
      below: 0.1  ## Almost no rain in the next 30 minutes
    - condition: template
      value_template: '{{ now().month > 2 }}'  ## Starting March 
    - condition: template
      value_template: '{{ now().month < 10 }}' ## Ending October
    - condition: numeric_state
      entity_id: sensor.br_irradiance
      above: 300  ## This indicates direct sunlight on my location (as in: not cloudy)
  action:
   - service: cover.set_cover_position
     data:
       entity_id: cover.level
       position: 40
   - service: notify.ios_iphone
     data:
       message: 'Het zonnescherm is naar beneden gedaan ivm de zon'
- alias: Sunscreen up
  initial_state: 'on'
  trigger:
  - platform: sun
    event: sunset
    offset: -00:45:00
  - platform: numeric_state
    entity_id: sensor.br_wind_force
    above: 7
  - platform: numeric_state
    entity_id: sensor.br_precipitation_forecast_total
    above: 0.2
  - platform: numeric_state
    entity_id: sensor.br_irradiance
    below: 100
    for:
     minutes: 5
  condition:
    condition: state
    entity_id: cover.level
    state: open
    for:
      seconds: 30  ## The screen takes some time to fully roll up or down, I don't want it changing direction half way
  action:
   - service: cover.close_cover
     entity_id: cover.level
   - service: notify.ios_iphone
     data:
       message: 'Het zonnescherm is weer ingetrokken'

as it was a sunny day today, the sunscreen went down perfectly :slight_smile:
i am still a bit finetuning, but for now it look likes it is working perfect.
With the ‘position’ parameter you can also set the position (in case of a cover fibaro in Roller Blind mode with Positioning)

2 Likes

Great that it’s working for you too!

I notice you removed the ‘predicted temperature’ as a condition. I added this so when it’s cold outside (like today) the sunlight is not being blocked and is used to heat the living room. Free comfort :sun_with_face:
But perhaps in your situation it’s different?

Yes my situation is different. i removed it, because the sun is hitting the kitchen directly. As i only open the suncreen for 40% it can be done whenever it is warm or cold. there is still a condition for march until oktober.

1 Like

Hoi Emphyrio, Martinvdm,

I’m also trying to get my zonnescherm/sunscreen working. I was looking at the latest code where the sun.sun is used as a trigger.
trigger:
platform: state
entity_id: sun.sun

I also don’t understand why this is used. I believe this trigger is now triggered (…) every minute as one of the attributes changes of this sun.sun entity. Why not just use a time trigger which triggers on an interval like:

trigger:
platform: time
# You can also match on interval. This will match every 5 minutes
minutes: ‘/5’
seconds: 00

Hey Martinvdm,

With the code below, don’t you get a message every 30 minutes now on a sunny day throughout the day?
I applied your code and I seem to get this message every 30 minutes as:

  1. Trigger is triggered every minute or so
  2. conditions (on a sunny day) are all true constantly (except the second condition) which results in all conditions being TRUE every 30 minutes (as after 30 minutes the second condition, see below, also becomes TRUE).

Or do I miss something (or in proper Dunglisch, do I see something over the head (if you know what I’m saying :wink: )

- condition: state
  entity_id: cover.level
  state: closed
  for:
    minutes: 30  ## Trying to prevent a crazy repetitive up-and-down action

I do understand what you mean, i lookup the code again and it look like you are right but it is working just working fine. Today was very sunny; 10:10 sunscreen went down and about 6 Pm went up again probably due to sunset.

I do not get many messages. As said; working fine. Perhaps @Emphyrio know the answer; he made the code initially.

Hi oliesjeik, I agree with you about the sun trigger looking a little strange. I happened to change it to a timed interval, just as you suggested. Just because it made more sense to me, not because it wasn’t working :slight_smile:

I think what you are saying about the condition ‘closed for 30 minutes’ is probably a matter of interpretation what ‘closed’ and ‘open’ means. They are rather counter-intuitive for an awning, because ‘closed’ means it’s rolled all the way out, and ‘open’ means the awning is rolled up (e.g. not providing any shade). And then in my case, the Fibaro switch was also reversed for ‘off’ and ‘on’. Okay, now I’m even confusing myself :slight_smile:

My suggestion: check your states when the awning is rolled up and rolled out. And match the state in your condition. Hope I’m making sense.