Summer Automations Help

Hello everyone Id like some help with some summer automations and since im a noob I cannot figure it out how to start, Id like an automation to start when the sun is above the horizon from 20th of May till 15 of September and turn off4 minutes after , can anyone help please?

I’d like to,help, not do your work :wink:

You should start with the examples in the documentation

Post your own automation here and ask specifically where you get stuck

Thanks for the link bud , but does not help me a lot it only gives example with people in or out of home I want something else than that , thank you though, Im new in homeassistant and you know Im like numnumnuts

Actually the first example is about testing for sunset (what you want) but you’re missing the condition to check today against your timeframe. I would say read the docs and search the forum for examples first, then post your not completely working automation over here so we can help you fix the remaining issues.

After all, home assistant is not an out of the box solution and requires some DIY tinkering.

Good luck!

I know that, hope one day though someone could create a stringfy like add on for homeassistant :stuck_out_tongue:

Your description is a little vague. Can I assume that you want the automation to turn something on (a light maybe???) at sunrise and turn the same something off 4 minutes later, but it should only do so from 5/20 through 9/15? If so, maybe something like this is what you’re looking for:

automation:
  - alias: Summer
    trigger:
      platform: sun
      event: sunrise
    condition:
      condition: template
      value_template: >
        {% set date = now().date() %}
        {% set start = strptime(date.year ~ '-05-20', '%Y-%m-%d').date() %}
        {% set end = strptime(date.year ~ '-09-15', '%Y-%m-%d').date() %}
        {{ start <= date <= end }}
    action:
      - service: homeassistant.turn_on
        entity_id: ENTITY_ID
      - delay:
          minutes: 4
      - service: homeassistant.turn_off
        entity_id: ENTITY_ID

Just change ENTITY_ID to the entity ID of the thing you want to turn on and off.

Let me know if you have any questions.

I compiled it and looks like that (to explain what its all about , when the sun gets above the horizon and the conditions are from may to september “calendar.summer automations” and the timer count 3 minutes the switch will turn off) but I miss a condition which is timer I would like it to stop after 3 minutes its the second condition which is empty anyone can help?

automation:
  - alias: 'Summer Shadow 1 down off'
    trigger:
      - platform: state
        entity_id: sun.sun
        to: 'above_horizon'
    condition:
      - condition: state
        entity_id: calendar.summer_automations
        state: 'on'
    condition:
      - condition: state
        entity_id:
        state:
    action:
      service: switch.turn_off
      entity_id: switch.sonoff_100016270b_4

I think you need to understand how automations work. The trigger(s) determine when the action(s) will run. The condition(s) determine if the actions will run when a trigger event happens.

So, basically, at sunrise the condition(s) will be evaluated. If true, then the action(s) will run. If false, then the action(s) will not run. Specifically, a condition cannot “stop” the automation action(s) after they’ve already started to run.

What you want is not another condition, but a delay step in the action part. So:

automation:
  - alias: 'Summer Shadow 1 turn on, then off 3 minutes later'
    trigger:
      - platform: state
        entity_id: sun.sun
        to: 'above_horizon'
    condition:
      - condition: state
        entity_id: calendar.summer_automations
        state: 'on'
    action:
      - service: switch.turn_on
        entity_id: switch.sonoff_100016270b_4
      - delay:
          minutes: 3
      - service: switch.turn_off
        entity_id: switch.sonoff_100016270b_4

EDIT: So, you only need one automation, which can turn the switch on, then off three minutes later. You don’t need two automations.

load the season component and then use this sensor as a condition: https://www.home-assistant.io/components/season/

thank you all so much guys this condition is needed for all my summer actions different minutes to some but this is what i wanted so if i get it , in one action ill set up on and off right?

Sorry, I don’t really understand your question.

I was going to add, if you did still want to do the turn off part in a second automation, then you could certainly do that. However, the main point is, you need to change the trigger, not the condition, because you want to change when the action will run, not change if the action will run. So, if you wanted to do the turn off part in a second automation, then it would look like this:

automation:
  - alias: 'Summer Shadow 1 down off'
    trigger:
      - platform: state
        entity_id: sun.sun
        to: 'above_horizon'
        for:
          minutes: 3
    condition:
      - condition: state
        entity_id: calendar.summer_automations
        state: 'on'
    action:
      service: switch.turn_off
      entity_id: switch.sonoff_100016270b_4

or, using a sun trigger instead of a state trigger:

automation:
  - alias: 'Summer Shadow 1 down off'
    trigger:
      - platform: sun
        event: sunrise
        offset: '00:03:00'
    condition:
      - condition: state
        entity_id: calendar.summer_automations
        state: 'on'
    action:
      service: switch.turn_off
      entity_id: switch.sonoff_100016270b_4

Either way would work.

well for one of my summer ones i need the sun position in the sky so if it was like noon and the sun was to some degrees (guess its the sun elevation) then the switch would turn on and off also as a plus condition, so what could be added in the recipe? ( i hate time cause time stays the same sun does not though , and it gets darker every day more and more)

Again, sorry, not following your question. Must be a language thing.

In general there are a few ways to “play” with time. In the trigger, which decides when the action(s) of the automation will start to run, and in the action section itself, you can add delays or wait_templates. And when things get more complex, you might need/want to use a timer entity.

It’s kind of hard to provide a general answer here. As @metbril said, it’s often easier to get help if you try something, and if it doesn’t work, come to the forum to ask for specific help. In this case, though, I didn’t mind giving you a “push” in the right direction. :slight_smile:

ok Id like to ask a last question how to set a wait template I mean what if I want for a switch like the one you gave me to wait 3 minutes then start? for example if one switch turn off and another one waits to start after some minutes, for example could taht work in action ?

 action:
      - delay:
          minutes: 3
      - service: switch.turn_on
        entity_id: switch.sonoff_10005b7999_3
      - delay:
          minutes: 2
      - service: switch.turn_off
        entity_id: switch.sonoff_10005b7999_3

I think you’re misunderstanding how automation works. The answer depends on more than just the few specifics you supplied. If you haven’t read the docs yet, you definitely should.

If, ignoring all other details and context, you simply want to turn one switch on a certain number of minutes after another switch turns off, then that would not use a wait_template. That would be an automation like this:

automation:
  - alias: Blah, blah, blah
    trigger:
      platform: state
      entity_id: switch.SWITCH_1
      to: 'off'
      for:
        minutes: MINUTES
    action:
      service: switch.turn_on
      entity_id: switch.SWITCH_2

Or even this:

automation:
  - alias: Blah, blah, blah
    trigger:
      platform: state
      entity_id: switch.SWITCH_1
      to: 'off'
    action:
      - delay:
          minutes: MINUTES
      - service: switch.turn_on
        entity_id: switch.SWITCH_2

Yes, you can do that.

thank you I dont want to write too many lines if i can have that in less lines

Yes, it’s always better to find a simpler solution than a more complex one. However, the questions you’ve asked have been too vague. It’s really hard to provide a proper, simple solution when the requirements are not specific.

In any case, I hope I’ve given you some tips and tricks you find helpful.

you sure did my friend I ve wrote many automations in my notebook Id publish them but I dont want to tire noone I could share and tell me if they are wright If you feel like it they are here

OK guys that could activate the switch at sun elevation 36 and below? :

automation:
  - alias: 'Summer Shadow 1 up turn on, then off 3 minutes later'
    trigger:
      - platform: numeric_state
        entity_id: sun.sun
        value_template: '{{state.attributes.elevation}}'
        below: 36
    condition:
      - condition: state
        entity_id: calendar.summer_automations
        state: 'on'
    action:
      - service: switch.turn_on
        entity_id: switch.sonoff_100016270b_4
      - delay:
          minutes: 3
      - service: switch.turn_off
        entity_id: switch.sonoff_100016270b_4