How to automate my awning (sunscreen)

Hey Emphyrio,

Indeed, the sun trigger works as well but I believe the interval is more intuitive.
About the close and open states: I also noticed it’s a bit counter-intuitive when I was making my automation :slight_smile:

The difference I believe with my sunscreen and yours is that you actually ‘know’ the state the sunscreen is in (closed or open) while with my sunscreen I don’t. My sunscreen is operated with a remote control (Somfy) and I use a RFlink to control the sunscreen to send a signal to either open or close. However, when I send out a ‘close’ or ‘open’ signal, I actually do not know for certain that the signal arrived and the screen actually opened or closed. It’s like a ‘klik aan/klik uit’ system where there is not feedback if action was actually executed or not.

I probably going to add an extra sensor in the future to check if sunscreen is really open or closed but for the time being, to prevent that e.g. the down automation is triggered every x minutes, I check with a condition if the last trigger time of the close automation is older as the last trigger time of the ‘open automation’ (hope I explain it ok)

I use the following condition for that:

- condition: template
  value_template: '{{as_timestamp(states.automation.sunscreen_down.attributes.last_triggered) | int <= as_timestamp(states.automation.sunscreen_up.attributes.last_triggered) | int }}' # this automation can only be triggered if timestamp of last_triggered time is OLDER than the timestamp of last_triggered time of the "screen up" automation. This condition prevents that the automation is triggered again if sunscreen is already down. Better would be to have a real sensor checking if sunscreen is up or down but currently I don't have a sensor in place. The | int is used to catch the fact that on start up both triggers report 'none' and hence this condition would never become true. The int makes it such that value = 0 for both and hence trigger can be executed.

I also added a few more checks, not sure if they are needed, still experimenting a bit but here is my automation based on your examples:

- alias: Sunscreen down #Sunscreen down/uitklappen
  initial_state: 'on' #on reboot HA or reloading of automations, automation is ON
  trigger:
    - platform: time
      minutes: '/5'
      seconds: 0
  condition:
    condition: and # all conditions need to be TRUE before action is executed.
    conditions:

      # Wather based conditions
    - condition: numeric_state
      entity_id: sun.sun
      value_template: '{{ state.attributes.elevation }}'
      above: 0  # Sun should be above the horizon, not below.
    - condition: sun
      after: sunrise
      after_offset: 02:00:00 # Sunrise for at least 2 hours
    - condition: sun
      before: sunset
      before_offset: -02:30:00 # Some time before sunset, there's no point in rolling out anymore
    - condition: numeric_state
      entity_id: sensor.br_wind_force
      below: 7 # Wind strenght - I still have to tune this value
    - condition: numeric_state
      entity_id: sensor.br_precipitation
      below: 0.1 # Almost no rain at the moment
    - condition: numeric_state
      entity_id: sensor.br_precipitation_forecast_total
      below: 0.1 # Almost no rain in the next 60 minutes is predicted
    - condition: numeric_state
      entity_id: sensor.br_irradiance
      above: 300 # This indicates direct sunlight on my location (as in: not cloudy)

      # Temperature based conditions
    - condition: numeric_state
      entity_id: sensor.br_temperature
      above: 18 # only if outdoor temperature is above x then allowed to roll out
    - condition: numeric_state
      entity_id: sensor.aeotec_dsb05_multisensor_temperature
      above: 22 # only if indoor temperature is above x then allowed to roll out

      # Time based conditions
    - condition: template
      value_template: '{{ now().month > 3 }}' # Starting April
    - condition: template
      value_template: '{{ now().month < 10 }}' # Ending October
    - condition: template
      value_template:  ' {{ as_timestamp(now()) - as_timestamp(states.automation.sunscreen_down.attributes.last_triggered) | int > 1800}}' # prevents that automation is triggered multiple times in a short amount of time. Checks last time automation is triggered, if more then 1800 seconds (30min), condition becomes TRUE
    - condition: template
      value_template: '{{as_timestamp(states.automation.sunscreen_down.attributes.last_triggered) | int <= as_timestamp(states.automation.sunscreen_up.attributes.last_triggered) | int }}' # this automation can only be triggered if timestamp of last_triggered time is OLDER than the timestamp of last_triggered time of the "screen up" automation. This condition prevents that the automation is triggered again if sunscreen is already down. Better would be to have a real sensor checking if sunscreen is up or down but currently I don't have a sensor in place. The | int is used to catch the fact that on start up both triggers report 'none' and hence this condition would never become true. The int makes it such that value = 0 for both and hence trigger can be executed.
  action:
    - service: cover.close_cover #closes/uitklappen the sunscreen - bit counterintuitive naming but close meeans it is folded out in my case)
      data:
        entity_id: cover.zonnescherm
    - service: notify.Telegram #Send message to inform about action
      data:
       message: "Het zonnescherm is naar beneden gedaan ivm de zon"

En voor inklappen:

- alias: Sunscreen up #Sunscreen up/inklappen
  initial_state: 'on' #on reboot HA or reloading of automations, automation is ON
  trigger:

  # Wather based triggers
  - platform: sun
    event: sunset
    offset: -02:30:00 #2,5 hours before sunset, sunscreen is going up again (might want to change depending on location)
  - platform: numeric_state
    entity_id: sensor.br_wind_force
    above: 7 #If wind force becomes to high, sunscreen needs to go up
  - platform: numeric_state
    entity_id: sensor.br_precipitation
    above: 0.01 # Rain at the moment
  - platform: numeric_state
    entity_id: sensor.br_precipitation_forecast_total
    above: 0.2 # Rain predicted in next 60 minutes
  - platform: numeric_state
    entity_id: sensor.br_irradiance
    below: 100
    for:
     minutes: 5 # Sunlight below X for Y minutes
  - platform: numeric_state
    entity_id: sensor.br_temperature
    below: 18 #If outdoor temperature is below x for y minutes then sunscreen can go up again.
    for:
      minutes: 10

  condition:
    condition: and
    conditions:
    - condition: template
      value_template: '{{as_timestamp(states.automation.sunscreen_up.attributes.last_triggered) | int <= as_timestamp(states.automation.sunscreen_down.attributes.last_triggered) | int }}' # this automation can only be triggered if timestamp of last_triggered time is OLDER than the timestamp of last_triggered time of the "screen down" automation. This condition prevents that the automation is triggered again if sunscreen is already up. Better would be to have a real sensor checking if sunscreen is up or down but currently I don't have a sensor in place. The | int is used to catch the fact that on start up both triggers report 'none' and hence this condition would never become true. The int makes it such that value = 0 for both and hence trigger can be executed.

  action:
    - service: cover.open_cover #close/inklappen the sunscreen - seems service is swapped
      entity_id: cover.zonnescherm
    - service: notify.Telegram #Send message to inform about action
      data:
       message: "Het zonnescherm is weer ingetrokken"
5 Likes

@oliesjeik
Any updates on your automation?

What hardware are you using for the screen?

Fibaro Roller Shutter 2. Or do you mean the awning itself?

The Awning itself. This is my next project outside of zoneminder and home security.

I think what matters is the motor you get with your awning. They come in different voltages. The Z-wave module has to be able to handle the voltage.

The Fibaro module allows to connect a hardwired switch as well. I didn’t install that but it would make a nice backup in case your Home Assistant is down for whatever reason.

So i changed a bit on it, but most is still the same. I do think you could use a template to do most sensors for numeric_state in 1 call. Changed some checks to not have the same on/off time since if you have multiple triggers it would also call the action twice. Also added the notify device state so you know what triggered your awning.

Now the only thing i would want to find out, how can i disable my fibaro shutter if the kitchen door is open? I have the check for automatic but if someone uses the switch manually it should be disabled. (easiest is to just cancel the command when the door is still open)

2 Likes

Thanks for sharing your configuration. I was thinking about your question. Assuming you are using Fibaro Roller Shutter 2, I found this in the manual:

Fibaro Roller Shutter uses the Protection Command Class v2 to prevent from unintended motor movement. Local Protection State:
0 - no protection. Roller Shutter responds to push buttons.
1 - not supported
2 - Local protection active. Roller Shutter does not respond to push buttons.

Once the Local Protection is activated, the module stops responding to S1 and S2 push buttons. SCENE ID and association commands will not be sent as well. The only exception is the B-button. Menu and Z-Wave network inclusion, after the B-button or S1 push button triple click, are still active.

In HA Z-Wave options for the Roller Shutter is the Protect option, I assume this is where you activate it:

Now to find out how you can use a service call to protect & unprotect… I don’t seem to find an appropriate one but perhaps you can find out?

Well the trick is to actually make the fibaro shutter “a dummy” so you can switch it, but then it will just announce “door is open, close it first please” and do nothing. But in order to receive the keypress it needs to be turned on. I could just instantly stop it, and revert it, but for all i know i opened it half way and if i revert it it would either go fully up or fully down. (and a revert needs to go both ways too)

In short, you click it -> it opens -> announce the door is open -> send stop command. Only then the shutter is in state ‘open’ even though it only opened it 1% (which makes the awning automation silly since it won’t open it anymore if the door is closed)

So yes, some hurdles to overcome, looking into the position thing now.

Also, do you have some way to make those icons better? They are all the same. Customize didn’t help change the icons although i did read it should change to something else.

Still seems to me like my suggestion could match what you are describing. If you could ‘protect’ the Fibaro from manual control (disabling the physical switch temporarily, turning it into a ‘dummy’), the Fibaro module would still be turned on. So in theory, it could detect the key press, and Home Assistant could respond by announcing ‘Hey close the door first’. Then when the door is closed, you could ‘unprotect’ the Fibaro and the buttons would work again.

Unfortunately this is all theory, but you could investigate further :slight_smile:

Edit: there’s even a configuration option for it… you should definitly try this :sunny:

Try to set it to different values and just check how the buttons are responding; is the button press still picked up by HA? If it works, you could set it from your automation using service zwave.set_config_parameter

I tried playing with it. But if you set it, it does still allow you to use a button. So it doesn’t work. Also if i click the options i see 3 options. No protection, Local Protection and 3rth one “Not Supported” perhaps that just indicates that it is not supported?

You can however protect the node. The setting below it.

But… when manually switching the device it doesn’t report back anything anymore.

This is what i see btw:

Do you have a shutter v3 or something else?

p.s. also the blind settings doesn’t work, read that on the forums. Its some fibaro specific thing and it does not work in openzwave. Might be the same with this. I’ll just do a quick check and stop with a sound. That works also (not the nicest, but enough for now)

Too bad, but good for you for finding a solution of sorts

Just a big thank you to all the contributers here. All your work make a very very good template so saves me so much time and thinking… cheers!

And i thank the same from whom i got the information too. I always try to put the topic/post in my package/yaml files at the top as comment so when people read it on github they know where it came from. (and it is also easy for yourself to check if there are updates)

Since we’re all sharing; here’s an update of my most recent version of the ‘sunscreen’ automation :slight_smile:

Changes:

  1. Weather Underground is no longer available if you’re not operating your own weather station. I just installed my own weather station, it’s been especially helpful for wind so far.
  2. The forecast for ‘high temperature today’ is coming from DarkSky now (not Weather Underground).
  3. There are now 2 automations for automatically rolling it up: 1 for ‘urgent up’ (rain/wind/sunset) and 1 for ‘regular up’. The ‘urgent up’ automation is always active, while the ‘regular up’ is inactive if you choose to operate the awning manually (= from Google Home in my case). This has increased the WAF significantly.

Automations:

- alias: Awning automatically down
  trigger:
  - platform: time_pattern
    minutes: '/1'
    seconds: 1
  condition:
    condition: and
    conditions:
    - condition: numeric_state
      entity_id: sun.sun
      value_template: '{{ states.sun.sun.attributes.azimuth }}'
      above: 130
      below: 265
    - condition: state
      entity_id: sun.sun
      state: 'above_horizon'
    - condition: state
      entity_id: cover.zonnescherm_level
      state: open
      for:
        minutes: 30
    - condition: sun
      before: sunset
      before_offset: -00:45:00
    - condition: numeric_state
      entity_id: sensor.dark_sky_daytime_high_temperature_0d
      above: 18
    - condition: numeric_state
      entity_id: sensor.wind_kph_avg_mean
      below: 7
    - condition: numeric_state
      entity_id: sensor.br_precipitation_forecast_total
      below: 0.1
    - condition: template
      value_template: '{{ now().month > 2 }}'
    - condition: template
      value_template: '{{ now().month < 10 }}'
    - condition: numeric_state
      entity_id: sensor.irradiance_avg_mean
      above: 350
    - condition: state
      entity_id: input_boolean.vacation_mode
      state: 'off'
    - condition: state
      entity_id: input_boolean.sunscreen_manual_up
      state: 'off'
  action:
    - service: switch.turn_on
      entity_id: switch.sunscreenswitch
    - service: notify.by_telegram
      data:
        message: The awning has automatically rolled down.

- alias: Sunscreen up with urgency
  trigger:
  - platform: sun
    event: sunset
    offset: -00:45:00
  - platform: numeric_state
    entity_id: sensor.wind_kph_avg_mean
    above: 7
  - platform: numeric_state
    entity_id: sensor.br_precipitation_forecast_total
    above: 0.2
  condition:
    condition: state
    entity_id: cover.zonnescherm_level
    state: closed
    for:
      seconds: 30
  action:
  - service: switch.turn_off
    entity_id: switch.sunscreenswitch
  - service: input_boolean.turn_off
    entity_id: input_boolean.sunscreen_manual_down
  - service: notify.by_telegram
    data:
      message: The awning was rolled up because of wind, predicted rain or nearing sunset. 

- alias: Awning automatically up low sunlight
  trigger:
    - platform: numeric_state
      entity_id: sensor.irradiance_avg_mean
      below: 290   # low sunlight
    - platform: numeric_state
      entity_id: sun.sun
      value_template: '{{ states.sun.sun.attributes.azimuth }}'
      above: 270   # the sun is no longer hitting the window
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: cover.zonnescherm_level
      state: closed
      for:
        seconds: 30  # the time it takes for the awning to fully open or close
    - condition: state
      entity_id: input_boolean.sunscreen_manual_down
      state: 'off'    # the awning was not manually opened
    - condition: sun
      after: sunset
      after_offset: "-4:00:00"  # sunset is within 4 hours
  action:
  - service: switch.turn_off
    entity_id: switch.sunscreenswitch
  - service: notify.by_telegram
    data:
      message: The awning was rolled up because of low sunlight (< 290 W/m2 or azimuth > 270) and sunset is within 4 hours.
4 Likes

I see you also changed the precipitation to 0.2, did the same since it was giving some false ones (or just so tiny it didn’t matter)

For note nr 3, you say for use with google home. Do you mean that if she says “sunscreen down” it will not allow automatic going open, or manual interaction? Uncertain what you mean now :wink:

Also added a door sensor with it, if the screen is open and the door is half way open it would crush against the door. So the door needs to be closed, if not it will send a message.

I also wanted to share my code…
I use 5 Somfy stateless sunscreens and 1 Somfy stateless awning.
Because all my covers are stateless, I made for every cover a template_cover like this:

  - platform: template
    covers:
      keuken_1_temp:
        friendly_name: "Keuken 1"
        value_template: "{{ is_state('input_boolean.keuken_1_closed', 'off')}}"
        open_cover:
          service: script.turn_on
          data:
            entity_id: script.keuken_1_openen
        close_cover:
          service: script.turn_on
          data:
            entity_id: script.keuken_1_sluiten
        stop_cover:
          service: cover.stop_cover
          data:
            entity_id: cover.keuken_1

and this are those 2 scripts:

  keuken_1_sluiten:
    sequence:
      - service: cover.close_cover
        entity_id: cover.keuken_1
      - delay:
          seconds: 20
      - service: input_boolean.turn_on
        entity_id: input_boolean.keuken_1_closed
      
  keuken_1_openen:
    sequence:
      - service: cover.open_cover
        entity_id: cover.keuken_1
      - delay:
          seconds: 20
      - service: input_boolean.turn_off
        entity_id: input_boolean.keuken_1_closed

and this the used input_boolean:

  keuken_1_closed:
    name: Keuken 1 gesloten
    icon: mdi:arrow-down-bold-box-outline

Since my covers are on different sides of the house I made scripts for the ‘achtergevel’, ‘zijgevel’ and the ‘zonnetent’. They don’t have to be closed at the same time.
I calculated the azimut on this site http://shadowcalculator.eu/#/lat/50.08/lng/19.899999999999977
This is the automation to close the backside ‘achtergevel’:

  alias: Achtergevel sluiten #Sunscreen down/uitklappen
  initial_state: 'on' #on reboot HA or reloading of automations, automation is ON
  trigger:
    - platform: time_pattern
      minutes: '/5'
      seconds: 00
  condition:
    condition: and # all conditions need to be TRUE before action is executed.
    conditions:

      # Sun based conditions
      - condition: numeric_state
        entity_id: sensor.sun_azimut
        above: 80  
        below: 200
      - condition: numeric_state
        entity_id: sun.sun
        value_template: '{{ state.attributes.elevation }}'
        above: 15  
      - condition: or
        conditions:
          - condition: numeric_state
            entity_id: sensor.huidige_opbrengst
            above: 1200
          - condition: numeric_state
            entity_id: sensor.opbrengst_solaredge_kostal
            above: 1200

      # Weather based conditions
      - condition: numeric_state
        entity_id: sensor.windsnelheid
        below: 40 # Wind strenght - I still have to tune this value
      - condition: numeric_state
        entity_id: sensor.ba_precipitation_forecast_average
        below: 0.25 # Rain the next 15 min
      - condition: numeric_state
        entity_id: sensor.dark_sky_uv_index_0d
        above: 3 # This indicates direct sunlight on my location (as in: not cloudy)

      # Temperature based conditions
      - condition: numeric_state
        entity_id: sensor.buitentemperatuur_gefilterd
        above: 20 # only if outdoor temperature is above x then allowed to roll out
      - condition: numeric_state
        entity_id: sensor.gemiddelde_temp_beneden
        above: 22 # only if indoor temperature is above x then allowed to roll out
      - condition: numeric_state
        entity_id:  sensor.dark_sky_daytime_high_temperature_0d
        above: 23

      # Time based conditions
      - condition: template
        value_template: '{{ now().month > 3 }}' # Starting April
      - condition: template
        value_template: '{{ now().month < 10 }}' # Ending October
      - condition: template
        value_template: >
          {{  is_state('input_boolean.keuken_1_closed', 'off') or
              is_state('input_boolean.keuken_2_closed', 'off') or
              is_state('input_boolean.slaapkamer_closed', 'off')  }}

      # No others screens are closing
      - condition: state
        entity_id: script.zijgevel_sluiten
        state: "off"
      - condition: state
        entity_id: script.zonnetent_my
        state: "off"

  action:
    - service: script.achtergevel_sluiten
    - service: notify.mobile_app_gphone
      data:
       message: "Het zonnescherm achtergevel gesloten"
    - delay:
        minutes: 5
    - service: script.achtergevel_sluiten

and this the script:

  achtergevel_sluiten:
    sequence:
      - service: cover.close_cover
        entity_id: cover.keuken_1_temp
      - delay:
          seconds: 10
      - service: cover.close_cover
        entity_id: cover.keuken_2_temp
      - delay:
          seconds: 10
      - service: cover.close_cover
        entity_id: cover.slaapkamer_temp
      - delay:
          seconds: 10
      - service: input_boolean.turn_on
        entity_id: input_boolean.achtergevel_closed

The automation to open my ‘achtergevel’:

  alias: Achtergevel openen #Sunscreen up/inklappen
  initial_state: 'on' #on reboot HA or reloading of automations, automation is ON
  trigger:

    # Sun based triggers
  - platform: numeric_state
    entity_id: sensor.sun_azimut
    above: 250
  - platform: state
    entity_id: sensor.dark_outside
    to: 'on'
  - platform: numeric_state
    entity_id: sensor.zonne_energie_gefilterd_lowpass
    below: 350
    
    # Weather based triggers
  - platform: numeric_state
    entity_id: sensor.windsnelheid
    above: 40 #If wind force becomes to high, sunscreen needs to go up
  - platform: numeric_state
    entity_id: sensor.ba_precipitation_forecast_average
    above: 0.30  # Rain the next 15 min

  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.achtergevel_closed
        state: 'on'

  action:
    - service: script.achtergevel_openen 
    - service: notify.mobile_app_gphone
      data_template:
       message: "Het zonnescherm achtergevel geopend, reden {{trigger.entity_id}} "
    - delay:
        minutes: 5
    - service: script.achtergevel_openen 

and the script:

  achtergevel_openen:
    sequence:
      - service: cover.open_cover
        entity_id: cover.keuken_1_temp
      - delay:
          seconds: 10
      - service: cover.open_cover
        entity_id: cover.keuken_2_temp
      - delay:
          seconds: 10
      - service: cover.open_cover
        entity_id: cover.slaapkamer_temp
      - delay:
          seconds: 10
      - service: input_boolean.turn_off
        entity_id: input_boolean.achtergevel_closed
      - delay:
          minutes: 1
      - condition: or
        conditions:
          - condition: state
            entity_id: 'input_boolean.keuken_1_closed'
            state: 'on'
          - condition: state
            entity_id: 'input_boolean.keuken_2_closed'
            state: 'on'
          - condition: state
            entity_id: 'input_boolean.slaapkamer_closed'
            state: 'on'
      - service: cover.open_cover
        entity_id: cover.keuken_1_temp
      - delay:
          seconds: 10
      - service: cover.open_cover
        entity_id: cover.keuken_2_temp
      - delay:
          seconds: 10
      - service: cover.open_cover
        entity_id: cover.slaapkamer_temp
      - delay: '00:01:10'
      - condition: or
        conditions:
          - condition: state
            entity_id: 'input_boolean.keuken_1_closed'
            state: 'on'
          - condition: state
            entity_id: 'input_boolean.keuken_2_closed'
            state: 'on'
          - condition: state
            entity_id: 'input_boolean.slaapkamer_closed'
            state: 'on'
      - service: cover.open_cover
        entity_id: cover.keuken_1_temp
      - delay:
          seconds: 10
      - service: cover.open_cover
        entity_id: cover.keuken_2_temp
      - delay:
          seconds: 10
      - service: cover.open_cover
        entity_id: cover.slaapkamer_temp
      - delay: '00:01:10'
      - condition: or
        conditions:
          - condition: state
            entity_id: 'input_boolean.keuken_1_closed'
            state: 'on'
          - condition: state
            entity_id: 'input_boolean.keuken_2_closed'
            state: 'on'
          - condition: state
            entity_id: 'input_boolean.slaapkamer_closed'
            state: 'on'
      - service: notify.mobile_app_gphone
        data_template:
          message: "Der is iets mis me die Somfy's van den achtergevel. Fix het maar!! "

If you have questions, shoot…

5 Likes

Roelof, Is your automation giving you the behavior you want?
Is Dark sky accurate enough?

I am also trying to perfectly automate my screens.
The difference is that i want to roll them down based on lux values from different sensors around the house. I tried it in home assistant but that does not give me the result i want.
I can’t get the timer to work correct. I want to have a steady reading for x minutes above a certain value. If it drops below that value the timer should start over. this wil make sure the screens only go down if it has been sunny for a while.
With NodeRed i managed to get this to work correct, but i don’t know how to implement all the other conditions that have to be met. And how to manage the screen up automation.

@ Giel,
That is an impressive set if lines you made.
The question to you also, does this give you the desired behavior? no intervention needed?

I went with the lux sensors so i get actual local readings.
I am also thinking of using a rain sensor for the screens to go up instantly on rain.
But of course i don’t want the screens to go up and down the whole time.

The only intervention I ever did was, when one of my covers didn’t receive the “open” command due an error at the somfy servers…