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…