Conditions in automation not working as expected

Hello,

I have a simple automation that turn on light when i’m back home, it works like a charm here it is:

- action:
  - data:
      brightness_pct: '70'
      color_name: peachpuff
      entity_id: light.niches
      transition: '15'
    service: light.turn_on
  alias: Back home light
  condition: []
  id: '1517835053425'
  trigger:
  - entity_id: device_tracker.myphone
    from: not_home
    platform: state
    to: home
  - event: sunset
    offset: -00:30:00
    platform: sun

Now i would like to add a condition that check if the lights are on, if so automation should stop, so i added the following code under condition: []

  condition:
  - condition: state
    entity_id: light.niches
    state: 'off'

But now if the automation is triggered when lights are off, nothing happen, if it’s started with light already turned on it switches them off.

I’m sure i’m making some mistake, can anyhone help?

Thanks.

Your condition is checking for the lights to be off so it should carry on and turn the lights on if the lights are off, if on then it should end the automation. I don’t see where it can turn them off as your action is not a toggle it just turns them on. Do you have a 2nd automation running? Also the editor may not work with ‘complex’ automations, so I would lay it out in the automation.yaml file like this…

  id: '1517835053425'
  alias: Back home light
  trigger:
    - platform: state
      entity_id: device_tracker.myphone
      from: not_home
      to: home
    - platform: sun
      event: sunset
      offset: -00:30:00
  condition:
    - condition: state
      entity_id: light.niches
      state: 'off'
  action:
    service: light.turn_on
    entity_id: light.niches
    data:
      brightness_pct: '70'
      color_name: peachpuff
      transition: '15'

Not sure if the spacing is correct for the automation editor, but that’s how I would do it :slight_smile:

I forgot to include an extra action in the same automation that turn off lights after 5 miutes. Thanks for the help, i’m gonna try it :slight_smile: