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
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"