How to stop automation from looping

I have the following code which is (probably) working but I need some help in order to triggered once and avoid looping
What can i do?

- id: test Awnings
  alias: Awnings_windy
  trigger:
    platform: numeric_state
    entity_id: sensor.dark_sky_wind_speed
    above: 20
  condition:    
    condition: template
    value_template: >
       {{(states('sensor.dark_sky_wind_speed') | float)}}
  action:
    - service: cover.close_cover
      entity_id: cover.50758014840d8e918614

I don’t see anything here that would “loop.” Also I don’t understand the point of your condition, which isn’t testing anything. (As written, the condition would be true whenever the value is non-zero. EDIT: Actually, now that I think about it some more I think it would never let the automation run. It would always evaluate to some string other than 'true'.)

Maybe you could provide some more insight into what problem you’re having.

Can you explain what you want it to do? I can’t figure out what that condition is meant to mean, for example. The condition should bee a boolean (true/false) expression, but yours is a float, so when does the condition hold?

See https://www.home-assistant.io/docs/automation/trigger/#numeric-state-trigger for some more examples. And you probably want a “for:” to make it trigger only after it has been above 20 for some number of seconds.

For comparison, here is my working automation for a fridge thermometer to tell me if I forgot to close the door:

- alias: Kylskåpsvarning                                                                                                           
  trigger:                                                                                                                         
  - above: '9'                                                                                                                     
    below: '100'                                                                                                                   
    entity_id: sensor.kylskapet_temperature                                                                                        
    for: 00:01:00                                                                                                                  
    platform: numeric_state                                                                                                        
  # no condition                                                                                                                   
  action:                                                                                                                          
  - data:                                                                                                                          
      message: Det är {{ states('sensor.kylskapet_temperature') }}°C i kylskåpet.                                                  
        Stäng det nu!                                                                                                              
      title: Kylskåpet är öppet                                                                                                    
    service: notify.bullit                                                                                                         

you are right
if I have understand and implement correct (first month user) the code supposed to
check the wind speed and if is >20 km/h would close the awning

however what I forgot to mention is that I prefer to alter the code as below.
My best case scenario is the awning not to be fully closed but partial.
Since I can not set the position easily I thought the following workaround.
But in this case, I think that I have to avoid looping

- id: test Awnings
  alias: Awnings_windy
  trigger:
    platform: numeric_state
    entity_id: sensor.dark_sky_wind_speed
    above: 20
  condition:    
    condition: template
    value_template: >
       {{(states('sensor.dark_sky_wind_speed') | float)}}
  action:
- service: cover.close_cover
      entity_id: cover.50758014840d8e918614
    - delay: 
        seconds: '60'  #(full closed)
    - service: cover.open_cover
      entity_id: cover.50758014840d8e918614
    - delay: 
         seconds: '10' #partial opend
    - service: cover.stop_cover
      entity_id: cover.50758014840d8e918614

if I enter in the developers toll the

{{(states('sensor.dark_sky_wind_speed') | float)}}

I getting (right now) 4.05

So I assume that the code is reading 4.05 and will be triggered when it will be 21 for example
Isn’t that right?

We’re not sure if it will trigger at all with that condition block, which you should remove. Does your cover not support the cover.cover_set_position service? And what do you mean by “avoid looping”?

Probably not
see here

No, the thing that checks tha value to determine whether it shoul trigger is the trigger. The condition should be true or false, based on things like whether the sun is up or you set an input_boolean or something. See the documentation link I provided, it has an example of a trigger with a value_template.

Disclaimer: I’m kind of new to home assistant myself.

To clarify, your trigger block looks ok. The condition block does not. Also, again, what do you mean by “avoid looping”?

Let me explain what I need.
My awning is almost always opened. I need to ensure that if it is windy to stay opened but at 20% for example.

So lets say is opened at 50% position. Ideally (if the wind is ?20km/h) the code should say go to 20% .
Since the position is not available I need it to close the awning, then open it and stop after 10 seconds which equals to 20%

But since it will open again and the condtion will met again (wind >20km/h) it will loop (i think)

No, the trigger will only “fire” when the value goes from 20 or below to above 20. In order for the actions to run a second time, the speed would have to go to 20 or below, and then rise above 20 again.

It sounds like you haven’t even tried the code yet. It’s best to experiment and only ask for help when things don’t work the way you expect. We all had to read the docs and experiment a bit to learn how to use HA. Welcome to the club! :smile:

Also, remove the condition. The way it is written it will never work.

Oh I see what you’re saying. Unless you have another automation to open the awning to 100%, it won’t open back up all the way by itself. However, if the wind speed drops below 20 and then goes above 20 again, the automation will fire again, even if the awning is already in the desired position. It would be difficult to prevent this from happening without knowing its position.

One possible solution would be to add a portion to the action: block that turns off the awning automation and create another automation to turn the awning automation back on after the awning automation is off for a certain period of time. Make sense?

in the next 10 days weather forecast says wind below 20 and thought to debug before my awning is gone
:slight_smile:

So if I understand correct you are saying that only the trigger will do the trick so I am going to remove the condition

You only need a condition if you want an automation to only fire if something else is true. For example, I have an automation to turn on a certain group of lights when I disarm my alarm, but I only want it to turn those lights on at night. So, my trigger is “when the alarm is disarmed,” and my condition is “if it is nighttime.” If I didn’t have the condition, it would fire the automation every time I disarm my alarm.

I see what you mean and it makes sense

So, is there a way to make this code to run once a day only?
I mean that in a worst case the wind will go >20 and the awning should go at 20%.
If it will run only once it is fine with me because the awning will be in the desired position.

In general the problem is the following. My wife or my kid probably will forget the awning in whatever position. Some days the wind will rise to 40-50 for 2-3 hours and then drops

I need to be sure that the awning will be at 20% position (when there is wind they don’t play with the awning) . Of course I am not 100% sure that this is the best solution

FWIW, I think your second automation was close. Removing the condition, fixing an indentation error in the action part, and fixing comments, I think this is what you want (at least to start with):

- id: test Awnings
  alias: Awnings_windy
  trigger:
    platform: numeric_state
    entity_id: sensor.dark_sky_wind_speed
    above: 20
  action:
    - service: cover.close_cover
      entity_id: cover.50758014840d8e918614
    - delay: 
        seconds: '60'  #(full closed)
    - service: cover.open_cover
      entity_id: cover.50758014840d8e918614
    - delay: 
         seconds: '10' #partial opend
    - service: cover.stop_cover
      entity_id: cover.50758014840d8e918614

Yep, you can disable the automation when it runs by adding this to the bottom of the action block:

    - service: automation.turn_off
      entity_id: automation.awnings_windy

Then create another automation that turns the awning automation back on at whatever time you want (midnight, 08:00, etc.). This will basically tell Home Assistant “after you run this automation, I want you to ignore it until [whatever time you specify in the second automation]”

@ pnbruckner
thanks. this is what I keep to test and see how it goes

it is a coincidence but earlier I installed the life360 integration :slight_smile:
I can see me and my wife at home, but I am a little confused regarding an automation I am thinking to make that triggers when we both leave home (to close all the covers)
If it is not much trouble could you provide some sample code to start with?

The logic if noone is at home then close all the covers and light (perhaps and the awning :slight_smile: )

@Tediore
super. That’s very fine with me.I will add it
(I am out of home a lot of hours, meaning that I don’t have much time to test and my biggest fear is the awning to jump on and off all day long :slight_smile: