Skip to content

Instantly share code, notes, and snippets.

@neumachen
Last active November 16, 2023 23:21
Show Gist options
  • Select an option

  • Save neumachen/fe1e231718ec79895fde3adb1ac3bb2a to your computer and use it in GitHub Desktop.

Select an option

Save neumachen/fe1e231718ec79895fde3adb1ac3bb2a to your computer and use it in GitHub Desktop.

Revisions

  1. neumachen revised this gist Nov 16, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion turn_on_switches_at_sunset.yaml
    Original file line number Diff line number Diff line change
    @@ -47,7 +47,7 @@ condition:
    condition: sun
    before: sunset
    # Add a buffer to be sure
    before_offset: "00:45:00"
    before_offset: "01:00:00"

    # This section will take action on the lights, and turn them on
    action:
  2. neumachen revised this gist Nov 16, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions turn_on_switches_at_sunset.yaml
    Original file line number Diff line number Diff line change
    @@ -45,9 +45,9 @@ trigger:
    condition:
    # Check that it is after sunset
    condition: sun
    after: sunset
    before: sunset
    # Add a buffer to be sure
    after_offset: "00:05:00"
    before_offset: "00:45:00"

    # This section will take action on the lights, and turn them on
    action:
  3. neumachen revised this gist Nov 14, 2023. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions turn_on_switches_at_sunset.yaml
    Original file line number Diff line number Diff line change
    @@ -12,15 +12,15 @@ blueprint:
    target:
    entity:
    domain: switch
    # Create a variable for capturing the desired offset for shifting the trigger
    # Create a variable for capturing the desired offset for shifting the trigger
    elevation_shift:
    name: Elevation Shift
    description: Using an elevation offset (height of sun relative to the horizon) to shift the sunset trigger, either earlier or later. Positive values bring the automation start time forward, whilst negative values delay the start time.
    default: 0.0
    # Use a selector, to set the time shift or offset
    selector:
    number:
    min: -10.0
    min: -10
    max: 10.0
    mode: slider
    step: 1.0
    @@ -40,14 +40,14 @@ trigger:
    attribute: elevation
    # Can be a positive or negative number
    below: !input elevation_shift

    # Add a condition to ensure that this only triggers near sunset, in the evening
    condition:
    # Check that it is after sunset
    condition: sun
    after: sunset
    # Add a buffer to be sure
    after_offset: "00:15:00"
    after_offset: "00:05:00"

    # This section will take action on the lights, and turn them on
    action:
  4. neumachen revised this gist Nov 4, 2023. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions turn_on_switches_at_sunset.yaml
    Original file line number Diff line number Diff line change
    @@ -43,11 +43,11 @@ trigger:

    # Add a condition to ensure that this only triggers near sunset, in the evening
    condition:
    # Check that it is after sunrise
    # Check that it is after sunset
    condition: sun
    after: sunrise
    after: sunset
    # Add a buffer to be sure
    after_offset: "01:00:00"
    after_offset: "00:15:00"

    # This section will take action on the lights, and turn them on
    action:
  5. neumachen revised this gist Nov 4, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion turn_on_switches_at_sunset.yaml
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    blueprint:
    name: turn on switches at sunset
    name: Turn On Switches At Sunset
    description: Turn on the following switches at sunset
    domain: automation
    input:
  6. neumachen created this gist Nov 4, 2023.
    56 changes: 56 additions & 0 deletions turn_on_switches_at_sunset.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    blueprint:
    name: turn on switches at sunset
    description: Turn on the following switches at sunset
    domain: automation
    input:
    # Create a variable for identifying the light to act upon
    target_switch:
    name: Switches
    description: This is the switch (or switches) that will be activated at sunset
    # Use a selector, to pick the light(s)
    selector:
    target:
    entity:
    domain: switch
    # Create a variable for capturing the desired offset for shifting the trigger
    elevation_shift:
    name: Elevation Shift
    description: Using an elevation offset (height of sun relative to the horizon) to shift the sunset trigger, either earlier or later. Positive values bring the automation start time forward, whilst negative values delay the start time.
    default: 0.0
    # Use a selector, to set the time shift or offset
    selector:
    number:
    min: -10.0
    max: 10.0
    mode: slider
    step: 1.0

    # Prevent the automation from running concurrently
    mode: single

    # Define the variables used in the action section
    variables:
    target_switch: !input target_switch

    # Define the trigger for the automation
    trigger:
    # Using the state of the sun to act as the trigger
    platform: numeric_state
    entity_id: sun.sun
    attribute: elevation
    # Can be a positive or negative number
    below: !input elevation_shift

    # Add a condition to ensure that this only triggers near sunset, in the evening
    condition:
    # Check that it is after sunrise
    condition: sun
    after: sunrise
    # Add a buffer to be sure
    after_offset: "01:00:00"

    # This section will take action on the lights, and turn them on
    action:
    # A very simple structure of turning on the selected light(s)
    - service: switch.turn_on
    target: !input target_switch