Complex Chrismaslight Automation

Hi
Could someone please help me with an complex automation (Christmas lights)?

The external sockets should switch on when someone is at home and the Helper ChristmasMode is OFF.
But if the helper is ON and the sun has set and someone is present then the sockets should switch on until mm:hh (helper)

Not Present @ home = SWICH OFF
Present @ home & (Helper ChristmasMode) = OFF, = SWITCH ON
Present @ home & (Helper ChristmasMode) = ON, = SWTICH OFF
Present @ home & (Helper ChristmasMode) = ON, AND SUNSET, = SWITCH ON

What do I have to use as a ls trigger?
How do you prevent that after the set “helpe mm:hh” and or a change to Helper, Zone, Sun doesn’t turn the light on again unintentionally.

alias: Christmaslights
description:
trigger:
  - platform: sun
    event: sunset
    offset: 0
  - platform: zone
    entity_id: device_tracker.iphone13a
    zone: zone.home
    event: enter
  - platform: zone
    entity_id: device_tracker.iphone13b
    zone: zone.home
    event: enter
  - platform: state
    entity_id:
      - input_boolean.ChristmasMode
    to: "on"
    from: "off"
condition:
  - condition: and
    conditions:
      - condition: or
        conditions:
          - condition: zone
            entity_id: device_tracker.iphone13a
            zone: zone.home
          - condition: zone
            entity_id: device_tracker.iphone13b
            zone: zone.home
      - condition: sun
        after: sunset
      - condition: state
        entity_id: input_boolean.ChristmasMode
        state: "on"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
        - switch.0015dbe332b6a9_2
        - switch.0015dbe332b6a9_6
  - wait_for_trigger:
      - platform: time
        at: input_datetime.christmaslights_off_at
  - service: switch.turn_off
    data: {}
    target:
      entity_id:
        - switch.0015dbe332b6a9_2
        - switch.0015dbe332b6a9_6
mode: single

Thanks :slight_smile:

Before I can help you achieve your goal, I need clarification for this requirement:

Currently, your automation’s Zone Trigger only monitors when either device_tracker enters the home zone. If you want to turn off the switch when no one is present, you’ll also need to monitor when the device_tracker leaves the home zone. Did you overlook to include it or did I misunderstand your requirement for when the switch should be turned off?

1 Like

Thanks in advance. If I leave the home zone, the sockets should be off.

@123 sorry for stressing (but my wife is already sharpening the knives), but can you help me?

This community currently has over 150 thousand members. If a day’s delay in responding to you is too slow, the good news is that there are tens of thousands of other users who might have more free time to help you.

1 Like

Experiment with the following automation and see if it meets your needs. The choose has four conditions and each one corresponds to one of your requirements.

alias: Christmaslights
description:
trigger:
  - platform: sun
    event: sunset
    offset: 0
  - platform: zone
    entity_id:
      - device_tracker.iphone13a
      - device_tracker.iphone13b
    zone: zone.home
    event: enter
  - platform: zone
    entity_id:
      - device_tracker.iphone13a
      - device_tracker.iphone13b
    zone: zone.home
    event: leave
  - platform: state
    entity_id: input_boolean.ChristmasMode
    to: "on"
    from: "off"
  - platform: time
    at: input_datetime.christmaslights_off_at
condition: []
action:
  - variables:
      lights:
        - switch.0015dbe332b6a9_2
        - switch.0015dbe332b6a9_6
      is_home: "{{ is_state('device_tracker.iphone13a', 'home') or is_state('device_tracker.iphone13b', 'home') }}"
      is_christmas_mode: "{{ is_state('input_boolean.christmasmode', 'on') }}"
  - choose:
      - conditions:
          - '{{ is_home }}'
          - '{{ is_christmas_mode }}'
          - "{{ is_state('sun.sun', 'below_horizon') }}"
        sequence:
          - service: switch.turn_on
            target:
              entity_id: '{{ lights }}'
      - conditions:
          - '{{ is_home }}'
          - '{{ not is_christmas_mode }}'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: '{{ lights }}'
      - conditions:
          - '{{ is_home }}'
          - '{{ is_christmas_mode }}'
        sequence:
          - service: switch.turn_off
            target:
              entity_id: '{{ lights }}'
      - conditions:
          - '{{ not is_home }}'
        sequence:
          - service: switch.turn_off
            target:
              entity_id: '{{ lights }}'
    default: []

Hi
First. I want to apologize for the stress! I’ve added it now and will see if it works the way it should tonight. I looked at the code, it’s actually quite logical, but I can’t code it myself yet…

How or where should I add a [Time Helper] to the code to switch off the sockets at the set time.
e.g. lights off at 11:00 p.m

THANKS :slight_smile:

Add a Time Trigger.

  - platform: time
    at: input_datetime.your_time_helper

Modify the choose's last conditions statement.

      - conditions:
          - '{{ not is_home or trigger.platform == 'time' }}'
        sequence:
          - service: switch.turn_off
            target:
              entity_id: '{{ lights }}'

light does not switch off at selected time.

In my logic, the first choose overwrites the light and turns it on?! Or am I misunderstanding this?
^*dont wonder I have adjusted the var (I speak German…)

    - choose:
        - conditions:
            - "{{ is_home }}"
            - "{{ is_weihnachtsbeleuchtung }}"
            - "{{ is_state('sun.sun', 'below_horizon') }}"

20:13 was set to turn off… this works, but he choose option 1

i added following code and set off time to 20:45, and it turned off :slight_smile: (but is this the right way?)

    - choose:
        - conditions:
            - "{{ is_home }}"
            - "{{ is_weihnachtsbeleuchtung }}"
            - "{{ is_state('sun.sun', 'below_horizon') }}"
            - "{{ not trigger.platform == 'time' }}"

in addition, the light does not come on at sunset. but if I turn the helper off/on it works. so there should also be a problem with the trigger sun

after a long back and forth the perfect solution

alias: AuĂźensteckdosen (inkl. Weihnachtsmodus)
description: >-
  Bei Abwesenheit werden die AuĂźensteckdosen ausgeschalten, bei Anwesenheit
  eingeschalten. Wenn Weihnachtsmodus Aktiv, dann schalten die Steckdosen nur
  ein wenn jemand Zuhause ist und die Sonne untergegangen ist. Die Steckdosen
  schalten sich zur eingestellten Uhrzeit (Helper) aus.
trigger:
  - platform: sun
    event: sunset
    offset: 0
    id: an
  - platform: numeric_state
    entity_id: zone.home
    above: 0
    id: an
  - platform: state
    entity_id:
      - input_boolean.weihnachtsbeleuchtung
    from: "off"
    to: "on"
    id: an
  - platform: numeric_state
    entity_id: zone.home
    id: aus
    below: 1
  - platform: time
    at: input_datetime.weihnachtsbeleuchtungaus_um
    id: aus
  - platform: state
    entity_id:
      - input_boolean.weihnachtsbeleuchtung
    from: "on"
    to: "off"
    id: aus
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: an
          - condition: time
            before: input_datetime.weihnachtsbeleuchtungaus_um
          - condition: state
            entity_id: input_boolean.weihnachtsbeleuchtung
            state: "on"
          - condition: numeric_state
            entity_id: zone.home
            above: 0
          - condition: sun
            after: sunset
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id:
                - switch.0015dbe991b6a9_2
                - switch.0015dbe991b6a9_6
      - conditions:
          - condition: trigger
            id: aus
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id:
                - switch.0015dbe991b6a9_2
                - switch.0015dbe991b6a9_6
mode: single

You have misunderstood the purpose of the Solution tag. Refer to guideline 21 in the FAQ.

You marked your own post as the Solution yet it’s based on the example I provided you eight days ago. Without that example, you wouldn’t have the basis for fulfilling your original requirements.

In addition, the example you posted appears to have fewer requirements because it no longer takes the device_trackers into account. Anyone reading the requirements you specified in your first post will be led to an alleged solution that doesn’t fulfill all of them.

Anyway, I hope you and your family enjoy the Christmas lighting.

1 Like