Dim by time but only if lights on, keeps breaking

Hi all

This used to work. Over the past while it’s gotten more and more unreliable and I don’t know what’s wrong with it.
Could someone take pity and point out my error? I’m the first to admit that I don’t even understand HASS syntax.
thanks

automation:
  alias: "Set dim level dusk"
  trigger:
  - platform: time
    after: "19:15"   #instantaneously at 8pm only, not 'after'
  - platform: state   #implicit OR betwen the two conditions
    entity_id: light.kitchen
    from: 'off'
    to: 'on'

  condition:
  - platform: state
    entity_id: light.kitchen
    state: 'on'
  - platform: time    #implicit AND
    after: "19:15"
    before: "21:59"

  action:
    service: light.turn_on
    entity_id: light.kitchen
    data:
      brightness: 50

automation 2:
  alias: "Set dim level 10pm"
  trigger:
  - platform: time
    after: "22:00"   #instantaneously at 10pm only, not 'after'
  - platform: state   #implicit OR betwen the two conditions
    entity_id: light.kitchen
    from: 'off'
    to: 'on'

  condition:
  - platform: state
    entity_id: light.kitchen
    state: 'on'
  - platform: time    #implicit AND
    after: "22:00"
    before: "23:59"

  action:
    service: light.turn_on
    entity_id: light.kitchen
    data:
      brightness: 25

automation 3:
  alias: "Set dim level overnight"
  trigger:
  - platform: time
    after: "00:00"   #instantaneously at midnight only, not 'after'
  - platform: state   #implicit OR betwen the two conditions
    entity_id: light.kitchen
    from: 'off'
    to: 'on'

  condition:
  - platform: state
    entity_id: light.kitchen
    state: 'on'
  - platform: time    #implicit AND
    after: "00:00"
    before: "05:45"

  action:
    service: light.turn_on
    entity_id: light.kitchen
    data:
      brightness: 15

automation 4:
  alias: "Set dim level daytime"
  trigger:
  - platform: time
    after: "07:00"   #instantaneously at 7am only, not 'after'
  - platform: state   #implicit OR betwen the two conditions
    entity_id: light.kitchen
    from: 'off'
    to: 'on'

  condition:
  - platform: state
    entity_id: light.kitchen
    state: 'on'
  - platform: time    #implicit AND
    after: "07:00"
    before: "18:59"

  action:
    service: light.turn_on
    entity_id: light.kitchen
    data:
      brightness: 254

@bluenote73

Something like this might work for you…

automation:
- alias: "Set dim level dusk"
    trigger:
      platform: time
      after: "19:15"                #instantaneously at 8pm only, not 'after'
    condition:
      condition: or
        - condition: state          #implicit OR betwen the two conditions
          entity_id: light.kitchen
          from: 'off'
          to: 'on'
        - condition: and
          conditions:
          - condition: state
            entity_id: light.kitchen
            state: 'on'
          - condition: time         #implicit AND
            after: "19:15"
            before: "21:59"
    action:
      service: light.turn_on
      entity_id: light.kitchen
      data:
        brightness: 50

It is can’t pinpoint exactly whats wrong. I am sure the actual syntax differs from the post. I just put this together because it is what I would try if I wanted to complete the same task.
You will get used to the Yaml and I am sure you know about tools like this. http://yaml-online-parser.appspot.com/ I just remember that the indents are 2 spaces.

I also use the include function and create and automation.yaml file.

when you have multiple entries of something like and automation, sensor, switch, etc. you only have to define it once. This helps me to keep a cleaner look to my files. So instead of…

automation:
alias:
  trigger:

automation_2:
alias:
  trigger:

you can just declare automation or components once and add new automations by the - alias or sensors by - platform

automation:
- alias: function of automation
    trigger:

- alias: ""
    trigger:

or

sensor:
- platform: finance
  other_data:

- platform: statistics
  entity_id:

Just a suggestion. Best of luck!

Thanks for those tips ptp, I will try and incorporate them. And yes, the spacing got destroyed when I pasted in the quote but it was late and my eyes were half closed so I let it be (sorry). I will try and edit the first post.

I’m not sure if it was obvious with my snippet, but the purposes were twofold -
a) at 7:15 dim the lights if they are on
b) between 7:15 and 10pm if the lights are turned on at any point, set the dim level.
c) if the dim level is manually adjusted without also a change in on-off state, leave the dim level alone to allow for manual adjustments at the switch

It didn’t seem like your snippet will trigger for both of those first two cases or am I misunderstanding?

thanks for the suggestions, they are good points.

EDIT: fixed the original snippet display in the first post

1 Like