Sun cover closing

Hi there

I’m trying to set up an automation that automatically closes the sun cover on the terrace, only when outside is sunny or partly cloudy and when the temperature is above 18°. This should happen only between noon and 16:00 (when the sun will be on my terrace).

The idea is to use as condition the forecast from weather.casa entity and to take the exact temperature from a sonoff temperature sensor placed on the terrace called sensor.sensore_temperatura_temperature.

Any idea how to write this automation? Which should be the trigger? Time? But what if for example at 13:00 the temperature is low and it gets hotter only after?

This automation should run only if somebody is home using the person tracking.

Maybe the solution it’s easy, but I can’t see it! :sweat_smile:

Thanks for helping!

You could do something like this (and there are multiple ways to accomplish what you want), where it’s checking every 5 minutes for changes in the weather and then uses conditions to test if those changes require automation to run:

trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: numeric_state
    entity_id: sensor.openweathermap_temperature
    above: '18'
  - condition: and
    conditions:
      - condition: state
        entity_id: sensor.openweathermap_condition
        state: partly_cloudy
      - condition: or
        conditions:
          - condition: state
            entity_id: sensor.openweathermap_temperature
            state: sunny

You will just have to verify the actual state values of whatever is tracking your weather conditions.

Sounds good, but how can I add the condition between noon and 16:00?

Just keep stacking ANDs where needed. It’s quite simple to do in the UI:

trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: numeric_state
    entity_id: sensor.openweathermap_temperature
    above: '18'
  - condition: and
    conditions:
      - condition: state
        entity_id: sensor.openweathermap_condition
        state: partly_cloudy
      - condition: or
        conditions:
          - condition: state
            entity_id: sensor.openweathermap_temperature
            state: sunny
  - condition: and
    conditions:
      - condition: time
        after: '12:00:00'
        before: '16:00:00'

Something like this should work?

alias: 'Tende sole: abbassa con notifica'
description: ''
trigger:
  - platform: time_pattern
    minutes: '5'
condition:
  - condition: numeric_state
    entity_id: sensor.sensore_temperatura_temperature
    above: '18'
  - condition: and
    conditions:
      - condition: state
        entity_id: weather.casa
        attribute: forecast
        state: sunny
      - condition: or
        conditions:
          - condition: state
            entity_id: weather.casa
            attribute: forecast
            state: partlycloudy
  - condition: and
    conditions:
      - condition: time
        after: '12:00:00'
        before: '16:00:00'
  - condition: and
    conditions:
      - condition: state
        entity_id: device_tracker.iphone_12_di_luca_2
        state: home
      - condition: or
        conditions:
          - condition: state
            entity_id: device_tracker.iphone_di_ambra
            state: home

But I’m wondering… won’t this keep happening every 5 minutes? I mean, if all conditions are true, my cover will go down, ok. But the automation will trigger again after 5 min forever?

There can always be another condition that stipulates that the cover must be up for it to fire.

I’ve created an input boolean to verify when the cover are closed or open. Let’s see if this will work!

This time pattern says that the automation will fire on the 5th minute of every hour while /5 means it runs every 5 minutes. It doesn’t have to be time based, if you have another condition that changes regularly enough then you could use that too.

Hi,
since I want to protect the plants at my terrace (south) window the whole year around, I run it by checking the cloud coverage in % either by a openweathermap or accuweather sensor as a trigger and suns azimuth as a condition. The point when the sun is shining into this window (= when a certain azimuth is reached) is here in winter ~ 2 hours earlier than in summer, that’s why I don’t use time values.
My cover only has down/stop/up buttons, means I can’t stop it at a certain state nore can I read its state. Therefore I create a switch input_boolean.cover_down

So, if the cloud coverage is lower than 50% for 10 minutes and if the suns azimuth is between 130° and 260° and if input_boolean.cover_down is off, the covers down switch is triggered for 9 seconds, which lowers the cover a bit more than half and the input_boolean.cover_down switch is set to on.
In case the cloud coverage would go above 50% and afterwards again lower 50% while within the azimuth range, it wouldn’t be triggered again.

1 Like

If you wanted to get a bit fancier with it you could add a door sensor (or similar) that engages when the end of the awning reaches the fully retracted state and take some of the guesswork out of it. But, I understand what you mean, I have drapes that work like that and I have to just “guess” as to where they are in the opening/closing process using timing and some clever script tricks.

You can do some fancy conditions with the azimuth of the sun to fully automate this process, and that would certainly be a perfect trigger for you rather than time based or device based since it changes regularly and you can use your input boolean to just know when it’s open and when it’s closed to complete the picture (and can even drill down further into actions and define CHOOSE methods). I use azimuth for my drapes for the same reason.

1 Like

This is the final configuration:


alias: 'Tende sole: abbassa con notifica'
description: ''
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: numeric_state
    above: '18'
    entity_id: sensor.ewelink_temperatura
  - condition: and
    conditions:
      - condition: state
        entity_id: weather.casa
        attribute: forecast
        state: sunny
      - condition: or
        conditions:
          - condition: state
            entity_id: weather.casa
            attribute: forecast
            state: partlycloudy
  - condition: and
    conditions:
      - condition: time
        after: '12:00:00'
        before: '16:00:00'
  - condition: and
    conditions:
      - condition: state
        entity_id: device_tracker.iphone_12_di_luca_2
        state: home
      - condition: or
        conditions:
          - condition: state
            entity_id: device_tracker.iphone_di_ambra
            state: home
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.tende
        state: 'off'
action:
  - service: notify.mobile_app_iphone_12_di_luca
    data:
      title: TENDE DA SOLE
      message: 'Sembra che oggi faccia caldo, vuoi abbassare le tende da sole?'
      data:
        push:
          category: ABBASSATENDE
  - service: notify.mobile_app_iphone_di_ambra
    data:
      title: TENDE DA SOLE
      message: 'Sembra che oggi faccia caldo, vuoi anbassare le tende da sole?'
      data:
        push:
          category: ABBASSATENDE
mode: single

I just tried to run the automation manually but something seems wrong! At the moment the temperature is above 18 degrees, but outside is raining! In this case the automation shouldn’t work but it does! It skips also the time condition!
If I check the debug seems that since the first condition (temperature) is true, it skips the other conditions going directly to the action! In each following condition the debug says “ This node was not executed and so no further trace information is available.”

Any suggestion?

Because when you manually execute an automation it skips the automation’s trigger and condition. Only the automation’s action is executed. It’s explained here:

Instead of using a Time Pattern Trigger to make Home Assistant repeatedly check if all the listed conditions are true (every 5 minutes), just let the events themselves trigger the automation when they occur.


alias: 'Tende sole: abbassa con notifica'
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.ewelink_temperatura
    above: '18'
  - platform: template
    value_template: "{{ states('weather.casa') in ['sunny', 'partcloudy'] }}"
  - platform: state
    entity_id: input_boolean.tende
    to: 'off'
  - platform: state
    entity_id: device_tracker.iphone_12_di_luca_2
    to: 'home'
  - platform: state
    entity_id: device_tracker.iphone_di_ambra
    to: 'home'
  - platform: time
    at: '12:00:00'
condition:
  - condition: numeric_state
    entity_id: sensor.ewelink_temperatura
    above: '18'
  - "{{ states('weather.casa') in ['sunny', 'partcloudy'] }}"
  - condition: time
    after: '12:00:00'
    before: '16:00:00'
  - "{{ is_state('device_tracker.iphone_12_di_luca_2', 'home') or is_state('device_tracker.iphone_di_ambra', 'home') }}"
  - condition: state
    entity_id: input_boolean.tende
    state: 'off'
action:
  - service: notify.mobile_app_iphone_12_di_luca
    data:
      title: TENDE DA SOLE
      message: 'Sembra che oggi faccia caldo, vuoi abbassare le tende da sole?'
      data:
        push:
          category: ABBASSATENDE
  - service: notify.mobile_app_iphone_di_ambra
    data:
      title: TENDE DA SOLE
      message: 'Sembra che oggi faccia caldo, vuoi anbassare le tende da sole?'
      data:
        push:
          category: ABBASSATENDE
mode: single

The automation is triggered (and all the conditions are checked) whenever any of the following occurs:

  • The temperature rises above 18.
  • The weather changes to either sunny or partlycloudy.
  • The input_boolean is turned off.
  • Luca or Ambra arrive home.
  • The time is noon.
1 Like

Yes the problem with this solution is that the automation will be triggered also if outside there are more than 18° but it’s raining! Isn’t it?

Yes, it will be triggered when the temperature exceeds 18 but the condition will determine if the action should be executed.

I suspect you don’t understand what I have proposed and how it compares to the automation with a Time Pattern Trigger.

  • In the automation you have now, what happens when the temperature rises above 18? The answer is nothing until the Time Pattern Trigger triggers at its 5-minute intervals. When it does trigger, it checks all the conditions. If the temperature is above 18 but none of the other conditions are true then it doesn’t execute the action.

  • In the automation I suggested, what happens when the temperature rises above 18? The answer is it immediately checks all the conditions. It doesn’t wait for the next 5-minute interval, it acts immediately. If the temperature is above 18 but none of the other conditions are true then it doesn’t execute the action.

2 Likes

It works perfectly!

I’ve built also the opposite version:

alias: '1Tende sole: alza automaticamente'
description: ''
trigger:
  - platform: numeric_state
    entity_id: weather.casa
    attribute: temperature
    below: '15'
  - platform: template
    value_template: '{{ states(''weather.casa'') in [''cloudy'', ''rainy''] }}'
  - platform: numeric_state
    entity_id: weather.casa
    attribute: wind_speed
    above: '40'
condition:
  - condition: state
    entity_id: input_boolean.tende
    state: 'on'
action:
  - scene: scene.tende_sole_su
  - service: notify.mobile_app_iphone_di_ambra
    data:
      title: TENDE DA SOLE
      message: 'Pare che il tempo sia cambiato, alzo le tende da sole'
  - service: notify.mobile_app_iphone
    data:
      message: 'Pare che il tempo sia cambiato, alzo le tende da sole'
      title: TENDE DA SOLE
mode: single