cancel
Showing results for 
Search instead for 
Did you mean: 

Automation that ends if the sun sets after 18:30

Joakim_Lind
Community Member

Is it possible to make an comming home automation script that turn on all 2 lights when the sun is set. But by 18:30 at night the automation should not run. Because the sun sets after 18:30 i the summer time and before in the winter I can´t figured out how this should be made?

2 Recommended AnswerS

jwl_
Community Member

If I understand what you're asking, what about something like this?

 

metadata:
  name: Coming home lighting
  description: Turn on 2 lights when someone arrives home after sunset but before 18:30
automations:
  - starters:
      type: home.state.HomePresence
      state: homePresenceMode
      is: HOME
    condition:
      type: time.between
      before: 18:30
      after: sunset
    actions:
      type: device.command.OnOff
      on: true
      devices:
        - Light 1 - Home
        - Light 2 - Home

 

 

View Recommended Answer in original post

jwl_
Community Member

In that case, you can try to do an "AND" conditional with another set of times to make sure it falls between a standard range.  Maybe something like this where you can change the second time conditions to fit your needs?

 

metadata:
  name: Coming home lighting
  description: Turn on 2 lights when someone arrives home after sunset but before 18:30
automations:
  - starters:
      type: home.state.HomePresence
      state: homePresenceMode
      is: HOME
    condition:
      type: and
      # "AND" together two or more conditionals
      conditions:
        - type: time.between
          before: 18:30
          after: sunset
        - type: time.between
          before: 18:30
          after: 15:00
    actions:
      type: device.command.OnOff
      on: true
      devices:
        - Light 1 - Home
        - Light 2 - Home

 

 

View Recommended Answer in original post

8 REPLIES 8

OpethNJ
Community Member

Script Editor FTW , along with a very similar script to what you want to do. If this doesn't make sense just let me know. 

 

metadata:
  name: Scheduled lighting
 
description: Turn on the lights at sunset, dim them at 10pm and turn them off at midnight.
automations:
# At sunset
- starters:
  - type: time.schedule
   
at: SUNSET
 
actions:
  # Adjusting brightness will automatically turn on the lights.
 
# No need to add a separate OnOff command.
 
- type: device.command.BrightnessAbsolute
   
devices:
    - Christmas lights - Living Room
   
brightness: 100

# At 10 PM
- starters:
  - type: time.schedule
   
at: 22:00
 
actions:
  - type: device.command.BrightnessAbsolute
   
devices:
    - Christmas lights - Living Room
   
brightness: 50

# At midnight
- starters:
  - type: time.schedule
   
at: 00:00
 
actions:
  - type: device.command.OnOff
   
devices: Christmas lights - Living Room
   
on: false

 

 

No, this does not make sense to my question.

jwl_
Community Member

If I understand what you're asking, what about something like this?

 

metadata:
  name: Coming home lighting
  description: Turn on 2 lights when someone arrives home after sunset but before 18:30
automations:
  - starters:
      type: home.state.HomePresence
      state: homePresenceMode
      is: HOME
    condition:
      type: time.between
      before: 18:30
      after: sunset
    actions:
      type: device.command.OnOff
      on: true
      devices:
        - Light 1 - Home
        - Light 2 - Home

 

 

Joakim_Lind
Community Member

Yes, that would work if the sun did´nt set after 18:30 in the summer time. So it will turn on the light after 18:30 in the summer time.

It would work if it was possable to add a second condition between sunset and sunrise.

Is it possable to do that?

jwl_
Community Member

In that case, you can try to do an "AND" conditional with another set of times to make sure it falls between a standard range.  Maybe something like this where you can change the second time conditions to fit your needs?

 

metadata:
  name: Coming home lighting
  description: Turn on 2 lights when someone arrives home after sunset but before 18:30
automations:
  - starters:
      type: home.state.HomePresence
      state: homePresenceMode
      is: HOME
    condition:
      type: and
      # "AND" together two or more conditionals
      conditions:
        - type: time.between
          before: 18:30
          after: sunset
        - type: time.between
          before: 18:30
          after: 15:00
    actions:
      type: device.command.OnOff
      on: true
      devices:
        - Light 1 - Home
        - Light 2 - Home

 

 

Joakim_Lind
Community Member

That was exactly what I tried to do but I got an error when I had 2 conditions. But now when I tried this again there was no errors. So this made the trick.

Thank you for your help!

ViciousNarwhal
Community Member

Just a thought for future, if you have something with a lux sensor, you can create the automation to turn on the lights is the level is too low.  This works irrespective of time of day like if it is really stormy.

Joakim_Lind
Community Member

So yesterday when we got home the lights turned on when the sun was still upp. I have not made any changes and another routine with only sunset to sunrise and no "AND" command still works.

My goal is to turn the lights on after sunset but not if the time is 18:30 or later.

# ------------------------------------------------------------------------------------------ #
# Lines starting with “#” are comments and will be ignored by the automation.
# Indentation determines hierarchy within the script.
# Visit g.co/home/script-editor-docs for full documentation.
# ------------------------------------------------------------------------------------------ #

metadata:
name: Tänd sovrum vid hemkost # Choose a short name that summarizes important starters and actions, like “Sunset lights”.
description: Tänd sovrummen vid hemkost senast 18:30 # Write a detailed description that includes everything the automation does, like “At sunset, on weekdays, close blinds, turn on lights to 50%, and play the sunset playlist on certain speakers.”

automations:
# “starters” and “actions” are required; “conditions” are optional.
# Use Ctrl + Space to see autocomplete suggestions.

# ---- STARTERS ---- #
# Starters describe events that will start the automation.
# To add more than one starter, duplicate the "- type" section under "starters".
# If you add multiple starter events, any one of them happening will start the automation.
starters:
- type: home.state.HomePresence
state: homePresenceMode
# [available operators: is, isNot]
is: HOME

# ---- CONDITIONS ---- #
# Conditions are optional. Delete this section if it’s empty.
# Conditions will prevent an automation from starting if the conditions aren’t met.
# See g.co/home/script-editor-docs for documentation about how to use logical operators like “and”, “or”, and “not”.
condition:
type: and
# "AND" together two or more conditionals
conditions:
- type: time.between
# Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
before: sunrise
# Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
after: sunset
# Optional. Days of the week to apply condition on.
weekdays:
- MON
- TUE
- WED
- THU
- FRI
- SAT
- SUN
- type: time.between
# Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
before: 18:30
# Optional. Accepts either clock time (10:00:00 AM, with seconds optional, or in a 24 hour format), or 'sunrise' or 'sunset', with an optional offset ('sunrise+10m', for instance)
after: sunrise
# Optional. Days of the week to apply condition on.
weekdays:
- MON
- TUE
- WED
- THU
- FRI
- SAT
- SUN

# ---- ACTIONS ---- #
# Actions will start when a starter event takes place and all conditions are met.
# Actions will start in the order they appear in the script and with any delay specified.
# To add more than one action, duplicate the "- type" section under "actions".
actions:
- type: device.command.OnOff # Turn the device on or off.
# Whether to turn the device on or off.
on: true
devices:
- Ellas fönsterlampa - Ellas rum
- Sovrumsfönstret - Sovrum
- Edvins fönsterlampa - Edvins rum