Condition: sun or entity_id: sun.sun?

Hello,

I have some lights on scripts for on with motion and off no motion detected, which work perfectly. I am just trying to sort out some conditions based on sun and time, I am confusing myself.

Which is best to use
condition: numeric_state
entity_id: sun.sun
value_template: β€˜{{ state.attributes.elevation }}’
below: 3.5
or
condition:

  • condition: sun
    after: sunset

as what I am wanting to do is have the bathroom light come on say between sunset and 1am at one brightness and between 1am-5am at another then back to full brightness from 5am to sunrise

I have it all working, but using
condition:

  • condition: time
    after: β€˜01:00:00’
    before: β€˜05:00:00’

etc but in the UK the days are getting longer (woo hoo) and thought it would be best to use the sun or sun.sun as well.

bit of a long post sorry but which is the best method and why please?

Cheers
Mark

1 Like

Your code is very hard to read. If you put your code inside triple quote marks like below it becomes way better readable (you can put code blocks inside these quote marks too)…

```your code here```

`condition:
condition: and
conditions:

  • condition: sun
    after: sunset
  • condition: time
    before: β€˜01:00:00’`

This is one I have just done, but my question really is… should I be using condition: sun or entity_id: sun.sun?
i.e.
`condition:
condition: and
conditions:

  • condition: numeric_state
    entity_id: sun.sun
    value_template: β€˜{{ state.attributes.elevation }}’
    below: 3.5
  • condition: time
    before: β€˜01:00:00’`

just not sure on the difference.

I guess you can do both. Using a value_template allows for more options, but can also get really complicated.

About the formatting: Put all your yaml code inside one set of tripple quotes. Your code looks much better and leaves indentation intact greatly improving readability…

condition:
  condition: and
  conditions:
  - condition: sun
    after: sunset
  - condition: time
    before: '01:00:00'
1 Like