Dont turn on lights during the day

Hy I try to automate my light settings for my garden. I need to “deactivate” (= turn light off) my switch during the day and when the sun goes down “activate” (= turn light on) it again. But it doesnt work :-/

Does somebody has an idea?

Can we see?

May have to share YAML for your automation to get someone to chime in with help.

You don’t deactivate the switch, but you add a condition to the automation that turns on the light (f.e. sun below horizon), so the automation will not trigger, unless the condition is met :wink:

description: ""
mode: single
trigger:
  - platform: device
    domain: mqtt
    device_id: c03caa8745812b437c29507b14fd5378
    type: action
    subtype: "on"
    discovery_id: 0x04cd15fffe470d4b action_on
condition:
  - condition: sun
    before: sunset
    after: sunrise
action:
  - service: light.turn_on
    data: {}
    target:
      entity_id:
        - switch.bathroom_secondary_light

iow, only activate light during night :thinking:

condition:
  - condition: state
    entity_id: sun.sun
    state: 'below_horizon'

That then will only run when the sun has set.

1 Like

Keep in mind that a cloudy rainy day will make it darker and the need for light might be before the suns position has crossed a line

I have a well working automation for my garden lights.
“Lights on when dark outside (from BNAS till ENMS (-6°))”
Please show your automation, maybe we can help try to fix things. :wink:

I try a lot and this was my last try:

trigger:
  - platform: state
    entity_id:
      - switch.garten_wz_licht
    to: "on"
condition:
  - condition: sun
    after: sunrise
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.garten_wz_licht

After sunrise is from sunrise to midnight.

Aaah ok so I need “after sunset” or also other changes?

In my opinion, when the switch goes to “on” and the its after sunset so the automation will switch the off again right?

condition:
  - condition: state
    entity_id: sun.sun
    state: 'above_horizon'

is all you need