ashley_s_light_fader:
  alias: Ashley’s Light Fader
  description: 'Fades a lamp over time. If you have any questions or comments about
    this script, feel free to tweet Ashley Bischoff at @FriendlyAshley. Released under
    the Apache 2.0 license. (v2.0)

    '
  fields:
    light:
      name: "\U0001F4A1 Light"
      description: entity_id of the lamp.
      selector:
        entity:
          domain: light
      example: light.kitchen
      required: true
    lampBrightnessScale:
      name: The lamp’s internal brightness scale
      description: 'Most lamps seem to internally use a 0 to 255 brightness scale,
        but some lamps internally use a 0% to 100% brightness scale. Either of these
        settings will still fade the lamp, but if you happen to match this setting
        to the lamp’s internal brightness scale, the resulting fade may be smoother.
        (If you’re not sure, you can just leave this as is.)

        '
      advanced: true
      required: true
      selector:
        select:
          options:
          - label: 0% to 100%
            value: zeroToOneHundred
          - label: 0 to 255
            value: zeroToTwoFiftyFive
      default: zeroToTwoFiftyFive
    transitionTime:
      name: ⏱ Fade time
      description: Fade duration.
      selector:
        duration:
      required: true
    easingTypeInput:
      name: "\U0001F4C9 Easing type"
      description: The easing function that you’d like the fade to use. As a starting
        point—you can’t go wrong with any of the “Ease-In-Out X” easings as those
        will always look pretty good whenever you’re fading between two nonzero brightness
        values. As well, the “Ease-Out X” easings often tend to look good if you might
        be fading up very quickly from zero to another brightness, and the “Ease-In
        X” easings are mostly only included for completeness as those tend to only
        look good if you might be fading down to zero very quickly. (See also https://easings.net
        for visual demos of each of these easing types.)
      selector:
        select:
          mode: list
          options:
          - label: Try to automatically select the easing type
            value: auto
          - label: Ease-In-Out Sine [a good all-rounder]
            value: easeInOutSine
          - label: Ease-In-Out Quad
            value: easeInOutQuad
          - label: Ease-In-Out Cubic
            value: easeInOutCubic
          - label: Ease-In-Out Quart
            value: easeInOutQuart
          - label: Ease-Out Sine
            value: easeOutSine
          - label: Ease-Out Quad
            value: easeOutCubic
          - label: Ease-Out Cubic
            value: easeOutCubic
          - label: Ease-Out Quart
            value: easeOutQuart
          - label: Ease-In Sine
            value: easeInSine
          - label: Ease-In Quad
            value: easeInCubic
          - label: Ease-In Cubic
            value: easeInCubic
          - label: Ease-In Quart
            value: easeInQuart
          - label: Linear [somewhat unnatural to the human eye; not recommended]
            value: linear
      default: auto
      required: true
    endBrightnessPercent:
      name: End brightness level
      description: Percentage from 0 to 100 representing the final brightness level.
      selector:
        number:
          min: 0
          max: 100
          step: 1
          mode: slider
          unit_of_measurement: '%'
      default: 50
      example: '50'
      required: true
    endBrightnessEntity:
      name: (optional) Use an entity instead for the end-brightness value?
      description: You can optionally have the script ignore the end-brightness value
        above and instead use the numeric value of anonther entity that you select
        here, such as an input-number helper, an input-select helper, an input-text
        helper, or a numeric sensor.
      selector:
        entity:
          domain:
          - input_number
          - input_select
          - input_text
          - sensor
      example: input_number.dining_room_entertaining_level
      required: false
      advanced: true
    endBrightnessEntityScale:
      name: The end-brightness entity’s brightness scale (if used)
      description: If you enable the “use an entity for the end-brightness value instead”
        option, select here whether your chosen entity represents brightness with
        a 0% to 100% scale or a 0 to 255 scale. (Note—in either case, this script
        will expect that entity to solely have an integer value without any nonnumeric
        characters such as “%”.)
      advanced: true
      selector:
        select:
          options:
          - label: 0% to 100%
            value: zeroToOneHundred
          - label: 0 to 255
            value: zeroToTwoFiftyFive
      default: zeroToOneHundred
      required: true
    endColorTemperatureKelvin:
      name: "\U0001F3A8 (optional) End color temperature (in Kelvin)"
      description: Color temperature from 2000 K to 6500 K representing the final
        color temperature.
      selector:
        number:
          min: 2000
          max: 6500
          step: 50
          mode: slider
          unit_of_measurement: °K
      example: '2700'
      required: false
    endColorTemperatureKelvinEntity:
      name: (optional) Use an entity instead for the ending Kelvin value?
      description: You can optionally have the script ignore the end-color-temperature
        value above and instead use the numeric value of anonther entity that you
        select here, such as an input-number helper, an input-select helper, an input-text
        helper, or a numeric sensor.
      selector:
        entity:
          domain:
          - input_number
          - input_select
          - input_text
          - sensor
      example: input_number.dining_room_color_temperature
      required: false
      advanced: true
    autoCancelThreshold:
      name: "\U0001F6AB (optional) Brightness-change threshold that auto-cancels the
        fade"
      description: You can optionally have the script automatically cancel its fade
        if the lamp’s brightness were to be manually changed by a certain amount.
        For example, let’s suppose that you were to set this value to 5% and then
        you were to run this script. If there comes a point within the fade where
        this script is expecting the lamp to be at, say, 22% brightness—but you’ve
        just manually set that lamp to 30% brightness—this script will automatically
        cancel its fade since that 8% difference is >= 5%. Note—if you use this, Ashley
        doesn’t recommend setting this to anything less than about 3; that’s just
        because it can be normal for there to be an occasional difference of 1 or
        2 since not all lamps instantly reflect newly assigned brightness values due
        to processing lag and other factors. In Ashley’s home, she personally uses
        a value of about 5 for this.
      selector:
        number:
          min: 2
          max: 100
          step: 1
          mode: slider
          unit_of_measurement: '%'
      default: 10
      example: '10'
      required: false
    shouldStopIfTheLampIsTurnedOffDuringTheFade:
      name: ⤵️ Cancel the fade if the lamp is turned off during the fade?
      description: By default, the script will automatically disengage if the lamp
        is turned off during the fade. But if you’d like to, you can also disable
        that behavior with this switch. (And don’t worry—this feature is smart enough
        to not automatically cancel the fade at points when the lamp’s intended brightness
        might be zero, such as if the script were to be fading down to zero or fading
        up from zero.)
      selector:
        boolean:
      advanced: false
      required: true
      default: true
    stopEntity:
      name: "\U0001F6D1 (optional) Stop if a certain entity is turned on during the
        fade?"
      description: 'You can optionally have the script keep an eye on an input boolean
        or a binary sensor or a light. And if that entity is then turned on during
        the fade, the script will automatically stop. So for example, if you create
        a “Stop Everything” input boolean, and if you set that entity here, you can
        stop your fade at any time by turning on that “Stop Everything” entity. '
      selector:
        entity:
          domain:
          - input_boolean
          - binary_sensor
          - light
          - switch
      example: input_boolean.stop_everything
      required: false
      advanced: true
    shouldResetTheStopEntityToOffAtStart:
      name: (optional) Reset that “stop” entity to off just before starting the fade?
      description: If you make use of the stop entity (above), you can also optionally
        have the script automatically reset that entity to “off” at the start of the
        fade. (By default, the script won’t change the value of the stop entity.)
      selector:
        boolean:
      advanced: true
      required: true
      default: false
    shouldInvertTheValueOfTheStopEntity:
      name: (optional) Stop only if the “stop” entity is instead turned OFF?
      description: If you make use of the stop entity (above), you can optionally
        have the script automatically stop only if that entity is turned OFF during
        the fade.
      selector:
        boolean:
      advanced: true
      required: true
      default: false
    minimumStepDelayInMilliseconds:
      name: Minimum delay per step
      description: The minimum delay between sending each brightness command. Some
        lamps only accept commands every X milliseconds—so while you can probably
        leave this as is, if by chance your lamp were to behave strangely, you might
        try bumping up this number by another ten or twenty milliseconds.
      advanced: true
      selector:
        number:
          min: 50
          max: 1000
          step: 10
          mode: slider
          unit_of_measurement: ms
      default: 100
      example: '100'
    shouldTryToUseNativeLampTransitionsToo:
      name: "\U0001F9EA (experimental) If available, use the lamp's native transitions
        too?"
      description: If this is enabled and if the lamp natively supports transitions,
        the script will make use of the lamp’s native transition effect when moving
        between brightness steps or color steps if those steps are very gradually
        spaced. When enabled, this has the possibility of offering even smoother fades.
        And if the lamp doesn’t happen to support the transition effect in the first
        place, this feature will automatically disengage. (And while Ashley feels
        comfortable using this feature in her own house, this feature isn’t as thoroughly
        tested as the script’s other features, so this feature is considered experimental
        for now.)
      selector:
        boolean:
      advanced: true
      required: true
      default: false
    isDebugMode:
      name: "\U0001F41B Enable debugging mode?"
      description: If this is enabled, the script will output status messages to your
        Home Assistant log along the way. Unless something were to be acting weirdly,
        you can leave this off.
      selector:
        boolean:
      advanced: true
      required: true
      default: false
  sequence:
  - variables:
      lightFriendlyName: '{{ state_attr(light, ''friendly_name'') }}'
      startTimestamp: '{{ as_timestamp(now()) }}'
      fadeTimeInSeconds: '{{ ((transitionTime.hours | int) * 60 * 60) + ((transitionTime.minutes
        | int) * 60) + (transitionTime.seconds | int) }}

        '
      endTimestamp: '{{ startTimestamp + fadeTimeInSeconds }}'
      fadeTimeInMilliseconds: '{{ fadeTimeInSeconds * 1000 }}'
      shouldIgnoreTheEndBrightnessValueAndUseAnEntityForTheEndBrightnessInstead: "{%
        if (endBrightnessEntity is defined) and (has_value(endBrightnessEntity)) %}\n
        \ {{ true }}\n{% else %}\n  {{ false }}\n{% endif %}\n"
      shouldIgnoreTheEndColorTemperatureValueAndUseAnEntityForTheEndColorTemperatureInstead: "{%
        if (endColorTemperatureKelvinEntity is defined) and (has_value(endColorTemperatureKelvinEntity))
        %}\n  {{ true }}\n{% else %}\n  {{ false }}\n{% endif %}\n"
      isStopEntityEnabled: "{% if (stopEntity is defined) and (has_value(stopEntity))
        %}\n  {{ true }}\n{% else %}\n  {{ false }}\n{% endif %}\n"
      isStopEntityToggleable: "{% if isStopEntityEnabled %}\n  {% set stopEntityDomain
        = states[stopEntity].domain %}\n  {% if stopEntityDomain == \"binary_sensor\"
        %}\n    {{ false }}\n  {% else %}\n    {## branch for stopEntityDomain being
        an input_boolean or a light or a switch ##} \n    {{ true }}\n  {% endif %}\n{%
        else %}\n  {{ false }}\n{% endif %}\n"
      stopEntityFriendlyName: "{% if isStopEntityEnabled %}\n  {{ state_attr(stopEntity,
        'friendly_name') }}\n{% else %}\n  {{ \"\" }}\n{% endif %}\n"
      minColorTemperatureKelvin: "{## init ##} {% set minColorTemperature = -1 %}\n{%
        set minColorTemperatureValue = state_attr(light, 'min_color_temp_kelvin')
        %} {% if minColorTemperatureValue %}\n  {% if is_number(minColorTemperatureValue)
        %}\n    {% set minColorTemperature = minColorTemperatureValue | int %}\n  {%
        endif %}\n{% endif %} {{ minColorTemperature }}\n"
      maxColorTemperatureKelvin: "{## init ##} {% set maxColorTemperature = -1 %}\n{%
        set maxColorTemperatureValue = state_attr(light, 'max_color_temp_kelvin')
        %} {% if maxColorTemperatureValue %}\n  {% if is_number(maxColorTemperatureValue)
        %}\n    {% set maxColorTemperature = maxColorTemperatureValue | int %}\n  {%
        endif %}\n{% endif %} {{ maxColorTemperature }}\n"
      doesLampSupportColorTemperatureKelvin: "{% if ((minColorTemperatureKelvin |
        int) > 0) and\n((maxColorTemperatureKelvin | int)) > 0 %}\n  {{ true }}\n{%
        else %}\n  {{ false }}\n{% endif %}\n"
      doesLampSupportTransitions: "{% set supportedFeatures = state_attr(light, 'supported_features')
        | int %}\n{## Bitfield of features supported by the light entity ##} {## SUPPORT_BRIGHTNESS
        = 1 ##} {## SUPPORT_COLOR_TEMP = 2 ##} {## SUPPORT_EFFECT = 4 ##} {## SUPPORT_FLASH
        = 8 ##} {## SUPPORT_COLOR = 16 ##} {## SUPPORT_TRANSITION = 32 ##} {## SUPPORT_WHITE_VALUE
        = 128 ##}\n{## via: https://github.com/home-assistant/core/blob/787faaa508cf83ca4f850ee7000ad17eade915aa/homeassistant/components/light/__init__.py#L39
        ##}\n{% if supportedFeatures >= 128 %}\n  {% set supportedFeatures = supportedFeatures
        - 128 %}\n{% endif %}\n{% if supportedFeatures >= 32 %}\n  {{ true }}\n{%
        else %}\n  {{ false }}\n{% endif %}\n\n"
      endColorTemperature: "{% if\nshouldIgnoreTheEndColorTemperatureValueAndUseAnEntityForTheEndColorTemperatureInstead\n%}\n
        \ {% set entityColorTemperatureValue = states(endColorTemperatureKelvinEntity)
        | round (0) %}\n  \n  {% set endColorTemperatureKelvinValue = entityColorTemperatureValue
        | int %}\n\n  {% if endColorTemperatureKelvinValue > (maxColorTemperatureKelvin
        | int\n  ) %}\n    {% set endColorTemperatureKelvinValue = maxColorTemperatureKelvin
        |int %}\n  {% endif %}\n\n  {% if endColorTemperatureKelvinValue < (minColorTemperatureKelvin
        | int\n  )%}\n    {% set endColorTemperatureKelvinValue = minColorTemperatureKelvin
        | int %}\n  {% endif %}\n  \n{% else %}\n  {## branch for shouldIgnoreTheEndColorTemperatureValueAndUseAnEntityForTheEndColorTemperatureInstead
        being off ##}\n  \n  {% if (endColorTemperatureKelvin is defined) and endColorTemperatureKelvin
        %}\n    {% set endColorTemperatureKelvinValue = endColorTemperatureKelvin
        | round(0) %}\n  {% else %}\n    {% set endColorTemperatureKelvinValue = 0
        %}\n  {% endif %}\n  \n{% endif %}\n\n{{ endColorTemperatureKelvinValue }}\n"
      isColorFadeRequested: "{% if (endColorTemperature |int) > 0 %}\n  {{ true }}\n{%
        else %}\n  {{ false }}\n{% endif %}\n"
      endBrightness: "{% if shouldIgnoreTheEndBrightnessValueAndUseAnEntityForTheEndBrightnessInstead
        %}\n  {% set entityBrightnessValue = states(endBrightnessEntity) | round (0)
        %}\n  {% if (endBrightnessEntityScale == lampBrightnessScale) %}\n    {% set
        endBrightness = entityBrightnessValue %}\n  {% elif (lampBrightnessScale ==
        \"zeroToTwoFiftyFive\") and (endBrightnessEntityScale == \"zeroToOneHundred\")
        %}\n    {% set endBrightness = (entityBrightnessValue * 2.55) | round(0) %}\n
        \ {% elif (lampBrightnessScale == \"zeroToOneHundred\") and (endBrightnessEntityScale
        == \"zeroToTwoFiftyFive\") %}\n    {% set endBrightness = (entityBrightnessValue
        / 2.55) | round(0) %}\n  {% endif %}\n{% else %}\n  {## branch for using the
        brightness selector's value rather than an entity's brightness value ##}\n
        \ {% if lampBrightnessScale == \"zeroToOneHundred\" %}\n  \t{% set endBrightness
        = endBrightnessPercent %}\n  {% else %}\n  \n    {## lampBrightnessScale ==
        \"zeroToTwoFiftyFive\" ##}\n    {% if endBrightnessPercent == 1 %}\n      {##
        special case to force the endBrightness to 1/255 if the user enters \"1%\"
        by inferring that the user is looking to set the lamp to its lowest possible
        brightness ##}\n    \t{% set endBrightness = 1 %}\n    {% else %}\n      {%
        set endBrightness = (endBrightnessPercent * 2.55) | round(0) %}\n    {% endif
        %}\n  \n  {% endif %}\n{% endif %}\n\n{{ endBrightness }}\n"
      startBrightness: "{% set rawLightLevel = state_attr(light, 'brightness') %}\n\n{##
        If a light is off, its brightness will return \"None\"? So first check if
        there's a valid brightness before setting the value ##}\n{% if rawLightLevel
        %}\n\t{% set currentLightLevel = rawLightLevel | int %}\n{% else %}\n\t{%
        set currentLightLevel = 0 %}\n{% endif %}\n\n{% if lampBrightnessScale ==
        \"zeroToOneHundred\" %}\n  {% set currentLightLevel = (currentLightLevel /
        2.55) | round(0) %}\n{% endif %}\n\n{## This next part, which nudges the starting
        level from 0 to 1, is necessary in cases \n  where there’s a color fade requested
        but the starting brightness level is 0. \n  And that’s because when a light
        is at 0, Home Assistant doesn’t know that light's Kelvin color.            So
        the light first needs to be nudged toward 1 just so that this script can see
        what it’s\n  starting Kelvin color is. ##}\n  \n{% if (currentLightLevel ==
        0) and (endBrightness > currentLightLevel) and isColorFadeRequested %}\n  {%
        set currentLightLevel = 1 %}\n{% endif %}\n\n{{ currentLightLevel }}\n"
      brightnessSpan: '{{ endBrightness - startBrightness }}'
      absoluteBrightnessSpan: '{{ brightnessSpan | abs }}'
      shouldAutoCancelTheFadeIfTheLampBrightnessIsManuallyChanged: "{% if (autoCancelThreshold
        is defined) and (is_number(autoCancelThreshold)) %}\n  {{ true }}\n{% else
        %}\n  {{ false }}\n{% endif %}\n"
      normalizedAutoCancelThreshold: "{% if not shouldAutoCancelTheFadeIfTheLampBrightnessIsManuallyChanged
        %}\n  {## exit early if shouldAutoCancelTheFadeIfTheLampBrightnessIsManuallyChanged
        isn’t even enabled ##}\n  {{ 255 }}\n{% elif (lampBrightnessScale == \"zeroToTwoFiftyFive\")
        %}\n  {{ (autoCancelThreshold * 2.55) | round (0) }}\n{% else %}\n  {{ autoCancelThreshold
        }}\n{% endif %}\n"
      expectedBrightness: '{{ startBrightness }}'
  - if:
    - condition: template
      value_template: '{{ isStopEntityEnabled and isStopEntityToggleable and shouldResetTheStopEntityToOffAtStart
        }}

        '
    then:
    - data: {}
      target:
        entity_id: '{{ stopEntity }}'
      action: homeassistant.turn_off
  - if:
    - condition: template
      value_template: "{## init ##} {% set shouldStop = false %} {% if isStopEntityEnabled
        %}\n  {% if (shouldInvertTheValueOfTheStopEntity is defined) and shouldInvertTheValueOfTheStopEntity
        %}\n    {% if not bool(states(stopEntity), false) %}\n      {% set shouldStop
        = true %}\n    {% endif %}\n  {% else %}\n    {% if bool(states(stopEntity),
        false) %}\n      {% set shouldStop = true %}\n    {% endif %}\n  {% endif
        %}\n{% endif %} {{ shouldStop }}\n"
    then:
    - if:
      - condition: template
        value_template: '{{ (shouldInvertTheValueOfTheStopEntity is defined) and shouldInvertTheValueOfTheStopEntity
          }}

          '
      then:
      - variables:
          stopMessage: '{% set stopMessage = "Stopped Ashley’s Light Fader because
            " + (stopEntityFriendlyName | string) + " is off." %} {{ stopMessage }}

            '
      - if:
        - condition: template
          value_template: '{{ isDebugMode }}

            '
        then:
        - data_template:
            message: '{{ stopMessage }}

              '
            level: warning
          action: system_log.write
      - stop: '{{ stopMessage }}

          '
      else:
      - variables:
          stopMessage: '{% set stopMessage = "Stopped Ashley’s Light Fader because
            " + (stopEntityFriendlyName | string) + " is on." %} {{ stopMessage }}

            '
      - if:
        - condition: template
          value_template: '{{ isDebugMode }}

            '
        then:
        - data_template:
            message: '{{ stopMessage }}

              '
            level: warning
          action: system_log.write
      - stop: '{{ stopMessage }}

          '
  - variables:
      timestampBeforeServiceCall: '{{ as_timestamp(now()) }}'
  - if:
    - condition: template
      value_template: '{{ (lampBrightnessScale == "zeroToTwoFiftyFive") }}

        '
    then:
    - target:
        entity_id: '{{ light }}'
      data:
        brightness: '{{ expectedBrightness }}'
      action: light.turn_on
    else:
    - target:
        entity_id: '{{ light }}'
      data:
        brightness_pct: '{{ expectedBrightness }}'
      action: light.turn_on
  - variables:
      processingDelayInMilliseconds: '{{ (as_timestamp(now()) -  timestampBeforeServiceCall)
        * 1000 }}'
      easingType: "{% if \"auto\" in easingTypeInput %}\n  {% if (startBrightness
        == 0) and (fadeTimeInSeconds <= 20) %}\n    {{ \"easeOutCubic\" }}\n  {% elif
        (startBrightness == 0) and (fadeTimeInSeconds <= 55) %}\n    {{ \"easeOutQuad\"
        }}\n  {% elif (endBrightness == 0) and (fadeTimeInSeconds <= 20) %}\n    {{
        \"easeInCubic\" }}\n  {% elif (endBrightness == 0) and (fadeTimeInSeconds
        <= 55) %}\n    {{ \"easeInQuad\" }}\n  {% else %}\n    {{ \"easeInOutSine\"
        }}\n  {% endif %}\n{% else %}\n  {{ easingTypeInput }}\n{% endif %}\n"
      isLampCurrentColorDefinedUsingKelvin: "{% set rawColorTemperature = state_attr(light,
        'color_temp_kelvin') %}\n\n{## If a light is off or if its color temperature
        is defined using a non-Kelvin color system, \n  its color temperature will
        return \"None\"? So first check if there's a valid color temperature ##}\n\n{%
        if rawColorTemperature %}\n\t{{ true }}\n{% else %}\n\t{{ false }}\n{% endif
        %}\n\n"
      startColorTemperature: "{## init ##} {% set currentColorTemperature = -1 %}\n{%
        set rawColorTemperature = state_attr(light, 'color_temp_kelvin') %}\n{## If
        a light is off or if its color temperature is defined using a non-Kelvin color
        system, \n  its color temperature will return \"None\"? So first check if
        there's a valid color temperature ##}\n\n{% if rawColorTemperature %}\n  {%
        if is_number(rawColorTemperature) %}\n    {% set currentColorTemperature =
        rawColorTemperature | int %}\n  {% endif %}\n{% endif %}\n{{ currentColorTemperature
        }}\n\n"
      colorTemperatureSpan: "{% if doesLampSupportColorTemperatureKelvin %}\n  {{
        (endColorTemperature | int) - (startColorTemperature | int) }}\n{% else %}\n
        \ {{ 0 }}\n{% endif %}\n"
      absoluteColorTemperatureSpan: '{{ colorTemperatureSpan | int | abs }}'
      isBrightnessFadeEnabled: "{% if (absoluteBrightnessSpan | int) > 0 %}\n  {{
        true }}\n{% else %}\n  {{ false }}\n{% endif %}\n"
      isColorFadeEnabled: "{% if isColorFadeRequested and doesLampSupportColorTemperatureKelvin
        and ((absoluteColorTemperatureSpan | int) > 0) %}\n  {{ true }}\n{% else %}\n
        \ {{ false }}\n{% endif %}\n"
      remainingTimeInMilliseconds: '{% set nowTimestamp = as_timestamp(now()) %}

        {{ (endTimestamp - nowTimestamp) * 1000 }}

        '
      delayInMilliseconds: "{## init ##}\n{% set frameMultiplicationFactor = 1 %}\n{%
        if \"Circ\" in easingType %}\n  {## Four as many frames for Circ-type easings
        ##}\n  {## set idealDelay = (idealDelay / 4) | round(0) ##}\n  {% set frameMultiplicationFactor
        = 3 %}\n{% elif (\"Cubic\" in easingType) or (\"Quart\" in easingType) %}\n
        \ {## Three as many frames for Cubic-type or Quart-type easings ##}\n  {##
        set idealDelay = (idealDelay / 3) | round(0) ##}\n  {% set frameMultiplicationFactor
        = 2 %}\n{% elif \"ease\" in easingType %}\n  {## Twice as many frames for
        other easing types ##}\n  {## set idealDelay = (idealDelay / 1.5) | round(0)
        ##}\n  {% set frameMultiplicationFactor = 1.2 %}\n{% endif %}\n{% if isBrightnessFadeEnabled
        %}\n  {% set brightnessFramesCount = (frameMultiplicationFactor * absoluteBrightnessSpan)
        | round(0) %}\n  {% set totalExpectedRemainingBrightnessFadeProcessingDelay
        = processingDelayInMilliseconds * brightnessFramesCount %}\n  {% set idealBrightnessFadeDelay
        = ((remainingTimeInMilliseconds - totalExpectedRemainingBrightnessFadeProcessingDelay)
        / brightnessFramesCount) | round(0) %}\n{% else %}\n  {% set idealBrightnessFadeDelay
        = 0 %}\n{% endif %}\n{% if isColorFadeEnabled %}\n  {## The division by 25
        below is working from the idea that you’d want the color fade \n    to progress
        at least every 25°K, such as 2,000 K, 2,025 K, 2,050 K, and so on ##}\n  \n
        \ {% set colorFramesCount = (frameMultiplicationFactor * (absoluteColorTemperatureSpan
        / 25)) | round(0) %}\n  {% set totalExpectedRemainingColorFadeProcessingDelay
        = (processingDelayInMilliseconds * colorFramesCount) | round(0) %}\n  {% set
        idealColorFadeDelay = ((remainingTimeInMilliseconds - totalExpectedRemainingColorFadeProcessingDelay)
        / colorFramesCount ) | round(0) %}\n{% else %}\n  {% set idealColorFadeDelay
        = 0 %}\n{% endif %}\n{## init ##} {% set idealDelay = 0 %}\n{## if both brightness-fade
        is enabled and color-fade is enabled, pick the one with the lowest ideal delay
        ##}\n{% if isBrightnessFadeEnabled and isColorFadeEnabled %}\n  {% if idealBrightnessFadeDelay
        < idealColorFadeDelay %}\n    {% set idealDelay = idealBrightnessFadeDelay
        %} \n  {% else %}\n    {% set idealDelay = idealColorFadeDelay %}\n  {% endif
        %}\n{% elif isBrightnessFadeEnabled %}\n  {% set idealDelay = idealBrightnessFadeDelay
        %}\n{% elif isColorFadeEnabled %}\n  {% set idealDelay = idealColorFadeDelay
        %}\n{% endif %}\n{## Make sure that the delay isn’t below the minimumStepDelayInMilliseconds
        ##} {% if idealDelay < minimumStepDelayInMilliseconds %}\n  {{ minimumStepDelayInMilliseconds
        }}\n{% else %}\n  {{ idealDelay }}\n{% endif %}\n"
      delayInSeconds: '{{ (delayInMilliseconds | int) / 1000 }}

        '
      transitionTimeParameterInSeconds: "{% set transitionTimeParameterInSeconds =
        ((delayInSeconds | float) * 0.9) | round(3) %}\n{## set a ceiling on the transition
        time ##}\n{% if transitionTimeParameterInSeconds > 10 %}\n  {% set transitionTimeParameterInSeconds
        = 10 %}\n{% endif %}\n{{ transitionTimeParameterInSeconds }}\n"
      minimumDelayInSecondsBeforeUsingNativeLampNativeTransitionsToo: '{{ 1 }}

        '
      shouldUseNativeLampTransitionsToo: "{% if \n  (\n    (shouldTryToUseNativeLampTransitionsToo
        is defined) \n    and shouldTryToUseNativeLampTransitionsToo \n    and doesLampSupportTransitions\n
        \   and ((transitionTimeParameterInSeconds | float(0) ) >=    \n    minimumDelayInSecondsBeforeUsingNativeLampNativeTransitionsToo
        | float(0) )\n  )\n%}\n  {{ true }}\n{% else %}\n  {{ false }}\n{% endif %}\n"
  - if:
    - condition: template
      value_template: "{{ ((absoluteBrightnessSpan | int) == 0) and not isColorFadeEnabled
        }}        \n"
    then:
    - variables:
        stopMessage: '{% set stopMessage = "Stopped Ashley’s Light Fader because "
          + (lightFriendlyName | string) + "’s starting brightness is the same as
          its ending brightness." %} {{ stopMessage }}

          '
    - if:
      - condition: template
        value_template: '{{ isDebugMode }}

          '
      then:
      - data_template:
          message: '{{ stopMessage }}

            '
          level: warning
        action: system_log.write
    - stop: '{{ stopMessage }}

        '
  - if:
    - condition: template
      value_template: "{{ ((absoluteBrightnessSpan | int) == 0) and ((absoluteColorTemperatureSpan
        | int) == 0) and isColorFadeEnabled }}        \n"
    then:
    - variables:
        stopMessage: '{% set stopMessage = "Stopped Ashley’s Light Fader because "
          + (lightFriendlyName | string) + "’s starting brightness is the same as
          its ending brightness and its starting color temperature is the same as
          its ending color temperature." %} {{ stopMessage }}

          '
    - if:
      - condition: template
        value_template: '{{ isDebugMode }}

          '
      then:
      - data_template:
          message: '{{ stopMessage }}

            '
          level: warning
        action: system_log.write
    - stop: '{{ stopMessage }}

        '
  - if:
    - condition: template
      value_template: "{{ isColorFadeRequested and not doesLampSupportColorTemperatureKelvin
        }}        \n"
    then:
    - variables:
        stopMessage: '{% set stopMessage = "Stopped Ashley’s Light Fader because a
          color fade was requested for " + (lightFriendlyName | string) + ", but it
          doesn’t seem to support Kelvin color temperatures. (You can look into this
          by going into Developer Tools and checking that " + (lightFriendlyName |
          string) + " has the defined attributes for “min_color_temp_kelvin” and “max_color_temp_kelvin”.)"
          %} {{ stopMessage }}

          '
    - if:
      - condition: template
        value_template: '{{ isDebugMode }}

          '
      then:
      - data_template:
          message: '{{ stopMessage }}

            '
          level: warning
        action: system_log.write
    - stop: '{{ stopMessage }}

        '
  - if:
    - condition: template
      value_template: "{{ isColorFadeRequested and not isLampCurrentColorDefinedUsingKelvin
        }}        \n"
    then:
    - variables:
        stopMessage: '{% set stopMessage = "Stopped Ashley’s Light Fader because a
          color fade was requested for " + (lightFriendlyName | string) + ", but its
          current color temperature doesn’t seem to be defined using Kelvin units.
          (You can look into this by going into Developer Tools and checking that
          " + (lightFriendlyName | string) + " has a defined “color_temp_kelvin” attribute.)"
          %} {{ stopMessage }}

          '
    - if:
      - condition: template
        value_template: '{{ isDebugMode }}

          '
      then:
      - data_template:
          message: '{{ stopMessage }}

            '
          level: warning
        action: system_log.write
    - stop: '{{ stopMessage }}

        '
  - if:
    - condition: template
      value_template: '{{ isDebugMode }}

        '
    then:
    - if:
      - condition: template
        value_template: '{{ isColorFadeEnabled }}

          '
      then:
      - data_template:
          message: '{{ easingType }} easing type with {{ delayInMilliseconds | int
            }} ms delay. remainingTimeInMilliseconds = {{ remainingTimeInMilliseconds
            | round(0) }}, absoluteColorTemperatureSpan = {{ absoluteColorTemperatureSpan
            }}, and absoluteBrightnessSpan = {{ absoluteBrightnessSpan }}

            '
          level: warning
        action: system_log.write
      - data_template:
          message: 'startBrightness = {{ startBrightness }}, endBrightness = {{ endBrightness
            }}, startColorTemperature = {{ startColorTemperature }}, endColorTemperature
            = {{ endColorTemperature }}, and  processingDelayInMilliseconds = {{ processingDelayInMilliseconds
            | int }}

            '
          level: warning
        action: system_log.write
      else:
      - data_template:
          message: '{{ easingType }} easing type with {{ delayInMilliseconds | int
            }} ms delay. remainingTimeInMilliseconds = {{ remainingTimeInMilliseconds
            | round(0) }}, and absoluteBrightnessSpan = {{ absoluteBrightnessSpan
            }}

            '
          level: warning
        action: system_log.write
      - data_template:
          message: 'startBrightness = {{ startBrightness }}, endBrightness = {{ endBrightness
            }}, and processingDelayInMilliseconds = {{ processingDelayInMilliseconds
            | int }}

            '
          level: warning
        action: system_log.write
  - repeat:
      sequence:
      - variables:
          percentageOfTimeCompleted: "{% set nowTimestamp = as_timestamp(now()) %}\n{%
            set percentageOfTimeCompleted = ((nowTimestamp - startTimestamp) / fadeTimeInSeconds)
            %}\n{% if (percentageOfTimeCompleted < 0) %}\n  {% set percentageOfTimeCompleted
            = 0 %}\n{% elif (percentageOfTimeCompleted > 1) %}\n  {% set percentageOfTimeCompleted
            = 1 %}\n{% endif %}\n{{ percentageOfTimeCompleted }}\n"
          easingAdjustedPercentageCompleted: "{% set percentageOfTimeCompleted = percentageOfTimeCompleted
            | float(0) %} {% if easingType == \"easeInSine\" %}\n  {## https://easings.net/#easeInSine
            ##}\n  {{  1 - cos((percentageOfTimeCompleted * pi) / 2) }}\n\n{% elif
            easingType == \"easeInQuad\" %}\n  {## https://easings.net/#easeInQuad
            ##}\n  {{ percentageOfTimeCompleted * percentageOfTimeCompleted }} \n\n{%
            elif easingType == \"easeInCubic\" %}\n  {## https://easings.net/#easeInCubic
            ##}\n  {{ percentageOfTimeCompleted * percentageOfTimeCompleted * percentageOfTimeCompleted
            }}\n\n{% elif easingType == \"easeInQuart\" %}\n  {## https://easings.net/#easeInQuart
            ##}\n  {{ percentageOfTimeCompleted * percentageOfTimeCompleted * percentageOfTimeCompleted
            * percentageOfTimeCompleted }}\n  \n{% elif easingType == \"easeOutSine\"
            %}\n  {## https://easings.net/#easeOutSine ##}\n  {{ sin((percentageOfTimeCompleted
            * pi) / 2) }}\n\n{% elif easingType == \"easeOutQuad\" %}\n  {## https://easings.net/#easeOutQuad
            ##}\n  {{ 1 - (1 - percentageOfTimeCompleted)* (1 - percentageOfTimeCompleted)
            }} \n\n{% elif easingType == \"easeOutCubic\" %}\n  {## https://easings.net/#easeOutCubic
            ##}\n  {{ 1 - ((1 - percentageOfTimeCompleted) ** 3) }}\n\n{% elif easingType
            == \"easeOutQuart\" %}\n  {## https://easings.net/#easeOutQuart ##}\n
            \ {{ 1 - ((1 - percentageOfTimeCompleted) ** 4) }}\n\n{% elif easingType
            == \"easeInOutSine\" %}\n  {## https://easings.net/#easeInOutSine ##}\n
            \ {{ -1 * ((cos(pi * percentageOfTimeCompleted) - 1) / 2) }}\n  \n{% elif
            easingType == \"easeInOutQuad\" %}\n  {## https://easings.net/#easeInOutQuad
            ##}\n  {% if (percentageOfTimeCompleted < 0.5) %}\n    {{ 2 * percentageOfTimeCompleted
            * percentageOfTimeCompleted }} \n  {% else %}\n    {{ 1- (((-2 * percentageOfTimeCompleted
            + 2) ** 2) / 2) }} \n  {% endif %}\n  \n{% elif easingType == \"easeInOutCubic\"
            %}\n  {## https://easings.net/#easeInOutCubic ##}\n  {% if (percentageOfTimeCompleted
            < 0.5) %}\n    {{ 4 * percentageOfTimeCompleted * percentageOfTimeCompleted
            * percentageOfTimeCompleted }} \n  {% else %}\n    {{ 1- (((-2 * percentageOfTimeCompleted
            + 2) ** 3) / 2) }} \n  {% endif %}\n    \n{% elif easingType == \"easeInOutQuart\"
            %}\n  {## https://easings.net/#easeInOutQuart ##}\n  {% if (percentageOfTimeCompleted
            < 0.5) %}\n    {{ 8 * percentageOfTimeCompleted * percentageOfTimeCompleted
            * percentageOfTimeCompleted * percentageOfTimeCompleted }} \n  {% else
            %}\n    {{ 1 - (((-2 * percentageOfTimeCompleted + 2) ** 4) / 2) }} \n
            \ {% endif %}\n{% else %}\n  {## linear ##}\n  {{ percentageOfTimeCompleted
            }}\n{% endif %}\n"
          expectedBrightness: "{% if isBrightnessFadeEnabled %}\n  {% set startBrightness
            = startBrightness | int %}\n  {% set brightnessSpan = brightnessSpan |
            int %}\n  {% set easingAdjustedPercentageCompleted = easingAdjustedPercentageCompleted
            | float(0) %}\n\n  {% set calculatedBrightness = (startBrightness + (brightnessSpan
            * easingAdjustedPercentageCompleted)) | round(0) %}\n  {% if (calculatedBrightness
            < 0) %}\n    {% set calculatedBrightness = 0 %}\n  {% elif (calculatedBrightness
            > 255) %}\n    {% set calculatedBrightness = 255 %}\n  {% endif %}\n\n
            \ {% if (endBrightness >= startBrightness) and (calculatedBrightness >
            endBrightness) %}\n    {% set calculatedBrightness = endBrightness %}\n
            \ {% elif (endBrightness < startBrightness) and (calculatedBrightness
            < endBrightness) %}\n    {% set calculatedBrightness = endBrightness %}\n
            \ {% endif %}\n{% else %}\n  {## if isBrightnessFadeEnabled is false ##}\n
            \ {% set calculatedBrightness = startBrightness %}\n{% endif %}\n\n{{
            calculatedBrightness }}\n"
          linearExpectedBrightness: "{% if isBrightnessFadeEnabled %}              \n
            \ {% set startBrightness = startBrightness | int %}\n  {% set brightnessSpan
            = brightnessSpan | int %}\n  {% set percentageOfTimeCompleted = percentageOfTimeCompleted
            | float(0) %}\n  \n  {% set calculatedBrightness = (startBrightness +
            (brightnessSpan * percentageOfTimeCompleted)) | round(0) %}\n  {% if (calculatedBrightness
            < 0) %}\n    {% set calculatedBrightness = 0 %}\n  {% elif (calculatedBrightness
            > 255) %}\n    {% set calculatedBrightness = 255 %}\n  {% endif %}\n\n
            \ {% if (endBrightness >= startBrightness) and (calculatedBrightness >
            endBrightness) %}\n    {% set calculatedBrightness = endBrightness %}\n
            \ {% elif (endBrightness < startBrightness) and (calculatedBrightness
            < endBrightness) %}\n    {% set calculatedBrightness = endBrightness %}\n
            \ {% endif %}\n{% else %}\n  {## if isBrightnessFadeEnabled is false ##}\n
            \ {% set calculatedBrightness = startBrightness %}\n{% endif %}\n\n{{
            calculatedBrightness }}\n"
          currentBrightness: "{% if isBrightnessFadeEnabled %}\n  {% set rawLightLevel
            = state_attr(light, 'brightness') %}\n\n  {## If a light is off, its brightness
            will return \"None\"? So first check if there's a valid brightness before
            getting the value ##}\n  {% if rawLightLevel %}\n  \t{% set currentLightLevel
            = rawLightLevel | int %}\n  {% else %}\n  \t{% set currentLightLevel =
            0 %}\n  {% endif %}\n  {% if lampBrightnessScale == \"zeroToOneHundred\"
            %}\n    {% set currentLightLevel = (currentLightLevel / 2.55) | round(0)
            %}\n  {% endif %}\n{% else %}\n  {% set currentLightLevel = startBrightness
            %}\n{% endif %}\n\n{{ currentLightLevel }}\n\n"
          expectedColorTemperature: "{% if isColorFadeEnabled %}\n  {% set startColorTemperature
            = startColorTemperature | int %}\n  {% set colorTemperatureSpan = colorTemperatureSpan
            | int %}\n  {% set easingAdjustedPercentageCompleted = easingAdjustedPercentageCompleted
            | float(0) %}\n\n  {% set calculatedColorTemperature = (startColorTemperature
            + (colorTemperatureSpan * easingAdjustedPercentageCompleted)) | round(0)
            %}\n\n  {% set minColorTemperatureKelvin = minColorTemperatureKelvin |
            int %}\n  {% set maxColorTemperatureKelvin = maxColorTemperatureKelvin
            | int %}\n\n  {% if (calculatedColorTemperature < minColorTemperatureKelvin)
            %}\n    {% set calculatedColorTemperature = minColorTemperatureKelvin
            %}\n  \n  {% elif (calculatedColorTemperature > maxColorTemperatureKelvin)
            %}\n    {% set calculatedColorTemperature = maxColorTemperatureKelvin
            %}\n  {% endif %}\n\n  {% if (endColorTemperature >= startColorTemperature)
            and (calculatedColorTemperature > endColorTemperature) %}\n    {% set
            calculatedColorTemperature = endColorTemperature %}\n  {% elif (endColorTemperature
            < startColorTemperature) and (calculatedColorTemperature < endColorTemperature)
            %}\n    {% set calculatedColorTemperature = endColorTemperature %}\n  {%
            endif %}\n{% else %}\n  {% set calculatedColorTemperature = 0 %}\n{% endif
            %}\n\n{{ calculatedColorTemperature }}\n"
          currentColorTemperature: "{## init ##}\n{% set currentColorTemperature =
            -1 %}\n{% if isColorFadeEnabled %}\n  {% set rawColorTemperature = state_attr(light,
            'color_temp_kelvin') %}\n  \n  {## If a light is off or if its color temperature
            is defined using a non-Kelvin color system, its color temperature will
            return \"None\"? So first check if there's a valid color temperature ##}\n
            \ {% if rawColorTemperature %}\n  \n    {% if is_number(rawColorTemperature)
            %}\n      {% set currentColorTemperature = rawColorTemperature | int %}\n
            \   {% endif %}\n  {% endif %}\n{% endif %}\n\n{{ currentColorTemperature
            }}\n"
      - if:
        - condition: template
          value_template: '{{ isBrightnessFadeEnabled and isColorFadeEnabled }}

            '
        then:
        - if:
          - condition: template
            value_template: "{{ \n  (\n    ( (currentBrightness | int) != (endBrightness
              | int) )\n    and\n    ( (currentBrightness | int) != (expectedBrightness
              | int) )\n  )\n  or\n  (\n    ( (currentColorTemperature | int) != (endColorTemperature
              | int) )\n    and\n    ( (currentColorTemperature | int) != (expectedColorTemperature
              | int) )\n  )\n}}\n"
          then:
          - if:
            - condition: template
              value_template: '{{ shouldUseNativeLampTransitionsToo }}

                '
            then:
            - if:
              - condition: template
                value_template: '{{ (lampBrightnessScale == "zeroToTwoFiftyFive")
                  }}

                  '
              then:
              - target:
                  entity_id: '{{ light }}'
                data:
                  brightness: '{{ expectedBrightness }}'
                  kelvin: '{{ expectedColorTemperature }}'
                  transition: '{{ transitionTimeParameterInSeconds | float(0)  }}'
                action: light.turn_on
              else:
              - target:
                  entity_id: '{{ light }}'
                data:
                  brightness_pct: '{{ expectedBrightness }}'
                  kelvin: '{{ expectedColorTemperature }}'
                  transition: '{{ transitionTimeParameterInSeconds | float(0) }}'
                action: light.turn_on
            else:
            - if:
              - condition: template
                value_template: '{{ (lampBrightnessScale == "zeroToTwoFiftyFive")
                  }}

                  '
              then:
              - target:
                  entity_id: '{{ light }}'
                data:
                  brightness: '{{ expectedBrightness }}'
                  kelvin: '{{ expectedColorTemperature }}'
                action: light.turn_on
              else:
              - target:
                  entity_id: '{{ light }}'
                data:
                  brightness_pct: '{{ expectedBrightness }}'
                  kelvin: '{{ expectedColorTemperature }}'
                action: light.turn_on
          - if:
            - condition: template
              value_template: '{{ isDebugMode }}

                '
            then:
            - if:
              - condition: template
                value_template: '{{ isColorFadeEnabled and isBrightnessFadeEnabled
                  }}

                  '
              then:
              - data_template:
                  message: 'Set {{ lightFriendlyName }} to {{ expectedBrightness |
                    int }} brightness and {{ expectedColorTemperature | int }}°K.
                    (Linear brightness would have been {{ linearExpectedBrightness
                    | int }}.) Delay is {{ delayInMilliseconds | int }} ms. Elapsed
                    time is {{ (as_timestamp(now()) - startTimestamp) | round(2) }}
                    seconds. (endBrightness is {{ endBrightness}} and endColorTemperature
                    is {{ endColorTemperature}}.)

                    '
                  level: warning
                action: system_log.write
        else:
        - if:
          - condition: template
            value_template: "{{ isBrightnessFadeEnabled and \n  (\n    ( (currentBrightness
              | int) != (endBrightness | int) ) \n    and\n    ( (currentBrightness
              | int) != (expectedBrightness | int) ) \n  )\n  }}\n"
          then:
          - if:
            - condition: template
              value_template: '{{ shouldUseNativeLampTransitionsToo }}

                '
            then:
            - if:
              - condition: template
                value_template: '{{ (lampBrightnessScale == "zeroToTwoFiftyFive")
                  }}

                  '
              then:
              - target:
                  entity_id: '{{ light }}'
                data:
                  brightness: '{{ expectedBrightness }}'
                  transition: '{{ transitionTimeParameterInSeconds }}'
                action: light.turn_on
              else:
              - target:
                  entity_id: '{{ light }}'
                data:
                  brightness_pct: '{{ expectedBrightness }}'
                  transition: '{{ transitionTimeParameterInSeconds }}'
                action: light.turn_on
            else:
            - if:
              - condition: template
                value_template: '{{ (lampBrightnessScale == "zeroToTwoFiftyFive")
                  }}

                  '
              then:
              - target:
                  entity_id: '{{ light }}'
                data:
                  brightness: '{{ expectedBrightness }}'
                action: light.turn_on
              else:
              - target:
                  entity_id: '{{ light }}'
                data:
                  brightness_pct: '{{ expectedBrightness }}'
                action: light.turn_on
          - if:
            - condition: template
              value_template: '{{ isDebugMode }}

                '
            then:
            - data_template:
                message: 'Set {{ lightFriendlyName }} to {{ expectedBrightness | int
                  }} brightness. (Linear brightness would have been {{ linearExpectedBrightness
                  | int }}.) Delay is {{ delayInMilliseconds | int }} ms. Elapsed
                  time is {{ (as_timestamp(now()) - startTimestamp) | round(2) }}
                  seconds. (endBrightness is {{ endBrightness}}.)

                  '
                level: warning
              action: system_log.write
          else:
          - if:
            - condition: template
              value_template: "{{ isColorFadeEnabled and \n  (\n    ( (currentColorTemperature
                | int) != (endColorTemperature | int) ) \n    and\n    ( (currentColorTemperature
                | int) != (expectedColorTemperature | int) ) \n  )\n}}\n"
            then:
            - if:
              - condition: template
                value_template: '{{ shouldUseNativeLampTransitionsToo }}

                  '
              then:
              - target:
                  entity_id: '{{ light }}'
                data:
                  kelvin: '{{ expectedColorTemperature }}'
                  transition: '{{ transitionTimeParameterInSeconds | round(3) }}'
                action: light.turn_on
              else:
              - target:
                  entity_id: '{{ light }}'
                data:
                  kelvin: '{{ expectedColorTemperature }}'
                action: light.turn_on
            - if:
              - condition: template
                value_template: '{{ isDebugMode }}

                  '
              then:
              - data_template:
                  message: 'Set {{ lightFriendlyName }} to {{ expectedColorTemperature
                    | int }}°K. Delay is {{ delayInMilliseconds | int }} ms. Elapsed
                    time is {{ (as_timestamp(now()) - startTimestamp) | round(2) }}
                    seconds. (endColorTemperature is {{ endColorTemperature}}.)

                    '
                  level: warning
                action: system_log.write
      - delay:
          milliseconds: '{{ delayInMilliseconds | float(0) }}'
      - if:
        - condition: template
          value_template: "{## init ##} {% set shouldStop = false %} {% if isStopEntityEnabled
            %}\n  {% if (shouldInvertTheValueOfTheStopEntity is defined) and shouldInvertTheValueOfTheStopEntity
            %}\n    {% if not bool(states(stopEntity), false) %}\n      {% set shouldStop
            = true %}\n    {% endif %}\n  {% else %}\n    {% if bool(states(stopEntity),
            false) %}\n      {% set shouldStop = true %}\n    {% endif %}\n  {% endif
            %}\n{% endif %} {{ shouldStop }}\n"
        then:
        - if:
          - condition: template
            value_template: '{{ (shouldInvertTheValueOfTheStopEntity is defined) and
              shouldInvertTheValueOfTheStopEntity }}

              '
          then:
          - variables:
              stopMessage: '{% set stopMessage = "Stopped Ashley’s Light Fader because
                " + (stopEntityFriendlyName | string) + " turned off." %} {{ stopMessage
                }}

                '
          - if:
            - condition: template
              value_template: '{{ isDebugMode }}

                '
            then:
            - data_template:
                message: '{{ stopMessage }}

                  '
                level: warning
              action: system_log.write
          - stop: '{{ stopMessage }}

              '
          else:
          - variables:
              stopMessage: '{% set stopMessage = "Stopped Ashley’s Light Fader because
                " + (stopEntityFriendlyName | string) + " turned on." %} {{ stopMessage
                }}

                '
          - if:
            - condition: template
              value_template: '{{ isDebugMode }}

                '
            then:
            - data_template:
                message: '{{ stopMessage }}

                  '
                level: warning
              action: system_log.write
          - stop: '{{ stopMessage }}

              '
      - variables:
          currentBrightness: "{% if is_state(light, 'off') %}\n  {% set currentLightLevel
            = 0 %}\n  {{ currentLightLevel }}\n{% else %}\n  {% set rawLightLevel
            = state_attr(light, 'brightness') %}\n\n  {## If a light is off, its brightness
            will return 'None'. So first check if there's a valid brightness before
            getting the value ##}\n\n  {% if rawLightLevel %}\n  \t{% set currentLightLevel
            = rawLightLevel | int %}\n  {% else %}\n  \t{% set currentLightLevel =
            0 %}\n  {% endif %}\n  {% if lampBrightnessScale == \"zeroToOneHundred\"
            %}\n    {% set currentLightLevel = (currentLightLevel / 2.55) | round(0)
            %}\n  {% endif %}\n\n  {{ currentLightLevel }}\n{% endif %}\n\n"
          brightnessDifferenceFromExpected: '{{ ( (currentBrightness | int) - (expectedBrightness
            | int) ) | abs }}

            '
          isBrightnessDifferenceAboveAutoCancelThreshold: "{% if shouldAutoCancelTheFadeIfTheLampBrightnessIsManuallyChanged
            %}\n  {{ (brightnessDifferenceFromExpected | int) >= (normalizedAutoCancelThreshold
            | int) }}\n{% else %}\n  {{ false }}\n{% endif %}\n"
      - if:
        - condition: template
          value_template: "{{ (\n    (\n    (not (shouldStopIfTheLampIsTurnedOffDuringTheFade
            is defined)) or\n       (\n         (shouldStopIfTheLampIsTurnedOffDuringTheFade
            is defined) and \n         shouldStopIfTheLampIsTurnedOffDuringTheFade\n
            \       )\n     )\n     and ( ((expectedBrightness | int) > 0) and ((currentBrightness
            | int) == 0) )\n   ) \n  }}\n"
        then:
        - variables:
            stopMessage: '{% set stopMessage = "Stopped Ashley’s Light Fader because
              " + (lightFriendlyName | string) + " was turned off during the fade."
              %}

              {{ stopMessage }}

              '
        - if:
          - condition: template
            value_template: '{{ isDebugMode }}

              '
          then:
          - data_template:
              message: '{{ stopMessage }}

                '
              level: warning
            action: system_log.write
        - stop: '{{ stopMessage }}

            '
      - if:
        - condition: template
          value_template: '{{ shouldAutoCancelTheFadeIfTheLampBrightnessIsManuallyChanged
            and isBrightnessDifferenceAboveAutoCancelThreshold }}

            '
        then:
        - variables:
            stopMessage: "{% if lampBrightnessScale == \"zeroToTwoFiftyFive\" %}\n
              \ {% set currentBrightnessAsPercentage = (currentBrightness / 2.55)
              | round(0) %}\n  {% set expectedBrightnessAsPercentage = (expectedBrightness
              / 2.55) | round(0) %}\n  {% set differenceFromExpectedAsPercentage =
              (brightnessDifferenceFromExpected / 2.55) | round(0) %}\n{% else %}\n
              \ {% set currentBrightnessAsPercentage = currentBrightness %}\n  {%
              set expectedBrightnessAsPercentage = expectedBrightness %}\n  {% set
              differenceFromExpectedAsPercentage = brightnessDifferenceFromExpected
              %}\n{% endif %}\n\n{% set stopMessage = \"Stopped Ashley’s Light Fader
              because \" + (lightFriendlyName | string) + \" was found to be at \"
              + (currentBrightnessAsPercentage | string) + \"%, a difference of \"
              + (differenceFromExpectedAsPercentage | string) + \" percentage points
              from the expected brightness of \" + (expectedBrightnessAsPercentage
              | string) + \"%, which is higher than the auto-cancel threshold of \"
              + (autoCancelThreshold | string) + \" percentage points.\" %}\n{{ stopMessage
              }}\n"
        - if:
          - condition: template
            value_template: '{{ isDebugMode }}

              '
          then:
          - data_template:
              message: '{{ stopMessage }}

                '
              level: warning
            action: system_log.write
        - stop: '{{ stopMessage }}

            '
      - if:
        - condition: not
          conditions:
          - condition: template
            value_template: '{{ effect == current_effect }}'
        then:
        - target:
            entity_id: '{{ light }}'
          data:
            effect: '{{ effect }}'
          action: light.turn_on
      until:
      - condition: template
        value_template: "{% if (as_timestamp(now()) >= endTimestamp) %}\n  {{ true
          }}\n{% elif isBrightnessFadeEnabled or isColorFadeEnabled %}\n  {## init
          ##}\n  {% set okayToEndTheLoop = true %}\n  \n  {% if isBrightnessFadeEnabled
          %}\n    {% set rawLightLevel = state_attr(light, 'brightness') %}\n\n    {##
          If a light is off, its brightness will return \"None\"? So first check if
          there's a valid brightness before getting the value ##}\n    {% if rawLightLevel
          %}\n    \t{% set currentLightLevel = rawLightLevel | int %}\n    {% else
          %}\n    \t{% set currentLightLevel = 0 %}\n    {% endif %}\n    {% if lampBrightnessScale
          == \"zeroToOneHundred\" %}\n      {% set currentLightLevel = (currentLightLevel
          / 2.55) | round(0) %}\n    {% endif %}\n  \n    {% if (endBrightness >=
          startBrightness) and (currentLightLevel < endBrightness) %}\n      {% set
          okayToEndTheLoop = false %}\n    {% elif (endBrightness < startBrightness)
          and (currentLightLevel > endBrightness) %}\n      {% set okayToEndTheLoop
          = false %}\n    {% endif %}\n  {% endif %}\n  \n  {## The \"and okayToEndTheLoop\"
          part is to avoid needlessly checking whether the color temp fails if the
          brightness check already fails ##}\n  {% if isColorFadeEnabled and okayToEndTheLoop
          %}\n\n    {## init ##}\n    {% set currentColorTemperature = -1 %}\n    \n
          \   {% set rawColorTemperature = state_attr(light, 'color_temp_kelvin')
          %}\n  \n    {## If a light is off or if its color temperature is defined
          using a non-Kelvin color system, its color temperature will return \"None\"?
          So first check if there's a valid color temperature ##}\n    {% if rawColorTemperature
          %}\n  \n      {% if is_number(rawColorTemperature) %}\n        {% set currentColorTemperature
          = rawColorTemperature | int %}\n      {% endif %}\n    {% endif %}\n    \n
          \   {% if (currentColorTemperature != -1) and (endColorTemperature >= startColorTemperature)
          and (currentColorTemperature < endColorTemperature) %}\n      {% set okayToEndTheLoop
          = false %}\n    {% elif (currentColorTemperature != -1) and (endColorTemperature
          < startColorTemperature) and (currentColorTemperature > endColorTemperature)
          %}\n      {% set okayToEndTheLoop = false %}\n    {% endif %}\n\n  {% endif
          %}\n  \n  {{ okayToEndTheLoop }}\n    \n{% else %}\n  {## neither isBrightnessFadeEnabled
          nor isColorFadeEnabled ##} \n  {{ true }}\n{% endif %}\n\n"
  - variables:
      currentBrightness: "{% set rawLightLevel = state_attr(light, 'brightness') %}\n\n{##
        If a light is off, its brightness will return 'None'. So first check if there's
        a valid brightness before getting the value ##}\n{% if rawLightLevel %}\n\t{%
        set currentLightLevel = rawLightLevel | int %}\n{% else %}\n\t{% set currentLightLevel
        = 0 %}\n{% endif %}\n{% if lampBrightnessScale == \"zeroToOneHundred\" %}\n
        \ {% set currentLightLevel = (currentLightLevel / 2.55) | round(0) %}\n{%
        endif %}\n\n{{ currentLightLevel }}\n"
      brightnessDifferenceFromExpected: '{{ ( (currentBrightness | int) - (endBrightness
        | int) ) | abs }}

        '
      isBrightnessDifferenceAboveAutoCancelThreshold: "{% if shouldAutoCancelTheFadeIfTheLampBrightnessIsManuallyChanged
        %}\n  {{ (brightnessDifferenceFromExpected | int) > (normalizedAutoCancelThreshold
        | int) }}\n{% else %}\n  {{ false }}\n{% endif %}\n"
      currentColorTemperature: "{## init ##} {% set currentColorTemperature = -1 %}
        {% if isColorFadeEnabled %}\n  {% set rawColorTemperature = state_attr(light,
        'color_temp_kelvin') %}\n  \n  {## If a light is off or if its color temperature
        is defined using a non-Kelvin color system, its color temperature will return
        \"None\"? So first check if there's a valid color temperature ##}\n  {% if
        rawColorTemperature %}\n  \n    {% if is_number(rawColorTemperature) %}\n
        \     {% set currentColorTemperature = rawColorTemperature | int %}\n    {%
        endif %}\n  {% endif %}\n{% endif %}\n{{ currentColorTemperature }}\n"
  - if:
    - condition: template
      value_template: "{{ (\n      (not shouldAutoCancelTheFadeIfTheLampBrightnessIsManuallyChanged)
        or \n      (not isBrightnessDifferenceAboveAutoCancelThreshold)\n    ) \n
        \   and\n    (\n      (not (shouldStopIfTheLampIsTurnedOffDuringTheFade is
        defined)) or\n      (not shouldStopIfTheLampIsTurnedOffDuringTheFade) or\n
        \     ((currentBrightness | int) != 0)\n    )\n    }}\n"
    then:
    - if:
      - condition: template
        value_template: "{{ isColorFadeEnabled and isBrightnessFadeEnabled \nand\n(\n
          \ (isBrightnessFadeEnabled and ((currentBrightness | int) != (endBrightness
          | int)) )\n  or (isColorFadeEnabled and ((currentColorTemperature | int)
          != (endColorTemperature | int)) )\n)\n}}\n"
      then:
      - if:
        - condition: template
          value_template: '{{ (lampBrightnessScale == "zeroToTwoFiftyFive") }}

            '
        then:
        - target:
            entity_id: '{{ light }}'
          data:
            brightness: '{{ endBrightness }}'
            kelvin: '{{ endColorTemperature }}'
          action: light.turn_on
        else:
        - target:
            entity_id: '{{ light }}'
          data:
            brightness_pct: '{{ endBrightness }}'
            kelvin: '{{ endColorTemperature }}'
          action: light.turn_on
      else:
      - if:
        - condition: template
          value_template: '{{ isBrightnessFadeEnabled and ((currentBrightness | int)
            != (endBrightness | int)) }}

            '
        then:
        - if:
          - condition: template
            value_template: '{{ (lampBrightnessScale == "zeroToTwoFiftyFive") }}

              '
          then:
          - target:
              entity_id: '{{ light }}'
            data:
              brightness: '{{ endBrightness }}'
            action: light.turn_on
          else:
          - target:
              entity_id: '{{ light }}'
            data:
              brightness_pct: '{{ endBrightness }}'
            action: light.turn_on
        else:
        - if:
          - condition: template
            value_template: '{{ isColorFadeEnabled and ((currentColorTemperature |
              int) != (endColorTemperature | int)) }}

              '
          then:
          - target:
              entity_id: '{{ light }}'
            data:
              kelvin: '{{ endColorTemperature }}'
            action: light.turn_on
    - if:
      - condition: template
        value_template: '{{ isDebugMode }}

          '
      then:
      - if:
        - condition: template
          value_template: '{{ isColorFadeEnabled and isBrightnessFadeEnabled }}

            '
        then:
        - data_template:
            message: 'Set {{ lightFriendlyName }} to {{ endBrightness | int }} brightness
              and {{ endColorTemperature | int }}°K. Elapsed time is {{ (as_timestamp(now())
              - startTimestamp) | round(2) }} seconds.

              '
            level: warning
          action: system_log.write
        else:
        - if:
          - condition: template
            value_template: '{{ isBrightnessFadeEnabled }}

              '
          then:
          - data_template:
              message: 'Set {{ lightFriendlyName }} to {{ endBrightness | int }} brightness.
                Elapsed time is {{ (as_timestamp(now()) - startTimestamp) | round(2)
                }} seconds.

                '
              level: warning
            action: system_log.write
          else:
          - if:
            - condition: template
              value_template: '{{ isColorFadeEnabled }}

                '
            then:
            - data_template:
                message: 'Set {{ lightFriendlyName }} to {{ endColorTemperature |
                  int }}°K. Elapsed time is {{ (as_timestamp(now()) - startTimestamp)
                  | round(2) }} seconds.

                  '
                level: warning
              action: system_log.write
  mode: parallel
  max: 15
  icon: mdi:lightbulb-on-50
global_light_control:
  alias: Global Light Control
  sequence:
  - variables:
      wled: "{{ expand('light.group_lucy')\n   | selectattr('entity_id','search','^light.wled_')\n
        \  | selectattr('state', 'eq', 'on')\n   | map(attribute='entity_id')\n   |
        list }}\n"
      onoff: "{{ expand('light.group_lucy')\n   | selectattr('entity_id','search','^light.tasmota_')\n
        \  | selectattr('state', 'eq', 'on')\n   | map(attribute='entity_id')\n   |
        list }}\n"
      others: "{{ expand('light.group_lucy') \n  | rejectattr('entity_id','search','^light.tasmota_')
        \n  | rejectattr('entity_id','search','^light.wled_')\n  | selectattr('state',
        'eq', 'on')\n  | map(attribute='entity_id')\n  | list }}\n"
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ is_state(''light.group_lucy'',''on'') }}'
      sequence:
      - action: script.state_save
      - action: input_number.set_value
        metadata: {}
        data:
          value: 0
        target:
          entity_id: input_number.fade_target
        enabled: false
      - action: light.turn_off
        metadata: {}
        data:
          transition: 14
        target:
          entity_id: '{{wled}}'
      - action: light.turn_off
        metadata: {}
        target:
          entity_id: '{{onoff}}'
      - repeat:
          sequence:
          - action: script.ashley_s_light_fader
            metadata: {}
            data:
              lampBrightnessScale: zeroToTwoFiftyFive
              easingTypeInput: auto
              endBrightnessPercent: 0
              endBrightnessEntityScale: zeroToOneHundred
              shouldStopIfTheLampIsTurnedOffDuringTheFade: false
              shouldResetTheStopEntityToOffAtStart: false
              shouldInvertTheValueOfTheStopEntity: false
              minimumStepDelayInMilliseconds: 100
              shouldTryToUseNativeLampTransitionsToo: false
              isDebugMode: false
              light: '{{repeat.item}}'
              transitionTime:
                hours: 0
                minutes: 0
                seconds: 5
          for_each: '{{ others }}'
      alias: Fade off, lights on
    - conditions:
      - condition: template
        value_template: '{{ is_state(''light.group_lucy'',''off'') }}'
      sequence:
      - action: script.state_restore
      alias: lights off
  mode: parallel
  max: 10
  description: ''
  icon: mdi:lightbulb
  fields: {}
scene_control:
  alias: Scene Control
  sequence:
  - variables:
      advanced_lights:
      - light.wled_ceiling
      - light.wled_desktop
      - light.wled_ghost
      - light.wled_umbreon
      - light.wled_bed
      - light.wled_tv
      - light.hexagon_2
      simple_lights:
      - light.tasmota_bed_bed
      - light.tasmota_heart_heart
      - light.tasmota_uv_uv
      - light.tasmota_vitrine_vitrine
      desktop_on:
      - light.wled_desktop
      - light.wled_umbreon
      - light.hexagon_2
      desktop_off:
      - light.tasmota_uv_uv
      - light.tasmota_vitrine_vitrine
      - light.tasmota_bed_bed
      - light.wled_ceiling
      - light.wled_bed
      - light.wled_tv
      - light.wled_bed
      - light.tasmota_heart_heart
      - light.wled_ghost
  - alias: Music Scene
    choose:
    - conditions:
      - condition: template
        value_template: '

          {{ scene == "MusicFX" }}'
      sequence:
      - if:
        - condition: not
          conditions:
          - condition: state
            entity_id: media_player.ledfx
            state: playing
          - condition: state
            entity_id: media_player.ledfx
            state: unavailable
        then:
        - action: media_player.media_play
          target:
            entity_id:
            - media_player.ledfx
          data: {}
      - if:
        - condition: not
          conditions:
          - condition: state
            entity_id: input_select.hexagon_effects
            state: Dancin' Foxx
        then:
        - action: input_select.select_option
          metadata: {}
          data:
            option: Dancin' Foxx
          target:
            entity_id: input_select.hexagon_effects
        - action: script.update_saved_states
          metadata: {}
          data:
            entity: binary_sensor.lights_previous
      alias: Turn On Music Scene
    - conditions:
      - condition: template
        value_template: '{{ scene != "MusicFX" }}'
      sequence:
      - if:
        - condition: state
          entity_id: input_select.hexagon_effects
          state: Dancin' Foxx
        then:
        - action: input_select.select_option
          metadata: {}
          data:
            option: '{{ state_attr(''binary_sensor.lights_previous'',''input_select.hexagon_effects'')     }}'
          target:
            entity_id: input_select.hexagon_effects
      - if:
        - condition: state
          entity_id: media_player.ledfx
          state: playing
        then:
        - action: media_player.media_pause
          target:
            entity_id:
            - media_player.ledfx
          data: {}
      alias: Turn Off Music Scene
  - alias: Scenes
    choose:
    - conditions:
      - condition: template
        value_template: '{{scene==''Default''}}'
      sequence:
      - action: script.state_save
        data:
          entity: binary_sensor.lights_previous
      - action: script.state_restore
        data:
          entity: binary_sensor.default
      alias: Default
    - conditions:
      - condition: template
        value_template: '{{ scene == "Desktop"}}

          '
      sequence:
      - action: script.state_save
        data:
          entity: binary_sensor.lights_previous
      - repeat:
          for_each: '{{ desktop_on }}'
          sequence:
          - data:
              brightness: 15
              transition: 7
            target:
              entity_id: '{{ repeat.item }}'
            action: light.turn_on
            enabled: true
        enabled: true
      - repeat:
          sequence:
          - if:
            - condition: template
              value_template: '{{ states(repeat.item) == ''on'' }}'
            then:
            - action: light.turn_off
              metadata: {}
              data:
                transition: 7
              target:
                entity_id: '{{ repeat.item }}'
          for_each: '{{ desktop_off }}'
        enabled: true
      alias: Desktop
    - conditions:
      - condition: template
        value_template: '{{ scene == "Romantic" and states(''sensor.scene_romantic'')
          != ''True''  }}

          '
      sequence:
      - action: script.update_saved_states
        metadata: {}
        data:
          entity: binary_sensor.lights_previous
      - if:
        - condition: not
          conditions:
          - condition: state
            entity_id: input_select.hexagon_effects
            state: Romantic
        then:
        - action: input_select.select_option
          metadata: {}
          data:
            option: Romantic
          target:
            entity_id: input_select.hexagon_effects
      - action: select.select_option
        target:
          entity_id: select.wled_preset
        data:
          option: Romantic
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
          milliseconds: 0
      - parallel:
        - action: script.ashley_s_light_fader
          metadata: {}
          data:
            lampBrightnessScale: zeroToOneHundred
            easingTypeInput: auto
            endBrightnessPercent: 8
            endBrightnessEntityScale: zeroToOneHundred
            shouldStopIfTheLampIsTurnedOffDuringTheFade: false
            shouldResetTheStopEntityToOffAtStart: false
            shouldInvertTheValueOfTheStopEntity: false
            minimumStepDelayInMilliseconds: 150
            shouldTryToUseNativeLampTransitionsToo: false
            isDebugMode: false
            light: light.hexagon_2
            transitionTime:
              hours: 0
              minutes: 0
              seconds: 3
        - action: light.turn_on
          metadata: {}
          data:
            transition: 8
            brightness_pct: 14
          target:
            entity_id: light.wled
      alias: Romantic
    - conditions:
      - condition: template
        value_template: '{{ scene == ''Only UV'' and states(''sensor.scene_uv'') !=
          ''True''  }}

          '
      sequence:
      - action: script.update_saved_states
        data:
          entity: binary_sensor.lights_previous
      - parallel:
        - action: script.ashley_s_light_fader
          metadata: {}
          data:
            lampBrightnessScale: zeroToOneHundred
            easingTypeInput: auto
            endBrightnessPercent: 0
            endBrightnessEntityScale: zeroToOneHundred
            shouldStopIfTheLampIsTurnedOffDuringTheFade: false
            shouldResetTheStopEntityToOffAtStart: false
            shouldInvertTheValueOfTheStopEntity: false
            minimumStepDelayInMilliseconds: 100
            shouldTryToUseNativeLampTransitionsToo: false
            isDebugMode: false
            light: light.hexagon_2
            transitionTime:
              hours: 0
              minutes: 0
              seconds: 3
        - action: script.ashley_s_light_fader
          metadata: {}
          data:
            lampBrightnessScale: zeroToTwoFiftyFive
            easingTypeInput: auto
            endBrightnessPercent: 0
            endBrightnessEntityScale: zeroToOneHundred
            shouldStopIfTheLampIsTurnedOffDuringTheFade: false
            shouldResetTheStopEntityToOffAtStart: false
            shouldInvertTheValueOfTheStopEntity: false
            minimumStepDelayInMilliseconds: 150
            shouldTryToUseNativeLampTransitionsToo: false
            isDebugMode: false
            light: light.wled
            transitionTime:
              hours: 0
              minutes: 0
              seconds: 3
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
          milliseconds: 0
      - action: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.real_light_entities
      - action: light.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: light.tasmota_uv_uv
      alias: UV
    default: []
  fields:
    scene:
      selector:
        text:
      name: scene
      default: default
      required: true
  description: ''
  mode: parallel
  max: 10
notify:
  alias: Notify
  sequence:
  - variables:
      duration: "{% if duration is defined %}\n  {{ duration }}\n{% else %}\n  00:00:03\n{%
        endif %}\n"
      title: '{{ title if title is defined else ''Notification'' }}'
      content: '{{ content }}'
      id: '{{ id if id is defined else '''' }}'
      show_popup: '{{ show_popup if show_popup is defined else true }}'
      play_sound: '{{ play_sound if play_sound is defined else false }}'
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ play_sound }}'
      sequence:
      - if: []
        then:
        - variables:
            ledfx_was_on: true
        - action: media_player.media_play
          target:
            entity_id: media_player.ledfx
          data: {}
      - if:
        - condition: state
          entity_id: media_player.vlc_telnet
          state: playing
        then:
        - variables:
            vlc_was_on: true
        - action: media_player.media_pause
          data: {}
          target:
            entity_id: media_player.vlc_telnet
      - action: button.press
        metadata: {}
        data: {}
        target:
          entity_id: button.lucy_pc_alarmsound
  - choose:
    - conditions:
      - condition: template
        value_template: '{{id != ""}}'
      sequence:
      - action: persistent_notification.create
        data:
          title: '{{ title }}'
          message: '{{ content }}'
          notification_id: '{{ id }}'
    default:
    - action: persistent_notification.create
      data:
        title: '{{ title }}'
        message: '{{ content }}'
  - choose:
    - conditions:
      - condition: template
        value_template: '{{show_popup}}'
      sequence:
      - action: timer.start
        metadata: {}
        data:
          duration: 00:00:03
        target:
          entity_id: timer.show_notification
        enabled: false
      - action: browser_mod.popup
        data:
          dismissable: true
          autoclose: false
          content:
            type: custom:home-feed-card
            title: '{{title}}'
            more_info_on_tap: true
            show_empty: false
            show_notification_title: false
            show_icons: false
            id_filter: ^..*
            compact_mode: true
            max_item_count: 1
          browser_id:
          - 73abbcdb326ecda81f588afbe6e4d13e
          - d57736aac8150a22889ce83bd52a4068
          size: normal
          timeout: 10000
          title: false
        enabled: false
      - action: browser_mod.popup
        data:
          dismissable: true
          autoclose: false
          browser_id:
          - 73abbcdb326ecda81f588afbe6e4d13e
          - d57736aac8150a22889ce83bd52a4068
          size: normal
          timeout: 7000
          title: '{{title}}'
          content:
            type: markdown
            content: '{{content}}'
    default:
    - action: browser_mod.notification
      metadata: {}
      data:
        browser_id:
        - 73abbcdb326ecda81f588afbe6e4d13e
        - d57736aac8150a22889ce83bd52a4068
        message: '{{title}}: {{ content }}'
        autoclose: false
  - choose:
    - conditions:
      - condition: template
        value_template: '{{show_popup}}'
      sequence:
      - action: timer.start
        metadata: {}
        data:
          duration: 00:00:03
        target:
          entity_id: timer.show_notification
        enabled: false
      - action: browser_mod.popup
        data:
          dismissable: true
          autoclose: false
          content:
            type: custom:home-feed-card
            more_info_on_tap: true
            show_empty: false
            show_notification_title: false
            show_icons: false
            id_filter: ^..*
            compact_mode: true
            max_item_count: 1
          browser_id:
          - 73abbcdb326ecda81f588afbe6e4d13e
          - d57736aac8150a22889ce83bd52a4068
          size: normal
          timeout: 10000
          title: '{{title}}'
        enabled: true
      - action: browser_mod.popup
        data:
          dismissable: true
          autoclose: false
          browser_id:
          - 73abbcdb326ecda81f588afbe6e4d13e
          - d57736aac8150a22889ce83bd52a4068
          size: normal
          timeout: 7000
          title: '{{title}}'
          content:
            type: markdown
            content: '{{content}}'
  fields:
    duration:
      selector:
        duration: {}
      default:
        hours: 0
        minutes: 0
        seconds: 3
    silent:
      selector:
        boolean: {}
      default: false
    title:
      selector:
        text: {}
    content:
      description: Required
      required: true
      selector:
        text: {}
    id:
      selector:
        text:
          prefix: id_
    play_sound:
      selector:
        boolean: {}
      default: false
      name: Play Notification Sound
      required: true
    show_popup:
      selector:
        boolean: {}
      name: Popup
      default: true
      required: true
    persistent:
      selector:
        boolean: {}
      default: true
    desktop:
      selector:
        boolean: {}
  description: Script to create a notification with optional timer and silence mode
toggle_playback:
  alias: LUCY-PC - Set Playback Device
  sequence:
  - if:
    - condition: template
      value_template: '{{is_state(''sensor.default_audio_device_short_name'',''Speakers'')}}'
    then:
    - action: button.press
      metadata: {}
      data: {}
      target:
        entity_id: button.lucy_pc_setheadsetdefault
    else:
    - action: button.press
      metadata: {}
      data: {}
      target:
        entity_id: button.lucy_pc_setspeakersdefault
  description: ''
standby_wake_pc:
  alias: Standby/Wake PC
  sequence:
  - if:
    - condition: template
      value_template: '{{is_state(''sensor.lucy_pc_powerstate'',''True'')}}'
    then:
    - action: button.press
      target:
        entity_id: button.lucy_pc_standby
      data: {}
    else:
    - action: button.press
      data: {}
      target:
        entity_id: button.lucy_pc_resume
  description: ''
navigation:
  alias: Navigation
  sequence:
  - variables:
      entity: 'sensor.{{menu}}_nav

        '
  - action: variable.update_sensor
    metadata: {}
    data:
      replace_attributes: false
      value: '{{active_tab}}'
    target:
      entity_id: sensor.misc_nav
  fields:
    active_tab:
      selector:
        text:
      name: active_tab
      required: true
    menu:
      selector:
        text:
      name: menu
      required: true
  description: ''
timer:
  alias: Kitchen Timer
  sequence:
  - action: timer.start
    metadata: {}
    data:
      duration: '{% set total_seconds = states(''input_number.timer_duration'') |
        int %} {% set hours = total_seconds // 3600 %} {% set minutes = (total_seconds
        % 3600) // 60 %} {% set seconds = total_seconds % 60 %} {{ ''%02d:%02d:%02d''
        | format(hours, minutes, seconds) }}

        '
    target:
      entity_id: timer.kitchen_timer
  fields: {}
  description: ''
  icon: mdi:timer
state_save:
  alias: State Save
  sequence:
  - variables:
      is_debug: false
      lights: "{{ expand('light.group_lucy')\n   | map(attribute='entity_id')\n   |
        list }}\n"
      entity: '{{ entity if entity is defined else ''binary_sensor.lights_previous''}}'
      scenes: "{{ states.input_boolean \n   | selectattr('entity_id', 'search', '^input_boolean.scene_')\n
        \  | map(attribute='entity_id')\n   | list }}\n"
  - action: counter.reset
    target:
      entity_id:
      - counter.state_changes
    data: {}
    enabled: true
  - repeat:
      for_each: '{{ lights }}'
      sequence:
      - alias: Save State
        if:
        - condition: template
          value_template: '{{ state_attr(entity, repeat.item) == None or state_attr(entity,
            repeat.item) != states(repeat.item) }}'
        then:
        - action: variable.update_sensor
          data:
            attributes:
              '{{ repeat.item }}': '{{ states(repeat.item) }}'
          target:
            entity_id: '{{ entity }}'
        - action: counter.increment
          metadata: {}
          data: {}
          target:
            entity_id: counter.state_changes
        - if:
          - condition: template
            value_template: '{{is_debug}}'
          then:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: Successfully updated {{ repeat.item }} {{ states(repeat.item)
                }} attributes of {{ entity }}.
              title: State Save
          alias: Debug
      - alias: Save Brightness
        if:
        - condition: template
          value_template: '{{ state_attr(repeat.item, ''brightness'') != None and
            state_attr(entity, repeat.item~".brightness") != state_attr(repeat.item,
            ''brightness'')}}'
        then:
        - action: variable.update_sensor
          data:
            attributes:
              '{{ repeat.item }}.brightness': '{{ state_attr(repeat.item,''brightness'')
                }}'
          target:
            entity_id: '{{ entity }}'
        - action: counter.increment
          metadata: {}
          data: {}
          target:
            entity_id: counter.state_changes
        - if:
          - condition: template
            value_template: '{{is_debug}}'
          then:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: Successfully updated {{ repeat.item }} {{ states(repeat.item)
                }} attributes of {{ entity }}.
              title: State Save
          alias: Debug
      - alias: Save Effect
        if:
        - condition: template
          value_template: '{{ state_attr(repeat.item, ''effect'') != None and state_attr(entity,
            repeat.item~".effect") != state_attr(repeat.item, ''effect'')}}'
        then:
        - action: variable.update_sensor
          data:
            attributes:
              '{{ repeat.item }}.effect': '{{ state_attr(repeat.item,''effect'') }}'
          target:
            entity_id: '{{ entity }}'
        - action: counter.increment
          metadata: {}
          data: {}
          target:
            entity_id: counter.state_changes
        - if:
          - condition: template
            value_template: '{{is_debug}}'
          then:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: Successfully updated {{ repeat.item }} {{ states(repeat.item)
                }} attributes of {{ entity }}.
              title: State Save
          alias: Debug
      - alias: Save color mode
        if:
        - condition: template
          value_template: '{{ state_attr(repeat.item, ''color_mode'') != None and
            state_attr(entity, repeat.item~".color_mode") != state_attr(repeat.item,
            ''color_mode'')}}'
        then:
        - action: variable.update_sensor
          data:
            attributes:
              '{{ repeat.item }}.color_mode': '{{ state_attr(repeat.item,''color_mode'')
                }}'
          target:
            entity_id: '{{ entity }}'
        - action: counter.increment
          metadata: {}
          data: {}
          target:
            entity_id: counter.state_changes
        - if:
          - condition: template
            value_template: '{{is_debug}}'
          then:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: Successfully updated {{ repeat.item }} {{ states(repeat.item)
                }} attributes of {{ entity }}.
              title: State Save
          alias: Debug
    enabled: true
  - repeat:
      for_each: '{{ scenes }}'
      sequence:
      - alias: Save State
        if:
        - condition: template
          value_template: '{{ state_attr(entity, repeat.item) == None or state_attr(entity,
            repeat.item) != states(repeat.item) }}'
        then:
        - action: variable.update_sensor
          data:
            attributes:
              '{{ repeat.item }}': '{{ states(repeat.item) }}'
          target:
            entity_id: '{{ entity }}'
        - action: counter.increment
          metadata: {}
          data: {}
          target:
            entity_id: counter.state_changes
        - if:
          - condition: template
            value_template: '{{is_debug}}'
          then:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: Successfully updated {{ repeat.item }} {{ states(repeat.item)
                }} attributes of {{ entity }}.
              title: State Save
          alias: Debug
    enabled: true
  - action: variable.update_sensor
    data:
      attributes:
        select.wled_live_override: '{{ states(''select.wled_live_override'') }}'
    target:
      entity_id: '{{ entity }}'
  - action: counter.increment
    metadata: {}
    data: {}
    target:
      entity_id: counter.state_changes
  - if:
    - condition: template
      value_template: '{{is_debug}}'
    then:
    - choose:
      - conditions:
        - condition: numeric_state
          entity_id: counter.state_changes
          below: 1
        sequence:
        - action: persistent_notification.create
          metadata: {}
          data:
            message: No changed detected.
            title: State Change
            notification_id: state_change
      default:
      - action: persistent_notification.create
        metadata: {}
        data:
          message: Successfully updated {{ states('counter.state_changes') }} attributes
            of {{ entity }}.
          title: State Save
          notification_id: state_change
    alias: Debug notify
  fields:
    entity:
      selector:
        entity: {}
      required: true
      default: sensor.scene_previous
  description: ''
  icon: mdi:content-save-check
state_restore:
  alias: State Restore
  sequence:
  - variables:
      is_debug: false
      lights: "{{ expand('light.group_lucy')\n   | map(attribute='entity_id')\n   |
        list }}\n"
      entity: '{{ entity if entity is defined else ''binary_sensor.lights_previous''}}'
      wled: "{{ expand('light.group_lucy')\n   | selectattr('entity_id','search','^light.wled_')\n\n
        \  | map(attribute='entity_id')\n   | list }}\n"
      onoff: "{{ expand('light.group_lucy')\n   | selectattr('entity_id','search','^light.tasmota_')\n\n
        \  | map(attribute='entity_id')\n   | list }}\n"
      others: "{{ expand('light.group_lucy') \n  | rejectattr('entity_id','search','^light.tasmota_')
        \n  | rejectattr('entity_id','search','^light.wled_')\n\n  | map(attribute='entity_id')\n
        \ | list }}\n"
      scenes: "{{ states.input_boolean \n   | selectattr('entity_id', 'search', '^input_boolean.scene_')\n
        \  | map(attribute='entity_id')\n   | list }}\n"
  - action: counter.reset
    data: {}
    target:
      entity_id: counter.states_restored
  - repeat:
      for_each: '{{ lights }}'
      sequence:
      - if:
        - condition: template
          value_template: '{{ (states(repeat.item) != ''unknown'' and state_attr(entity,
            repeat.item) != states(repeat.item)) or state_attr(entity, repeat.item~".brightness")
            != state_attr(repeat.item,''brightness'')}}'
        then:
        - if:
          - condition: template
            value_template: '{{ is_debug }}'
          then:
          - action: persistent_notification.create
            data:
              message: Restored {{ repeat.item }} state to {{ state_attr(entity, repeat.item)
                }}.
              title: State Restore
          alias: Debug
        - if:
          - condition: template
            value_template: '{{state_attr(entity, repeat.item) == ''on'' }}'
          then:
          - choose:
            - conditions:
              - condition: template
                value_template: '{{state_attr(entity, repeat.item~".brightness") !=
                  None }}'
              sequence:
              - action: light.turn_on
                metadata: {}
                data:
                  transition: 12
                  brightness: '{{ state_attr(entity, repeat.item~''.brightness'')
                    | int }}'
                target:
                  entity_id: '{{repeat.item}}'
              - if:
                - condition: template
                  value_template: '{{repeat.item == ''light.hexagon_2'' and state_attr(entity,
                    ''light.hexagon_2.effect'') != states(''input_select.hexagon_effects'')}}'
                then:
                - action: input_select.select_option
                  target:
                    entity_id:
                    - input_select.hexagon_effects
                  data:
                    option: '{{state_attr(entity, repeat.item~''.effect'')}}'
              - action: counter.increment
                target:
                  entity_id:
                  - counter.states_restored
                data: {}
            default:
            - action: light.turn_on
              metadata: {}
              data:
                transition: 8
              target:
                entity_id: '{{repeat.item}}'
            enabled: false
          - choose:
            - conditions:
              - condition: template
                value_template: '{{repeat.item in wled or repeat.item in others}}'
              sequence:
              - action: light.turn_on
                metadata: {}
                data:
                  transition: 3
                  brightness: '{{ state_attr(entity, repeat.item~''.brightness'')
                    | int }}'
                target:
                  entity_id: '{{repeat.item}}'
              - action: counter.increment
                target:
                  entity_id:
                  - counter.states_restored
                data: {}
              - if:
                - condition: template
                  value_template: '{{state_attr(entity, repeat.item) == ''on'' }}'
                then: []
            - conditions:
              - condition: template
                value_template: '{{repeat.item in onoff}}'
              sequence:
              - action: light.turn_on
                metadata: {}
                data: {}
                target:
                  entity_id: '{{repeat.item}}'
              - action: counter.increment
                target:
                  entity_id:
                  - counter.states_restored
                data: {}
          else:
          - action: light.turn_off
            metadata: {}
            data:
              transition: 7
            target:
              entity_id: '{{repeat.item}}'
          - action: counter.increment
            target:
              entity_id:
              - counter.states_restored
            data: {}
  - repeat:
      for_each: '{{ scenes }}'
      sequence:
      - if:
        - condition: template
          value_template: '{{ (states(repeat.item) != ''unknown'' and state_attr(entity,
            repeat.item) != states(repeat.item))}}'
        then:
        - if:
          - condition: template
            value_template: '{{ is_debug }}'
          then:
          - action: persistent_notification.create
            data:
              message: Restored {{ repeat.item }} state to {{ state_attr(entity, repeat.item)
                }}.
              title: State Restore
          alias: Debug
        - if:
          - condition: template
            value_template: '{{state_attr(entity, repeat.item) == ''on'' }}'
          then:
          - action: input_boolean.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: '{{repeat.item}}'
          - action: counter.increment
            target:
              entity_id:
              - counter.states_restored
            data: {}
          else:
          - action: counter.increment
            target:
              entity_id:
              - counter.states_restored
            data: {}
          - action: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: '{{repeat.item}}'
  - action: select.select_option
    metadata: {}
    data:
      option: '{{state_attr(entity, ''select.wled_live_override'')}}'
    target:
      entity_id: select.wled_live_override
  - if:
    - condition: template
      value_template: '{{is_debug}}'
    then:
    - variables:
        msg: '{{ "No changes detected." if states(''counter.states_restored'') ==
          0 else "Restored "+states(''counter.states_restored'')+" attributes from
          "+entity }}'
    - action: script.notify
      metadata: {}
      data:
        duration:
          hours: 0
          minutes: 0
          seconds: 3
        silent: false
        play_sound: false
        show_popup: false
        content: '{{msg}}'
        title: State Restore
  fields:
    entity:
      selector:
        entity: {}
      default: sensor.scene_previous
      required: true
  description: ''
custom_wled_preset:
  alias: Set Preset - WLED
  sequence:
  - variables:
      desktop_state: '{{ is_state(''light.wled_desktop'',''on'') | lower() }}'
      desktop_brightness: '{{ (state_attr(''light.wled_desktop'', ''brightness'')|int)
        if is_state(''light.wled_desktop'', ''on'') else 0 }}'
      bed_state: '{{ is_state(''light.wled_bed'',''on'') | lower() }}'
      bed_brightness: '{{ (state_attr(''light.wled_bed'', ''brightness'')|int) if
        is_state(''light.wled_bed'', ''on'') else 0 }}'
      ghost_state: '{{ is_state(''light.wled_ghost'',''on'') | lower() }}'
      ghost_brightness: '{{ (state_attr(''light.wled_ghost'', ''brightness'')|int)
        if is_state(''light.wled_ghost'', ''on'') else 0 }}'
      umbreon_state: '{{ is_state(''light.wled_umbreon'',''on'') | lower() }}'
      umbreon_brightness: '{{ (state_attr(''light.wled_umbreon'', ''brightness'')|int)
        if is_state(''light.wled_umbreon'', ''on'') else 0 }}'
      tv_state: '{{ is_state(''light.wled_tv'',''on'') | lower() }}'
      tv_brightness: '{{ (state_attr(''light.wled_tv'', ''brightness'')|int) if is_state(''light.wled_tv'',
        ''on'') else 0 }}'
      ceiling_state: '{{ is_state(''light.wled_ceiling'',''on'') | lower() }}'
      ceiling_brightness: '{{ (state_attr(''light.wled_ceiling'', ''brightness'')|int)
        if is_state(''light.wled_ceiling'', ''on'') else 0 }}'
  - alias: Set Default Segment Bounds
    action: rest_command.wled_api
    metadata: {}
    data:
      payload: "{\n  \"mainseg\": 5,\n  \"seg\": [\n    {\"id\": 6, \"start\": 217,
        \"stop\": 266, \"grp\": 2, \"frz\": false, \"n\": \"Games Room - Vitrine\"},\n
        \   {\"id\": 7, \"start\": 266, \"stop\": 282, \"grp\": 2, \"frz\": false,
        \"n\": \"Games Room - Moon\"},\n    {\"id\": 0, \"start\": 0, \"stop\": 46,
        \"grp\": 1, \"frz\": false, \"n\": \"Desktop\"},\n    {\"id\": 1, \"start\":
        46, \"stop\": 57, \"grp\": 1, \"frz\": false, \"n\": \"Umbreon\"},\n    {\"id\":
        2, \"start\": 57, \"stop\": 125, \"grp\": 1, \"frz\": false, \"n\": \"Ceiling\"},\n
        \   {\"id\": 3, \"start\": 125, \"stop\": 151, \"grp\": 1, \"frz\": false,
        \"n\": \"TV\"},\n    {\"id\": 4, \"start\": 151, \"stop\": 158, \"grp\": 1,
        \"frz\": false, \"n\": \"Ghost\"},\n    {\"id\": 5, \"start\": 158, \"stop\":
        217, \"grp\": 1, \"frz\": false, \"n\": \"Bed\"}\n  ]\n}"
    response_variable: response
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - choose:
    - conditions:
      - condition: template
        value_template: '{{preset ==''Pink Noise''}}'
      sequence:
      - action: rest_command.wled_api
        data:
          payload: "{\n    \"mainseg\": 5,\n    \"seg\": [\n      {\"id\": 0,\"on\":
            {{ desktop_state }}, \"bri\": {{ desktop_brightness }}, \"n\": \"Desktop\",
            \"col\": [[96, 45, 205], [132, 41, 123], [190, 0, 54]], \"fx\": 27, \"sx\":
            9, \"ix\": 63, \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\":
            false, \"rev\": false, \"mi\": false},\n      {\"id\": 1, \"on\": {{ umbreon_state
            }}, \"bri\": {{ umbreon_brightness }}, \"n\": \"Umbreon\", \"col\": [[96,
            45, 205], [132, 41, 123], [190, 0, 54]], \"fx\": 107, \"sx\": 9, \"ix\":
            63, \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false,
            \"rev\": false, \"mi\": true},\n      {\"id\": 2, \"on\": {{ ceiling_state
            }}, \"bri\": {{ ceiling_brightness }}, \"n\": \"Ceiling\", \"col\": [[96,
            45, 205], [132, 41, 123], [190, 0, 54]], \"fx\": 107, \"sx\": 9, \"ix\":
            63, \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false,
            \"rev\": false, \"mi\": true},\n      {\"id\": 3, \"on\": {{ tv_state
            }}, \"bri\": {{ tv_brightness }}, \"n\": \"TV\", \"col\": [[96, 45, 205],
            [132, 41, 123], [190, 0, 54]], \"fx\": 107, \"sx\": 9, \"ix\": 63, \"pal\":
            4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false, \"rev\": false,
            \"mi\": true},\n      {\"id\": 4, \"on\": {{ ghost_state }}, \"bri\":
            {{ ghost_brightness }}, \"n\": \"Ghost\", \"col\": [[96, 45, 205], [132,
            41, 123], [190, 0, 54]], \"fx\": 107, \"sx\": 9, \"ix\": 63, \"pal\":
            4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false, \"rev\": false,
            \"mi\": true},\n      {\"id\": 5, \"on\": {{ bed_state }}, \"bri\": {{
            bed_brightness }}, \"n\": \"Bed\", \"col\": [[96, 45, 205], [132, 41,
            123], [190, 0, 54]], \"fx\": 107, \"sx\": 9, \"ix\": 63, \"pal\": 4, \"c1\":
            128, \"c2\": 128, \"c3\": 16, \"sel\": false, \"rev\": false, \"mi\":
            true}\n    ],\n    \"n\": \"Pink Noise\"\n}"
        response_variable: response
      alias: Pink Noise
    - conditions:
      - condition: template
        value_template: '{{preset ==''Pink Noise 2''}}'
      sequence:
      - action: rest_command.wled_api
        data:
          payload: "{\n      \"mainseg\": 5,\n      \"seg\": [\n        { \"id\":
            0,  \"on\": {{ desktop_state }}, \"bri\": {{ desktop_brightness }}, \"n\":
            \"Desktop\", \"col\": [[96, 45, 205], [132, 41, 123], [190, 0, 54]], \"fx\":
            27, \"sx\": 9, \"ix\": 63, \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\":
            16, \"sel\": false, \"rev\": false, \"mi\": false},\n        { \"id\":
            1, \"on\": {{ umbreon_state }}, \"bri\": {{ umbreon_brightness }}, \"n\":
            \"Umbreon\", \"col\": [[96, 45, 205], [132, 41, 123], [190, 0, 54]], \"fx\":
            107, \"sx\": 9, \"ix\": 63, \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\":
            16, \"sel\": false, \"rev\": false, \"mi\": true},\n        { \"id\":
            2, \"on\": {{ ceiling_state }}, \"bri\": {{ ceiling_brightness }}, \"n\":
            \"Ceiling\", \"col\": [[96, 45, 205], [132, 41, 123], [190, 0, 54]], \"fx\":
            107, \"sx\": 9, \"ix\": 63, \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\":
            16, \"sel\": false, \"rev\": false, \"mi\": true},\n        { \"id\":
            3, \"on\": {{ tv_state }}, \"bri\": {{ tv_brightness }}, \"n\": \"TV\",
            \"col\": [[96, 45, 205], [132, 41, 123], [190, 0, 54]], \"fx\": 107, \"sx\":
            9, \"ix\": 63, \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\":
            false, \"rev\": false, \"mi\": true},\n        { \"id\": 4, \"on\": {{
            ghost_state }}, \"bri\": {{ ghost_brightness }}, \"n\": \"Ghost\", \"col\":
            [[255, 0, 255], [144, 0, 255], [0, 0, 0]], \"fx\": 27, \"sx\": 9, \"ix\":
            63, \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false,
            \"rev\": false, \"mi\": true},\n        { \"id\": 5, \"on\": {{ bed_state
            }}, \"bri\": {{ bed_brightness }}, \"n\": \"Bed\", \"col\": [[96, 45,
            205], [132, 41, 123], [190, 0, 54]], \"fx\": 107, \"sx\": 9, \"ix\": 63,
            \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false, \"rev\":
            false, \"mi\": true}\n      ],\n      \"n\": \"Pink Noise 2\"\n}"
        response_variable: response
      alias: Pink Noise
    - conditions:
      - condition: template
        value_template: '{{preset == ''Mint Shock''}}'
      sequence:
      - action: rest_command.wled_api
        data:
          payload: "{\n    \"mainseg\": 5,\n    \"seg\": [\n      {\"id\": 0, \"on\":
            {{ desktop_state }}, \"bri\": {{ desktop_brightness }}, \"n\": \"Desktop\",
            \"col\": [[153, 0, 255], [132, 41, 123], [190, 0, 54]], \"fx\": 110, \"sx\":
            166, \"ix\": 255, \"pal\": 255, \"c1\": 128, \"c2\": 128, \"c3\": 16,
            \"sel\": false, \"rev\": true, \"mi\": false},\n      {\"id\": 1, \"on\":
            {{ umbreon_state }}, \"bri\": {{ umbreon_brightness }}, \"n\": \"Umbreon\",
            \"col\": [[0, 255, 200], [166, 0, 255], [190, 0, 54]], \"fx\": 76, \"sx\":
            99, \"ix\": 207, \"pal\": 3, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\":
            false, \"rev\": false, \"mi\": true},\n      {\"id\": 2, \"on\": {{ ceiling_state
            }}, \"bri\": {{ ceiling_brightness }}, \"n\": \"Ceiling\", \"col\": [[30,
            148, 234], [132, 41, 123], [190, 0, 54]], \"fx\": 110, \"sx\": 103, \"ix\":
            66, \"pal\": 255, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false,
            \"rev\": true, \"mi\": true},\n      {\"id\": 3, \"on\": {{ tv_state }},
            \"bri\": {{ tv_brightness }}, \"n\": \"TV\", \"col\": [[96, 45, 205],
            [132, 41, 123], [190, 0, 54]], \"fx\": 110, \"sx\": 81, \"ix\": 81, \"pal\":
            255, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false, \"rev\": true,
            \"mi\": true},\n      {\"id\": 4, \"on\": {{ ghost_state }}, \"bri\":
            {{ ghost_brightness }}, \"n\": \"Ghost\", \"col\": [[0, 255, 200], [144,
            0, 255], [255, 0, 255]], \"fx\": 111, \"sx\": 67, \"ix\": 23, \"pal\":
            254, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false, \"rev\": true,
            \"mi\": false},\n      {\"id\": 5, \"on\": {{ bed_state }}, \"bri\": {{
            bed_brightness }}, \"n\": \"Bed\", \"col\": [[255, 170, 0], [0, 0, 0],
            [0, 0, 0]], \"fx\": 110, \"sx\": 128, \"ix\": 128, \"pal\": 255, \"c1\":
            128, \"c2\": 128, \"c3\": 16, \"sel\": true, \"rev\": true, \"mi\": true}\n
            \   ],\n    \"n\": \"Mint Shock\"\n}"
        response_variable: response
      alias: Mint Shock
    - conditions:
      - condition: template
        value_template: '{{preset == ''Floating Foxx''}}'
      sequence:
      - action: rest_command.wled_api
        data:
          payload: "{\n  \"mainseg\": 5,\n  \"seg\": [\n    {\"id\": 0, \"on\": {{
            desktop_state }}, \"bri\": {{ desktop_brightness }}, \"n\": \"Desktop\",
            \"col\": [[148, 0, 211], [75, 0, 130], [255, 255, 255]], \"fx\": 67, \"sx\":
            9, \"ix\": 127, \"pal\": 249, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\":
            true, \"rev\": true, \"mi\": true},\n    {\"id\": 1, \"on\": {{ umbreon_state
            }}, \"bri\": {{ umbreon_brightness }}, \"n\": \"Umbreon\", \"col\": [[138,
            43, 226], [75, 0, 130], [255, 255, 255]], \"fx\": 67, \"sx\": 9, \"ix\":
            127, \"pal\": 251, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": true,
            \"rev\": true, \"mi\": true},\n    {\"id\": 2, \"on\": {{ ceiling_state
            }}, \"bri\": {{ ceiling_brightness }}, \"n\": \"Ceiling\", \"col\": [[148,
            0, 211], [75, 0, 130], [255, 255, 255]], \"fx\": 67, \"sx\": 9, \"ix\":
            127, \"pal\": 250, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": true,
            \"rev\": true, \"mi\": true},\n    {\"id\": 3, \"on\": {{ tv_state }},
            \"bri\": {{ tv_brightness }}, \"n\": \"TV\", \"col\": [[138, 43, 226],
            [75, 0, 130], [255, 255, 255]], \"fx\": 67, \"sx\": 9, \"ix\": 196, \"pal\":
            251, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": true, \"rev\": true,
            \"mi\": true},\n    {\"id\": 4, \"on\": {{ ghost_state }}, \"bri\": {{
            ghost_brightness }}, \"n\": \"Ghost\", \"col\": [[148, 0, 211], [75, 0,
            130], [255, 255, 255]], \"fx\": 67, \"sx\": 9, \"ix\": 196, \"pal\": 252,
            \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": true, \"rev\": true, \"mi\":
            true},\n    {\"id\": 5, \"on\": {{ bed_state }}, \"bri\": {{ bed_brightness
            }}, \"n\": \"Bed\", \"col\": [[138, 43, 226], [75, 0, 130], [255, 255,
            255]], \"fx\": 67, \"sx\": 9, \"ix\": 196, \"pal\": 253, \"c1\": 128,
            \"c2\": 128, \"c3\": 16, \"sel\": true, \"rev\": true, \"mi\": true}\n
            \ ],\n  \"n\": \"Floating Foxx\"\n}"
        response_variable: response
      alias: Violet Flow
    - conditions:
      - condition: template
        value_template: '{{ preset == ''Love'' }}'
      sequence:
      - action: rest_command.wled_api
        data:
          payload: "{\n  \"mainseg\": 5,\n  \"seg\": [\n    {\"id\": 0, \"on\": {{
            desktop_state }}, \"bri\": {{ desktop_brightness }}, \"n\": \"Desktop\",
            \"col\": [[96, 45, 205], [132, 41, 123], [190, 0, 54]], \"fx\": 38, \"sx\":
            9, \"ix\": 63, \"pal\": 18, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\":
            false, \"rev\": false, \"mi\": false},\n    {\"id\": 1, \"on\": {{ umbreon_state
            }}, \"bri\": {{ umbreon_brightness }}, \"n\": \"Umbreon\", \"col\": [[96,
            45, 205], [132, 41, 123], [190, 0, 54]], \"fx\": 107, \"sx\": 9, \"ix\":
            63, \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false,
            \"rev\": false, \"mi\": true},\n    {\"id\": 2, \"on\": {{ ceiling_state
            }}, \"bri\": {{ ceiling_brightness }}, \"n\": \"Ceiling\", \"col\": [[96,
            45, 205], [132, 41, 123], [190, 0, 54]], \"fx\": 107, \"sx\": 9, \"ix\":
            63, \"pal\": 4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false,
            \"rev\": true, \"mi\": true},\n    {\"id\": 3, \"on\": {{ tv_state }},
            \"bri\": {{ tv_brightness }}, \"n\": \"TV\", \"col\": [[96, 45, 205],
            [132, 41, 123], [190, 0, 54]], \"fx\": 107, \"sx\": 9, \"ix\": 63, \"pal\":
            4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false, \"rev\": false,
            \"mi\": true},\n    {\"id\": 4, \"on\": {{ ghost_state }}, \"bri\": {{
            ghost_brightness }}, \"n\": \"Ghost\", \"col\": [[0, 255, 200], [144,
            0, 255], [255, 0, 255]], \"fx\": 111, \"sx\": 128, \"ix\": 128, \"pal\":
            4, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": false, \"rev\": false,
            \"mi\": false},\n    {\"id\": 5, \"on\": {{ bed_state }}, \"bri\": {{
            bed_brightness }}, \"n\": \"Bed\", \"col\": [[255, 170, 0], [0, 0, 0],
            [0, 0, 0]], \"fx\": 107, \"sx\": 3, \"ix\": 128, \"pal\": 18, \"c1\":
            128, \"c2\": 128, \"c3\": 16, \"sel\": true, \"rev\": false, \"mi\": false}\n
            \ ],\n  \"n\": \"Love\"\n}"
        response_variable: response
      alias: Love
    - conditions:
      - condition: template
        value_template: '{{preset == ''Cosmic Flow''}}'
      sequence:
      - action: rest_command.wled_api
        data:
          payload: "{\n  \"mainseg\": 5,\n  \"seg\": [\n    {\"id\": 0, \"on\": {{
            desktop_state }}, \"bri\": {{ desktop_brightness }}, \"n\": \"Desktop\",
            \"col\": [[72, 61, 139], [75, 0, 130], [148, 0, 211]], \"fx\": 78, \"sx\":
            160, \"ix\": 145, \"pal\": 28, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\":
            true, \"rev\": false, \"mi\": true},\n    {\"id\": 1, \"on\": {{ umbreon_state
            }}, \"bri\": {{ umbreon_brightness }}, \"n\": \"Umbreon\", \"col\": [[72,
            61, 139], [75, 0, 130], [148, 0, 211]], \"fx\": 78, \"sx\": 160, \"ix\":
            145, \"pal\": 28, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": true,
            \"rev\": false, \"mi\": true},\n    {\"id\": 2, \"on\": {{ ceiling_state
            }}, \"bri\": {{ ceiling_brightness }}, \"n\": \"Ceiling\", \"col\": [[72,
            61, 139], [75, 0, 130], [148, 0, 211]], \"fx\": 78, \"sx\": 160, \"ix\":
            145, \"pal\": 28, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": true,
            \"rev\": false, \"mi\": true},\n    {\"id\": 3, \"on\": {{ tv_state }},
            \"bri\": {{ tv_brightness }}, \"n\": \"TV\", \"col\": [[72, 61, 139],
            [75, 0, 130], [148, 0, 211]], \"fx\": 78, \"sx\": 160, \"ix\": 145, \"pal\":
            28, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": true, \"rev\": false,
            \"mi\": true},\n    {\"id\": 4, \"on\": {{ ghost_state }}, \"bri\":  {{
            ghost_brightness }}, \"n\": \"Ghost\", \"col\": [[72, 61, 139], [75, 0,
            130], [148, 0, 211]], \"fx\": 78, \"sx\": 160, \"ix\": 145, \"pal\": 28,
            \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": true, \"rev\": false, \"mi\":
            true},\n    {\"id\": 5, \"on\": {{ bed_state }}, \"bri\": {{ bed_brightness
            }}, \"n\": \"Bed\", \"col\": [[72, 61, 139], [75, 0, 130], [148, 0, 211]],
            \"fx\": 78, \"sx\": 160, \"ix\": 145, \"pal\": 28, \"c1\": 128, \"c2\":
            128, \"c3\": 16, \"sel\": true, \"rev\": false, \"mi\": true}\n  ],\n
            \ \"n\": \"Cosmic Flow\"\n}"
      alias: Cosmic Flow
    - conditions:
      - condition: template
        value_template: '{{preset == ''Hyped Foxx''}}'
      sequence:
      - action: rest_command.wled_api
        data:
          payload: "{\n  \"mainseg\": 5,\n  \"seg\": [\n    {\"id\": 0, \"on\": {{
            desktop_state }}, \"bri\": {{ desktop_brightness }}, \"n\": \"Desktop\",
            \"col\": [[128, 0, 128], [153, 50, 204], [255, 255, 255]], \"fx\": 89,
            \"sx\": 110, \"ix\": 120, \"pal\": 19, \"c1\": 128, \"c2\": 128, \"c3\":
            16, \"sel\": true, \"rev\": false, \"mi\": true},\n    {\"id\": 1, \"on\":
            {{ umbreon_state }}, \"bri\": {{ umbreon_brightness }}, \"n\": \"Umbreon\",
            \"col\": [[128, 0, 128], [153, 50, 204], [255, 255, 255]], \"fx\": 89,
            \"sx\": 110, \"ix\": 120, \"pal\": 19, \"c1\": 128, \"c2\": 128, \"c3\":
            16, \"sel\": true, \"rev\": false, \"mi\": true},\n    {\"id\": 2, \"on\":
            {{ ceiling_state }}, \"bri\": {{ ceiling_brightness }}, \"n\": \"Ceiling\",
            \"col\": [[128, 0, 128], [153, 50, 204], [255, 255, 255]], \"fx\": 89,
            \"sx\": 110, \"ix\": 120, \"pal\": 19, \"c1\": 128, \"c2\": 128, \"c3\":
            16, \"sel\": true, \"rev\": false, \"mi\": true},\n    {\"id\": 3, \"on\":
            {{ tv_state }}, \"bri\": {{ tv_brightness }}, \"n\": \"TV\", \"col\":
            [[128, 0, 128], [153, 50, 204], [255, 255, 255]], \"fx\": 89, \"sx\":
            110, \"ix\": 120, \"pal\": 19, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\":
            true, \"rev\": false, \"mi\": true},\n    {\"id\": 4, \"on\": {{ ghost_state
            }}, \"bri\": {{ ghost_brightness }}, \"n\": \"Ghost\", \"col\": [[128,
            0, 128], [153, 50, 204], [255, 255, 255]], \"fx\": 89, \"sx\": 110, \"ix\":
            120, \"pal\": 19, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": true,
            \"rev\": false, \"mi\": true},\n    {\"id\": 5, \"on\": {{ bed_state }},
            \"bri\": {{ bed_brightness }}, \"n\": \"Bed\", \"col\": [[128, 0, 128],
            [153, 50, 204], [255, 255, 255]], \"fx\": 89, \"sx\": 110, \"ix\": 120,
            \"pal\": 19, \"c1\": 128, \"c2\": 128, \"c3\": 16, \"sel\": true, \"rev\":
            false, \"mi\": true}\n  ],\n  \"n\": \"Hyped Foxx\"\n}"
        response_variable: response
      alias: Hyped Foxx
    - conditions:
      - condition: template
        value_template: '{{ preset == ''Pink Bliss'' }}'
      sequence:
      - action: rest_command.wled_api
        data:
          payload: "{\n  \"mainseg\": 5,\n  \"seg\": [\n    {\"id\": 0, \"on\": {{
            desktop_state }},  \"bri\": {{ desktop_brightness }}, \"col\": [[255,
            20, 147], [255, 105, 180], [255, 182, 193]], \"fx\": 49, \"sx\": 25, \"ix\":
            128, \"pal\": 253},\n    {\"id\": 1, \"on\": {{ umbreon_state }}, \"bri\":
            {{ umbreon_brightness }},  \"col\": [[255, 20, 147], [255, 105, 180],
            [255, 182, 193]], \"fx\": 49, \"sx\": 25, \"ix\": 128, \"pal\": 253},\n
            \   {\"id\": 2, \"on\": {{ ceiling_state }}, \"bri\": {{ ceiling_brightness
            }}, \"col\": [[255, 20, 147], [255, 105, 180], [255, 182, 193]], \"fx\":
            49, \"sx\": 25, \"ix\": 128, \"pal\": 253},\n    {\"id\": 3, \"on\": {{
            tv_state }}, \"bri\": {{ tv_brightness }}, \"col\": [[255, 20, 147], [255,
            105, 180], [255, 182, 193]], \"fx\": 49, \"sx\": 25, \"ix\": 128, \"pal\":
            253},\n    {\"id\": 4, \"on\": {{ ghost_state }}, \"bri\": {{ ghost_brightness
            }}, \"col\": [[255, 20, 147], [255, 105, 180], [255, 182, 193]], \"fx\":
            49, \"sx\": 25, \"ix\": 128, \"pal\": 253},\n    {\"id\": 5, \"on\": {{
            bed_state }}, \"bri\": {{ bed_brightness }}, \"col\": [[255, 20, 147],
            [255, 105, 180], [255, 182, 193]], \"fx\": 49, \"sx\": 25, \"ix\": 128,
            \"pal\": 253}\n  ]\n}"
        response_variable: response
      alias: Pink Bliss
    - conditions:
      - condition: template
        value_template: '{{ preset == ''Running Wild'' }}'
      sequence:
      - action: rest_command.wled_api
        data:
          payload: "{\n  \"on\": true,\n  \"bri\": 255,\n  \"transition\": 5,\n  \"mainseg\":
            5,\n  \"seg\": [\n    {\"id\": 0, \"grp\": 1, \"on\": {{ desktop_state
            }}, \"bri\": {{ desktop_brightness }},\"n\": \"Desktop\", \"col\": [[72,61,139],[75,0,130],[148,0,211]],\"fx\":15,\"sx\":37,\"ix\":33,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false},\n
            \   {\"id\": 1, \"grp\": 1, \"on\": {{ umbreon_state }}, \"bri\": {{ umbreon_brightness
            }},\"n\": \"Umbreon\", \"col\": [[72,61,139],[75,0,130],[148,0,211]],\"fx\":15,\"sx\":37,\"ix\":33,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false},\n
            \   {\"id\": 2, \"grp\": 1, \"on\": {{ ceiling_state }}, \"bri\": {{ ceiling_brightness
            }},\"n\": \"Ceiling\", \"col\": [[72,61,139],[75,0,130],[148,0,211]],\"fx\":15,\"sx\":37,\"ix\":33,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false},\n
            \   {\"id\": 3, \"grp\": 1, \"on\": {{ tv_state }}, \"bri\": {{ tv_brightness
            }},\"n\": \"TV\", \"col\": [[72,61,139],[75,0,130],[148,0,211]],\"fx\":15,\"sx\":37,\"ix\":33,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false},\n
            \   {\"id\": 4, \"grp\": 1, \"on\": {{ ghost_state }}, \"bri\": {{ ghost_brightness
            }},\"n\": \"Ghost\", \"col\": [[72,61,139],[75,0,130],[148,0,211]],\"fx\":15,\"sx\":37,\"ix\":33,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false},\n
            \   {\"id\": 5, \"grp\": 1, \"on\": {{ bed_state }}, \"bri\": {{ bed_brightness
            }},\"n\": \"Bed\", \"col\": [[72,61,139],[75,0,130],[148,0,211]],\"fx\":15,\"sx\":37,\"ix\":33,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false}\n
            \ ]\n}"
        response_variable: response
      alias: Running Wild
    - conditions:
      - condition: template
        value_template: '{{ preset == ''Fairy Forest'' }}'
      sequence:
      - action: rest_command.wled_api
        data:
          payload: "{\n  \"on\": true,\n  \"bri\": 255,\n  \"transition\": 5,\n  \"mainseg\":
            5,\n  \"seg\": [\n    {\"id\":0,\"grp\":2,\"on\": {{ desktop_state }},
            \"bri\": {{ desktop_brightness }},\"n\":\"Desktop\",\"col\":[[255,20,147],[255,105,180],[255,182,193]],\"fx\":49,\"sx\":25,\"ix\":128,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false},\n
            \   {\"id\":1,\"grp\":1,\"on\": {{ umbreon_state }}, \"bri\": {{ umbreon_brightness
            }},\"n\":\"Umbreon\",\"col\":[[255,20,147],[255,105,180],[255,182,193]],\"fx\":49,\"sx\":25,\"ix\":128,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false},\n
            \   {\"id\":2,\"grp\":2,\"on\": {{ ceiling_state }}, \"bri\": {{ ceiling_brightness
            }},\"n\":\"Ceiling\",\"col\":[[255,20,147],[255,105,180],[255,182,193]],\"fx\":49,\"sx\":25,\"ix\":128,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false},\n
            \   {\"id\":3,\"grp\":2,\"on\": {{ tv_state }}, \"bri\": {{ tv_brightness
            }},\"n\":\"TV\",\"col\":[[255,20,147],[255,105,180],[255,182,193]],\"fx\":49,\"sx\":25,\"ix\":128,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":false,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false},\n
            \   {\"id\":4,\"grp\":1,\"on\": {{ ghost_state }}, \"bri\": {{ ghost_brightness
            }},\"n\":\"Ghost\",\"col\":[[255,20,147],[255,105,180],[255,182,193]],\"fx\":49,\"sx\":25,\"ix\":128,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":false,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false},\n
            \   {\"id\":5,\"grp\":1,\"on\": {{ bed_state }}, \"bri\": {{ bed_brightness
            }},\"n\":\"Bed\",\"col\":[[255,20,147],[255,105,180],[255,182,193]],\"fx\":49,\"sx\":25,\"ix\":128,\"pal\":253,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":false,\"rev\":false,\"mi\":true,\"o1\":false,\"o2\":false,\"o3\":false}\n
            \ ]\n }"
        response_variable: response
      alias: Fairy Forest
  - action: script.notify
    metadata: {}
    data:
      duration:
        hours: 0
        minutes: 0
        seconds: 3
      silent: false
      play_sound: false
      show_popup: false
      content: 'Response: {{response}}'
      title: Activated {{preset}}
      id: wled_preset
    enabled: false
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - action: input_select.select_first
    data: {}
    target:
      entity_id: input_select.presets_wled
    enabled: false
  - action: rest_command.wled_api
    metadata: {}
    data:
      payload: "{\n  \"mainseg\": 5,\n  \"seg\": [\n\n    {\"id\": 3, \"start\": 125,
        \"stop\": 0},\n    {\"id\": 6, \"start\": 125, \"stop\": 150, \"grp\": 1,
        \"frz\": false, \"n\": \"TV_progress_left\"},\n    {\"id\": 7, \"start\":
        150, \"stop\": 151, \"grp\": 1, \"frz\": false, \"n\": \"TV_progress_done\"}\n\n
        \ ]\n}"
    response_variable: response
    alias: Set Progress Bar Bounds
    enabled: false
  - action: variable.update_binary_sensor
    metadata: {}
    data:
      replace_attributes: false
      attributes:
        latest_wled_preset: '{{preset}}'
    target:
      entity_id: binary_sensor.lights_previous
  description: ''
  fields:
    preset:
      selector:
        text:
      required: true
automatic_lights_fading:
  alias: Automatic Lights Fading
  sequence:
  - variables:
      lights: "{{ expand('light.group_lucy')\n   | selectattr('attributes.color_mode',
        'in', ['hs', 'rgb', 'xy', 'color_temp'])\n   | selectattr('state', 'eq', 'on')\n
        \  | map(attribute='entity_id')\n   | list }}\n"
  - if:
    - condition: template
      value_template: '{{is_state(''input_boolean.external_brightness_change'',''off'')
        }}'
    then:
    - repeat:
        sequence:
        - data:
            lampBrightnessScale: zeroToTwoFiftyFive
            easingTypeInput: auto
            endBrightnessPercent: 50
            endBrightnessEntityScale: zeroToTwoFiftyFive
            shouldStopIfTheLampIsTurnedOffDuringTheFade: true
            shouldResetTheStopEntityToOffAtStart: false
            shouldInvertTheValueOfTheStopEntity: false
            minimumStepDelayInMilliseconds: 100
            shouldTryToUseNativeLampTransitionsToo: false
            isDebugMode: false
            endBrightnessEntity: input_number.fade_target
            transitionTime:
              hours: 0
              minutes: 0
              seconds: 2
            light: '{{ repeat.item }}'
          action: script.ashley_s_light_fader
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 500
        for_each: '{{ lights }}'
  description: ''
update_fader_value:
  alias: External Brightness Change
  sequence:
  - action: input_boolean.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.external_brightness_change
  - action: input_number.set_value
    metadata: {}
    data:
      value: '{{(state_attr(''light.real_light_entities'',''brightness''))|round(0)|int}}'
    target:
      entity_id: input_number.fade_target
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - action: input_boolean.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.external_brightness_change
  description: ''
archive_package:
  alias: Archive Delivered Packages
  sequence:
  - variables:
      tracking_no: '{{states(''input_text.tracking_number'')}}'
  - action: seventeentrack.archive_package
    metadata: {}
    data:
      config_entry_id: 01JA545FB4S1WQCDDC2RZ5W63V
      package_tracking_number: '{{ tracking_no }}'
  - action: input_text.set_value
    metadata: {}
    data:
      value: ''
    target:
      entity_id: input_text.tracking_number
  - delay:
      hours: 0
      minutes: 45
      seconds: 0
      milliseconds: 0
  - if:
    - condition: template
      value_template: '{{states.sensor[''17track_delivered''].attributes.packages
        | length >0}}'
    then:
    - variables:
        package: '{{states.sensor[''17track_delivered''].attributes.packages[0].tracking_number}}'
    - action: input_text.set_value
      metadata: {}
      data:
        value: '{{ package }}'
      target:
        entity_id: input_text.tracking_number
  mode: single
  description: ''
generate_unique_id:
  alias: Generate Unique ID
  sequence:
  - action: persistent_notification.create
    data:
      message: '{{ "unique_id: "+(range(10000,99999)|random|string) +"-"+(range(10000,99999)|random|string)+"-"+(range(10000,99999)|random|string)+"-"+(range(10000,99999)|random|string)+"-"+(range(10000,99999)|random|string)}}

        '
      title: Generated Unique Identifier
      notification_id: guid_gen
  description: ''
lucy_ceiling_control_segments:
  alias: Lucy Ceiling Control
  sequence:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{setmode==''temp''}}'
      sequence:
      - action: light.turn_on
        metadata: {}
        data:
          kelvin: 4300
        target:
          entity_id: light.lucy_ceiling
    - conditions:
      - condition: template
        value_template: '{{setmode==''rgb''}}'
      sequence:
      - action: light.turn_on
        metadata: {}
        data:
          rgb_color:
          - 115
          - 6
          - 224
        target:
          entity_id: light.lucy_ceiling
    default:
    - if:
      - condition: template
        value_template: '{{ brightness is defined }}'
      then:
      - action: rest_command.govee_api_post
        data:
          payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"device\":
            \"0A:B2:D0:C9:07:62:51:EA\",\n    \"sku\": \"H60A1\",\n    \"capability\":
            {\n      \"type\": \"devices.capabilities.segment_color_setting\",\n      \"instance\":
            \"segmentedBrightness\",\n      \"value\": {\n        \"segment\": {{
            segments }},\n        \"brightness\": {{ brightness }}\n      }\n    }\n
            \ }\n}  \n"
        response_variable: response
    - if:
      - condition: template
        value_template: '{{ color is defined }}'
      then:
      - action: script.notify
        metadata: {}
        data:
          duration:
            hours: 0
            minutes: 0
            seconds: 3
          silent: false
          play_sound: false
          show_popup: false
          persistent: true
          content: '{% set color= [122,122,122] %} {{"Applying color "+ ((color[0]
            * 65536 + color[1] * 256 + color[2])) | string + " / rgb("+(color[0]|string)+","+(color[1]|string)+
            ","+(color[2]|string)+")" }}

            '
      - action: rest_command.govee_api_post
        data:
          payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"device\":
            \"0A:B2:D0:C9:07:62:51:EA\",\n    \"sku\": \"H60A1\",\n    \"capability\":
            {\n      \"type\": \"devices.capabilities.segment_color_setting\",\n      \"instance\":
            \"segmentedColorRgb\",\n      \"value\": {\n        \"segment\": {{ segments
            }},\n        \"rgb\": {{ (color[0] * 65536 + color[1] * 256 + color[2])
            | int }}\n      }\n    }\n  }\n}  \n"
        response_variable: response
      - action: script.notify
        metadata: {}
        data:
          duration:
            hours: 0
            minutes: 0
            seconds: 3
          silent: false
          play_sound: false
          show_popup: false
          persistent: true
          content: "Result:  {{ response }} \n"
  description: ''
  fields:
    color:
      selector:
        color_rgb: {}
      default:
      - 88
      - 30
      - 194
      required: false
    segments:
      selector:
        object: {}
      default:
      - 0
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      - 10
      - 11
      - 12
      required: true
    brightness:
      selector:
        number:
          min: 1
          max: 100
          step: 1
    setmode:
      selector:
        text:
      name: setmode
lucy_ceiling_gradient_effect:
  alias: Set Preset - Ceiling
  sequence:
  - variables:
      value: "{% set id= 1614324 %} {% if preset==\"Hyped Foxx\"%}\n  {% set id= 1581259
        %}\n{% endif %} {{id|int}}\n"
  - action: rest_command.govee_api_post
    data:
      payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\": \"H60A1\",\n
        \   \"device\": \"0A:B2:D0:C9:07:62:51:EA\",\n    \"capability\": {\n      \"type\":
        \"devices.capabilities.dynamic_scene\",\n      \"instance\": \"snapshot\",\n
        \     \"value\": {{value|int}}\n    }\n  }\n}"
    response_variable: response
  - variables:
      status: '{{ true if response.status == 200 else false}}'
      returned_value: '{{ (preset if status == true and response.content.capability.value
        == value)|default(''n/a'') }}'
  - delay:
      seconds: 1
  - action: script.notify
    data:
      title: 'Ceiling Preset: {{ preset }} {{ value }}'
      content: 'Status: {{ status }}, Value: {{ returned_value }}'
  - action: input_select.select_first
    target:
      entity_id: input_select.presets_ceiling
    data: {}
  - action: variable.update_sensor
    metadata: {}
    data:
      replace_attributes: false
      value: '{{returned_value}}'
      attributes:
        value: '{{value}}'
        last_updated: '{{now()|string}}

          '
    target:
      entity_id: sensor.lucy_ceiling_active_preset
  mode: single
  fields:
    preset:
      selector:
        text:
      name: preset
      default: Cosmic Dream
      required: true
send_govee_scenes_requests:
  alias: Send Govee Scenes Requests
  sequence:
  - data:
      payload: "{\n  \"requestId\": \"uuid1\",\n  \"payload\": {\n      \"sku\": \"H60A1\",\n
        \     \"device\": \"0A:B2:D0:C9:07:62:51:EA\"\n  }\n}\n"
    action: rest_command.govee_api_post
    response_variable: response
  - action: script.notify
    metadata: {}
    data:
      duration:
        hours: 0
        minutes: 0
        seconds: 3
      silent: false
      play_sound: false
      show_popup: false
      persistent: true
      content: '{{response}}'
      title: API Requests
  - delay: 00:00:01
  - data:
      payload: "{\n  \"requestId\": \"uuid2\",\n  \"payload\": {\n      \"sku\": \"H600D\",\n
        \     \"device\": \"0C:0F:E8:06:90:06:3F:4C\"\n  }\n}\n"
    action: rest_command.govee_api_post
    response_variable: response
  - action: script.notify
    metadata: {}
    data:
      duration:
        hours: 0
        minutes: 0
        seconds: 3
      silent: false
      play_sound: false
      show_popup: false
      persistent: true
      content: '{{response}}'
      title: API Requests
  description: ''
set_preset_hexagon:
  alias: Set Preset - Hexagon
  sequence:
  - variables:
      preset: '{{states(''input_select.presets_hexagon'')}}'
  - if:
    - condition: template
      value_template: '{{preset == "Dancin'' Foxx"}}'
    then:
    - action: variable.update_binary_sensor
      metadata: {}
      data:
        attributes:
          light.hexagon_2_brightness: '{{state_attr(''light.hexagon_2'',''brightness'')}}'
          light.hexagon_2_effect: '{{ iif(state_attr(''light.hexagon_2'',''effect''),
            state_attr(''light.hexagon_2'',''effect''), state_attr(''binary_sensor.lights_previous'',''light.hexagon_2_effect''))
            }}'
      target:
        entity_id: binary_sensor.lights_previous
    - action: scene.turn_on
      metadata: {}
      target:
        entity_id: scene.govee_to_mqtt_one_click_default_dancing_foxx
    - delay:
        hours: 0
        minutes: 0
        seconds: 1
        milliseconds: 0
    - action: light.turn_on
      metadata: {}
      data:
        brightness: '{{state_attr(''binary_sensor.lights_previous'',''light.hexagon_2_brightness'')}}'
      target:
        entity_id: light.hexagon_2
    else:
    - action: light.turn_on
      metadata: {}
      data:
        effect: '{{preset}}'
      target:
        entity_id: light.hexagon_2
    - action: variable.update_binary_sensor
      metadata: {}
      data:
        attributes:
          light.hexagon_2_effect: '{{states(''input_select.presets_hexagon'')}}'
      target:
        entity_id: binary_sensor.lights_previous
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  mode: single
  description: ''
  fields:
    preset:
      selector:
        text:
      name: preset
      required: false
new_script_3:
  alias: New Script
  sequence:
  - action: rest_command.govee_api
    data:
      command: device/diy-scenes
      payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\": \"H60A1\",\n
        \   \"device\": \"0A:B2:D0:C9:07:62:51:EA\"\n  }\n}"
    response_variable: response
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ response.status == 200 }}'
      - condition: template
        value_template: '{{ response.content.payload.capabilities[0].parameters.options
          | length > 0 }}'
      sequence:
      - repeat:
          for_each: '{{ response.content.payload.capabilities[0].parameters.options
            }}'
          sequence:
          - action: browser_mod.notification
            metadata: {}
            data:
              message: '[{{ response.content.payload.capabilities[0].parameters.options
                | map(attribute=''name'')| join('', '') }}] {{repeat.item.name}}:
                {{repeat.item.value}}'
              title: Available Scenes
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ response.status != 200 }}'
      sequence:
      - action: browser_mod.notification
        metadata: {}
        data:
          message: 'Error: Response status was {{ response.status }}'
          title: Scene Fetch Error
  description: ''
update_ceiling_states:
  alias: Update Ceiling States
  sequence:
  - action: rest_command.govee_api
    data:
      command: device/state
      payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\": \"H60A1\",\n
        \   \"device\": \"0A:B2:D0:C9:07:62:51:EA\"\n  }\n}"
    response_variable: response
  - action: rest_command.govee_api
    data:
      command: device/scenes
      payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\": \"H60A1\",\n
        \   \"device\": \"0A:B2:D0:C9:07:62:51:EA\"\n  }\n}"
    response_variable: lightscenes
  - action: rest_command.govee_api
    data:
      command: device/diy-scenes
      payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\": \"H60A1\",\n
        \   \"device\": \"0A:B2:D0:C9:07:62:51:EA\"\n  }\n}"
    response_variable: diyscenes
  - action: rest_command.govee_api_devices
    data: {}
    response_variable: snapshots
  - variables:
      snapshot_dict: "{ {% for item in snapshots.content.data[5].capabilities[8].parameters.options
        %}\n  \"{{ item.name }}\": {{ item.value }}{{ \",\" if not loop.last else
        \"\" }}\n{% endfor %} }\n"
      lightscenes_dict: "{ {% for item in lightscenes.content.payload.capabilities[0].parameters.options
        %}\n  \"{{ item.name }}\": {{ item.value }}{{ \",\" if not loop.last else
        \"\" }}\n{% endfor %} }\n"
      diyscenes_dict: "{ {% for item in diyscenes.content.payload.capabilities[0].parameters.options
        %}\n  \"{{ item.name }}\": {{ item.value }}{{ \",\" if not loop.last else
        \"\" }}\n{% endfor %} }\n"
      effect_list: '{{ (snapshot_dict.keys() | list + diyscenes_dict.keys() | list
        + lightscenes_dict.keys() | list ) | unique | sort }}

        '
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ response.status == 200 }}'
      sequence:
      - action: variable.update_sensor
        metadata: {}
        data:
          replace_attributes: false
          attributes:
            online: '{{ response.content.payload.capabilities[0].state.value }}'
            state: '{{ ''on'' if response.content.payload.capabilities[1].state.value==1
              else ''off'' }}'
            brightness: '{{ response.content.payload.capabilities[2].state.value }}'
            color_rgb: '{{ response.content.payload.capabilities[5].state.value if
              response.content.payload.capabilities[5].state.value != 0 else state_attr(''sensor.lucy_ceiling_attributes'',''color_rgb'')
              }}'
            color_temp_kelvin: '{{ response.content.payload.capabilities[6].state.value
              if response.content.payload.capabilities[6].state.value != 0 else state_attr(''sensor.lucy_ceiling_attributes'',''color_temp_kelvin'')}}'
            color_temp: '{{ ((1000000 / response.content.payload.capabilities[6].state.value)
              | round(0) | int) if response.content.payload.capabilities[6].state.value
              != 0 else state_attr(''sensor.lucy_ceiling_attributes'',''color_temp'')
              }}'
            snapshots: '{{ snapshot_dict }}'
            diy_scenes: '{{ diyscenes_dict }}'
            light_scenes: '{{ lightscenes_dict }}'
            effect_list: '{{ effect_list }}'
            last_updated: '{{ now() | string }}'
          value: '{{ ''on'' if response.content.payload.capabilities[1].state.value==1
            else ''off'' }}'
        target:
          entity_id: sensor.lucy_ceiling_attributes
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ response.status != 200 }}'
      sequence:
      - action: browser_mod.notification
        metadata: {}
        data:
          message: 'Error: Response status was {{ response.status }}'
          title: Scene Fetch Error
    enabled: true
  description: ''
  mode: queued
  max: 10
update_state_sensors:
  alias: Update State Sensors
  sequence:
  - action: script.update_ceiling_states
    data: {}
  description: Update all the custom sensor states
  mode: queued
  max: 10
govee_control:
  alias: Govee Control
  sequence:
  - variables:
      sku: '{{state_attr(sensor,''info'')[''sku'']}}

        '
      device: '{{state_attr(sensor,''info'')[''device'']}}

        '
      entity_id: '{{state_attr(sensor,''info'')[''entity_id'']}}

        '
  - alias: setColorTemp
    choose:
    - conditions:
      - condition: template
        value_template: '{{color_temp is defined}}'
      sequence:
      - variables:
          value: '{{ (1000000 / color_temp) | round(0) | int}}

            '
      - action: script.notify
        metadata: {}
        data:
          content: "target: <{{entity_id}}> \nmireds: {{color_temp}} \n"
          title: 'color_temp : {{value}}K'
          id: Log_color_temp
        enabled: false
      - action: rest_command.govee_api_post
        data:
          payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
            \"{{ sku | string }}\",\n    \"device\": \"{{ device | string}}\",\n    \"capability\":
            {\n      \"type\": \"devices.capabilities.color_setting\",\n      \"instance\":
            \"colorTemperatureK\",\n      \"value\": {{ value | int }}\n    }\n  }\n}"
        response_variable: response
        alias: setColorTemp
      - action: variable.update_sensor
        metadata: {}
        data:
          replace_attributes: false
          attributes:
            color_mode: color_temp
            color_temp: '{{ color_temp }}'
            color_temp_kelvin: '{{ value }}'
            last_updated: '{{now()|string}}'
            state: 'on'
          value: 'on'
        target:
          entity_id: '{{sensor}}'
      - action: script.notify
        metadata: {}
        data:
          content: "target: <{{entity_id}}> \nmireds: {{color_temp}} \n"
          title: 'color_temp : {{value}}K -> {{response.content.msg}}!'
          id: Log_color_temp
        enabled: false
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 500
  - alias: setEffect
    choose:
    - conditions:
      - condition: template
        value_template: '{{effect is defined}}'
      sequence:
      - variables:
          snapshots: '{{ state_attr(sensor, ''snapshots'') }}'
          diy_scenes: '{{ state_attr(sensor, ''diy_scenes'') }}'
          light_scenes: '{{ state_attr(sensor, ''light_scenes'') }}'
          value: "{% if effect in snapshots %}\n  {{ snapshots[effect] }}\n{% elif
            effect in diy_scenes %}\n  {{ diy_scenes[effect] }}\n{% elif effect in
            light_scenes %}\n  {{ light_scenes[effect].id }}\n{% else %}\n  none\n{%
            endif %}"
          instance: "{% if effect in snapshots %}\n  snapshot\n{% elif effect in diy_scenes
            %}\n  diyScene\n{% elif effect in light_scenes %}\n  lightScene\n{% else
            %}\n  none\n{% endif %}"
      - action: script.notify
        metadata: {}
        data:
          content: "target: <{{entity_id}}> \ninstance: {{instance}} \n"
          title: 'effect : {{value}}'
          id: Log_effect
        enabled: false
      - choose:
        - conditions:
          - condition: template
            value_template: '{{ value != ''none'' and instance != ''none'' }}'
          sequence:
          - action: rest_command.govee_api_post
            data:
              payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
                \"{{ sku }}\",\n    \"device\": \"{{ device }}\",\n    \"capability\":
                {\n      \"type\": \"devices.capabilities.dynamic_scene\",\n      \"instance\":
                \"{{ instance }}\",\n      \"value\": {{ value | int }}\n    }\n  }\n}"
            response_variable: response
        default:
        - action: browser_mod.notification
          data:
            message: Der ausgewählte Effekt '{{ effect }}' ist nicht verfügbar.
            title: Fehler
      - action: variable.update_sensor
        metadata: {}
        data:
          replace_attributes: false
          attributes:
            effect: '{{effect|string}}'
            color_mode: effect
            last_updated: '{{now()|string}}'
            state: 'on'
          value: 'on'
        target:
          entity_id: '{{sensor}}'
      - action: script.notify
        metadata: {}
        data:
          content: "target: <{{entity_id}}> \ninstance: {{instance}} \n"
          title: 'effect : {{value}} -> {{response.content.msg}}!'
          id: Log_effect
        enabled: false
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 500
  - alias: setColorRGB
    choose:
    - conditions:
      - condition: template
        value_template: '{{color_rgb is defined or color is defined}}'
      sequence:
      - variables:
          value: '{{color if color is defined else ( color_rgb[0] * 65536+ color_rgb[1]
            * 256 +  color_rgb[2] ) | int}}

            '
      - action: script.notify
        metadata: {}
        data:
          content: "target: <{{entity_id}}> \nvalue: {{value}}\n"
          title: 'color_rgb: ({{color if color is defined else (color_rgb[0], color_rgb[1],
            color_rgb[2])}})'
          id: Log_color_rgb
        enabled: false
      - action: rest_command.govee_api_post
        data:
          payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
            \"{{ sku | string }}\",\n    \"device\": \"{{ device | string}}\",\n    \"capability\":
            {\n      \"type\": \"devices.capabilities.color_setting\",\n      \"instance\":
            \"colorRgb\",\n      \"value\": {{ value | int }}\n    }\n  }\n}"
        response_variable: response
        alias: setColorRGB
      - action: variable.update_sensor
        metadata: {}
        data:
          replace_attributes: false
          attributes:
            color_rgb: '{{value}}'
            color_mode: rgb
            color:
              r: '{{color_rgb[0] if color_rgb is defined else state_attr(sensor,''color_rgb'').r}}'
              g: '{{color_rgb[1] if color_rgb is defined else state_attr(sensor,''color_rgb'').g}}'
              b: '{{color_rgb[2] if color_rgb is defined else state_attr(sensor,''color_rgb'').b}}'
            last_updated: '{{now()}}'
            state: 'on'
          value: 'on'
        target:
          entity_id: '{{sensor}}'
      - action: script.notify
        metadata: {}
        data:
          content: "target: <{{entity_id}}> \nvalue: {{value}}\n"
          title: 'color_rgb: ({{color if color is defined else (color_rgb[0], color_rgb[1],
            color_rgb[2])}}) -> {{response.content.msg}}!'
          id: Log_color_rgb
        enabled: false
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 500
  - alias: powerSwitch
    choose:
    - conditions:
      - condition: template
        value_template: '{{switch is defined}}'
      sequence:
      - variables:
          value: '{{1 if switch==''on'' else 0 }}'
      - action: script.notify
        metadata: {}
        data:
          content: "target: <{{entity_id}}> \n"
          title: 'powerSwitch: {{switch}}'
          id: Log_power_switch
        enabled: false
      - action: rest_command.govee_api_post
        data:
          payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
            \"{{ sku | string }}\",\n    \"device\": \"{{ device | string}}\",\n    \"capability\":
            {\n      \"type\": \"devices.capabilities.on_off\",\n      \"instance\":
            \"powerSwitch\",\n      \"value\": {{ value | int }}\n    }\n  }\n}"
        response_variable: response
        alias: powerSwitch
      - action: variable.update_sensor
        metadata: {}
        data:
          replace_attributes: false
          value: '{{ switch }}'
          attributes:
            last_updated: '{{now()|string}}'
            state: '{{ switch }}'
        target:
          entity_id: '{{sensor}}'
      - action: script.notify
        metadata: {}
        data:
          content: "target: <{{entity_id}}> \n"
          title: 'powerSwitch: {{switch}} -> {{response.content.msg}}!'
          id: Log_power_switch
        enabled: false
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 500
  - alias: setBrightness
    choose:
    - conditions:
      - condition: template
        value_template: '{{brightness is defined}}'
      sequence:
      - variables:
          value: '{{brightness}}'
      - action: script.notify
        metadata: {}
        data:
          id: Log_brightness
          content: "target: <{{entity_id}}> \nabsolute: {{(value / 100 * 255) | round(0)}}
            \n"
          title: 'brightness : {{value}}%'
        enabled: false
      - action: rest_command.govee_api_post
        data:
          payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
            \"{{ sku | string }}\",\n    \"device\": \"{{ device | string}}\",\n    \"capability\":
            {\n      \"type\": \"devices.capabilities.range\",\n      \"instance\":
            \"brightness\",\n      \"value\": {{ value | int }}\n    }\n  }\n}"
        response_variable: response
        alias: setBrightness
      - action: variable.update_sensor
        metadata: {}
        data:
          replace_attributes: false
          attributes:
            brightness: '{{value}}'
            last_updated: '{{now()|string}}'
            state: 'on'
          value: 'on'
        target:
          entity_id: '{{sensor}}'
      - action: script.notify
        metadata: {}
        data:
          id: Log_brightness
          content: "target: <{{entity_id}}> \nabsolute: {{(value / 100 * 255) | round(0)}}
            \n"
          title: 'brightness : {{value}}% -> {{response.content.msg}}!'
        enabled: false
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 500
  - alias: mode
    choose:
    - conditions:
      - condition: template
        value_template: '{{mode is defined}}'
      sequence:
      - choose:
        - conditions:
          - condition: template
            value_template: '{{mode ==''effect''}}'
          sequence:
          - action: script.govee_control
            metadata: {}
            data:
              sensor: '{{sensor}}'
              effect: '{{state_attr(sensor,''effect'')}}'
          alias: effect
        - conditions:
          - condition: template
            value_template: '{{mode ==''color_rgb''}}'
          sequence:
          - action: script.govee_control
            metadata: {}
            data:
              sensor: '{{sensor}}'
              color: '{{state_attr(sensor,''color_rgb'')}}'
          alias: color_rgb
        - conditions:
          - condition: template
            value_template: '{{mode ==''color_temp''}}'
          sequence:
          - action: script.govee_control
            metadata: {}
            data:
              sensor: '{{sensor}}'
              color_temp: '{{state_attr(sensor,''color_temp'')}}'
          alias: color_temp
  - sequence:
    - action: rest_command.govee_api
      data:
        command: device/state
        payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\": \"{{
          sku | string }}\",\n    \"device\": \"{{ device | string}}\",      \n  }\n}"
      response_variable: response
    - action: variable.update_sensor
      metadata: {}
      data:
        replace_attributes: false
        attributes:
          online: '{{ response.content.payload.capabilities[0].state.value }}'
          state: '{{ ''on'' if response.content.payload.capabilities[1].state.value==1
            else ''off'' }}'
          brightness: '{{ response.content.payload.capabilities[2].state.value }}'
          color_rgb: '{{ response.content.payload.capabilities[5].state.value if response.content.payload.capabilities[5].state.value
            != 0 else state_attr(''sensor.lucy_ceiling_attributes'',''color_rgb'')
            }}'
          color_temp_kelvin: '{{ response.content.payload.capabilities[6].state.value
            if response.content.payload.capabilities[6].state.value != 0 else state_attr(''sensor.lucy_ceiling_attributes'',''color_temp_kelvin'')}}'
          color_temp: '{{ ((1000000 / response.content.payload.capabilities[6].state.value)
            | round(0) | int) if response.content.payload.capabilities[6].state.value
            != 0 else state_attr(''sensor.lucy_ceiling_attributes'',''color_temp'')
            }}'
        value: '{{ ''on'' if response.content.payload.capabilities[1].state.value==1
          else ''off'' }}'
      target:
        entity_id: '{{ sensor }}'
    enabled: false
  - if:
    - condition: template
      value_template: "{% set last_updated = state_attr(sensor, 'last_updated') %}\n{%
        if last_updated %}\n  {{ (now() - last_updated | as_datetime).total_seconds()
        > 5 }}\n{% else %}\n  true\n{% endif %}"
    then:
    - action: script.govee_get_states
      metadata: {}
      data:
        sensor: '{{sensor}}'
  fields:
    effect:
      selector:
        text: {}
      name: effect
      required: false
    sensor:
      selector:
        entity:
          multiple: false
      name: sensor
      required: true
      default: sensor.lucy_ceiling_attributes
    color_temp:
      selector:
        number:
          min: 153
          max: 456
          step: 1
      name: color_temp
      required: false
    color_rgb:
      selector:
        color_rgb: {}
      name: color_rgb
    switch:
      selector:
        text:
      name: switch
    brightness:
      selector:
        number:
          min: 0
          max: 100
          step: 1
      name: brightness
      required: false
    mode:
      selector:
        select:
          options:
          - color_temp
          - effect
          - color_rgb
      name: mode
    color:
      selector:
        number:
          min: 1
          max: 100
  description: ''
  icon: mdi:alpha-g-circle
  mode: parallel
  max: 10
state_toggle:
  alias: State Toggle
  sequence:
  - action: variable.update_sensor
    metadata: {}
    data:
      replace_attributes: false
      attributes:
        '{{toggle}}': '{{state}}'
    target:
      entity_id: sensor.state_toggles
  fields:
    toggle:
      selector:
        text:
      name: toggle
      required: true
    state:
      selector:
        text:
      name: state
      required: true
  description: ''
  icon: mdi:toggle-switch-off-outline
lucys_master_light:
  alias: Lucys Master Light
  sequence:
  - variables:
      dim: "{{ expand('light.group_lucy')\n   | rejectattr('entity_id','search','^light.tasmota_')\n
        \  | selectattr('state', 'eq', 'on')\n   | map(attribute='entity_id')\n   |
        list }}\n"
      onoff: "{{ expand('light.group_lucy')\n   | selectattr('entity_id','search','^light.tasmota_')\n
        \  | selectattr('state', 'eq', 'on')\n   | map(attribute='entity_id')\n   |
        list }}\n"
      scenes: "{{ expand('switch.lucys_scenes')\n   | map(attribute='entity_id')\n
        \  | list }}\n"
  - choose:
    - conditions:
      - condition: template
        value_template: '{{switch is defined or (brightness is defined and brightness==0)}}'
      sequence:
      - choose:
        - conditions:
          - condition: template
            value_template: '{{ switch == ''turnOff'' or brightness == 0 }}'
          sequence:
          - action: script.state_save
            data:
              entity: binary_sensor.lights_previous
            enabled: true
          - action: light.turn_off
            metadata: {}
            data:
              transition: 5
            target:
              entity_id: '{{dim}}'
            enabled: true
          - action: light.turn_off
            metadata: {}
            target:
              entity_id: '{{onoff}}'
            enabled: true
          - action: variable.update_sensor
            metadata: {}
            data:
              replace_attributes: false
              value: 'Off'
            target:
              entity_id: sensor.lucy_master_attributes
          alias: Fade off, lights on
        - conditions:
          - condition: template
            value_template: '{{ switch == ''turnOn'' }}'
          sequence:
          - action: script.state_restore
            data:
              entity: binary_sensor.lights_previous
            enabled: true
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.all_off_stateful_scene
            enabled: false
          - action: variable.update_sensor
            metadata: {}
            data:
              replace_attributes: false
              value: 'On'
            target:
              entity_id: sensor.lucy_master_attributes
          alias: lights off
    - conditions:
      - condition: template
        value_template: '{{brightness is defined }}'
      sequence:
      - action: light.turn_on
        metadata: {}
        data:
          transition: 2
          brightness: '{{ brightness | int }}'
        target:
          entity_id: '{{dim}}'
  - variables:
      state: '{{states(''light.group_lucy'')}}'
      brightness: '{{brightness if brightness is defined else state_attr(''light.group_lucy'',''brightness'')}}'
  - action: variable.update_sensor
    metadata: {}
    data:
      replace_attributes: false
      attributes:
        brightness: '{{brightness}}'
    target:
      entity_id: sensor.lucy_master_attributes
  description: ''
  fields:
    switch:
      selector:
        text:
      name: switch
    brightness:
      selector:
        number:
          min: 0
          max: 255
          step: 1
update_tv_bar:
  alias: update_tv_bar
  sequence:
  - action: variable.update_sensor
    metadata: {}
    data:
      replace_attributes: false
      value: '{{state_attr(''media_player.fuchscast'', ''media_position'')}}'
      attributes:
        segs_filled: 0
    target:
      entity_id: sensor.fuchscast_position
  - variables:
      segs_done: '{{(26/100*((states(''sensor.fuchscast_position'')|float / state_attr(''media_player.fuchscast'',
        ''media_duration'')|float)*100))|round(0)}}

        '
      segs_filled: '{{state_attr(''sensor.fuchscast_position'', ''segs_filled'')}}

        '
  - if:
    - condition: and
      conditions:
      - condition: state
        entity_id: input_boolean.scene_tv_bar
        state: 'on'
      - condition: template
        value_template: '{{segs_filled|int != segs_done|int}}'
    then:
    - action: rest_command.wled_api
      metadata: {}
      data:
        payload: "{\n  \"mainseg\": 0,\n  \"seg\": [\n    {\"id\":6,\"start\":125,\"stop\":
          {{ iif((151-segs_done)>125,(151-segs_done),0) }},\"grp\":1,\"spc\":0,\"of\":0,\"on\":true,\"frz\":false,\"bri\":255,\"cct\":127,\"set\":0,\"n\":\"\",\"col\":[[0,0,0],[90,68,180],[4,196,193]],\"fx\":0,\"sx\":128,\"ix\":128,\"pal\":2,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":true,\"mi\":false,\"o1\":false,\"o2\":false,\"o3\":false,\"si\":0,\"m12\":0}]}\n
          \ ]\n}"
      response_variable: response
    - delay:
        hours: 0
        minutes: 0
        seconds: 0
        milliseconds: 500
    - action: rest_command.wled_api
      metadata: {}
      data:
        payload: "{\n  \"mainseg\": 0,\n  \"seg\": [\n    {\"id\":3,\"start\": {{
          iif((151-segs_done)<=150,(151-segs_done),150) }},\"stop\":151,\"grp\":1,\"spc\":0,\"of\":0,\"on\":true,\"frz\":false,\"cct\":127,\"set\":0,\"n\":\"TV\",\"col\":[[96,45,205],[132,41,123],[190,0,54]],\"fx\":46,\"sx\":76,\"ix\":11,\"pal\":246,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":true,\"mi\":false,\"o1\":false,\"o2\":false,\"o3\":false,\"si\":0,\"m12\":0}]}\n
          \ ]\n}"
      response_variable: response
    - action: variable.update_sensor
      metadata: {}
      data:
        replace_attributes: false
        attributes:
          segs_filled: '{{segs_done}}

            '
        value: '{{states(''sensor.fuchscast_position'')|float + 0.5}}'
      target:
        entity_id: sensor.fuchscast_position
  - repeat:
      sequence:
      - action: variable.update_sensor
        metadata: {}
        data:
          replace_attributes: false
          value: '{{states(''sensor.fuchscast_position'')|float + 1}}'
        target:
          entity_id: sensor.fuchscast_position
      - variables:
          segs_done: '{{(26/100*((states(''sensor.fuchscast_position'')|float / state_attr(''media_player.fuchscast'',
            ''media_duration'')|float)*100))|round(0)}}

            '
          segs_filled: '{{state_attr(''sensor.fuchscast_position'', ''segs_filled'')}}

            '
      - if:
        - condition: and
          conditions:
          - condition: state
            entity_id: input_boolean.scene_tv_bar
            state: 'on'
          - condition: template
            value_template: '{{segs_filled|int != segs_done|int}}'
        then:
        - action: variable.update_sensor
          metadata: {}
          data:
            replace_attributes: false
            attributes:
              segs_filled: '{{segs_done}}

                '
          target:
            entity_id: sensor.fuchscast_position
        - action: rest_command.wled_api
          metadata: {}
          data:
            payload: "{\n  \"mainseg\": 0,\n  \"seg\": [\n    {\"id\":6,\"start\":125,\"stop\":
              {{ iif((151-segs_done)>125,(151-segs_done),0) }},\"grp\":1,\"spc\":0,\"of\":0,\"on\":true,\"frz\":false,\"bri\":255,\"cct\":127,\"set\":0,\"n\":\"\",\"col\":[[0,0,0],[90,68,180],[4,196,193]],\"fx\":0,\"sx\":128,\"ix\":128,\"pal\":2,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":true,\"mi\":false,\"o1\":false,\"o2\":false,\"o3\":false,\"si\":0,\"m12\":0}]}\n
              \ ]\n}"
          response_variable: response
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
          milliseconds: 0
      - if:
        - condition: and
          conditions:
          - condition: state
            entity_id: input_boolean.scene_tv_bar
            state: 'on'
          - condition: template
            value_template: '{{segs_filled|int != segs_done|int}}'
        then:
        - action: variable.update_sensor
          metadata: {}
          data:
            replace_attributes: false
            value: '{{states(''sensor.fuchscast_position'')|float + 1}}'
          target:
            entity_id: sensor.fuchscast_position
        - action: rest_command.wled_api
          metadata: {}
          data:
            payload: "{\n  \"mainseg\": 0,\n  \"seg\": [\n    {\"id\":3,\"start\":
              {{ iif((151-segs_done)<=150,(151-segs_done),150) }},\"stop\":151,\"grp\":1,\"spc\":0,\"of\":0,\"on\":true,\"frz\":false,\"cct\":127,\"set\":0,\"n\":\"TV\",\"col\":[[96,45,205],[132,41,123],[190,0,54]],\"fx\":46,\"sx\":76,\"ix\":11,\"pal\":246,\"c1\":128,\"c2\":128,\"c3\":16,\"sel\":true,\"rev\":true,\"mi\":false,\"o1\":false,\"o2\":false,\"o3\":false,\"si\":0,\"m12\":0}]}\n
              \ ]\n}"
          response_variable: response
      while:
      - condition: and
        conditions:
        - condition: state
          entity_id: input_boolean.scene_tv_bar
          state: 'on'
        - condition: state
          entity_id: media_player.fuchscast
          state: playing
          enabled: false
    enabled: true
  description: ''
  icon: mdi:youtube-tv
  mode: single
light_color_temp_by_step:
  alias: Light - Color Temp by step
  sequence:
  - variables:
      val: '{{ value if value is defined else 10}}'
      entity: '{{ entity if entity is defined else ''light.lucy_ceiling'' }}'
      target_temp: "{% set min = state_attr(entity,'min_mireds')|int %} {% set max
        = state_attr(entity,'max_mireds')|int %} {% set current = state_attr(entity,'color_temp')|int
        %} {% set new = (current | int) + (value |int) %}  {% if new > max %}\n  {{max|int}}\n{%
        elif new < min %}\n  {{min|int}}\n{% else %}\n  {{ new|int }}\n{% endif %}\n"
  - action: light.turn_on
    metadata: {}
    data:
      color_temp: '{{ target_temp }}'
    target:
      entity_id: '{{ entity }}'
  fields:
    value:
      selector:
        number:
          min: -50
          max: 50
          step: 1
      default: 10
      required: true
    entity:
      selector:
        entity: {}
      name: entity
      default: light.lucy_ceiling
      required: true
  description: ''
  icon: mdi:temperature-kelvin
govee_get_states:
  alias: Govee Get States
  sequence:
  - variables:
      sku: '{{state_attr(sensor,''info'')[''sku'']}}

        '
      device: '{{state_attr(sensor,''info'')[''device'']}}

        '
      entity_id: '{{state_attr(sensor,''info'')[''entity_id'']}}

        '
  - action: rest_command.govee_api
    data:
      command: device/state
      payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\": \"{{
        sku }}\",\n    \"device\": \"{{ device }}\"\n  }\n}"
    response_variable: response
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 25
  - action: rest_command.govee_api
    data:
      command: device/scenes
      payload: "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n      \"sku\": \"{{
        sku }}\",\n      \"device\": \"{{ device }}\"\n  }\n}"
    response_variable: lightscenes
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 25
  - action: rest_command.govee_api
    data:
      command: device/diy-scenes
      payload: "{\n  \"requestId\": \"uuid\",\n    \"payload\": {\n        \"sku\":
        \"{{ sku }}\",\n        \"device\": \"{{ device }}\"\n  }\n}"
    response_variable: diyscenes
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 25
  - action: rest_command.govee_api_devices
    data: {}
    response_variable: snapshots
  - variables:
      snapshot_dict: "{ {% for item in\nsnapshots.content.data[5].capabilities[8].parameters.options
        %}\n  \"{{ item.name }}\": {{ item.value }}{{ \",\" if not loop.last else
        \"\" }}\n{% endfor %} }   \n"
      lightscenes_dict: "{ {% for item in\nlightscenes.content.payload.capabilities[0].parameters.options
        %}\n  \"{{ item.name }}\": {{ item.value }}{{ \",\" if not loop.last else
        \"\" }}\n{% endfor %} }\n"
      diyscenes_dict: "{ {% for item in\ndiyscenes.content.payload.capabilities[0].parameters.options
        %}\n  \"{{ item.name }}\": {{ item.value }}{{ \",\" if not loop.last else
        \"\" }}\n{% endfor %} }\n"
      effect_list: '{{ (snapshot_dict.keys() | list + diyscenes_dict.keys() | list
        +

        lightscenes_dict.keys() | list ) | unique | sort }}

        '
  - action: variable.update_sensor
    metadata: {}
    data:
      replace_attributes: false
      attributes:
        online: '{{ response.content.payload.capabilities[0].state.value }}'
        last_updated: '{{ now() | string }}'
    target:
      entity_id: '{{ sensor }}'
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ response.status == 200 }}'
      sequence:
      - action: variable.update_sensor
        metadata: {}
        data:
          replace_attributes: false
          attributes:
            online: '{{ response.content.payload.capabilities[0].state.value }}'
            state: '{{ ''on'' if response.content.payload.capabilities[1].state.value==1
              else ''off'' }}'
            brightness: '{{ response.content.payload.capabilities[2].state.value }}'
            color_rgb: '{{ response.content.payload.capabilities[5].state.value if
              response.content.payload.capabilities[5].state.value != 0 else state_attr(sensor,''color_rgb'')
              }}'
            color_temp_kelvin: '{{ response.content.payload.capabilities[6].state.value
              if response.content.payload.capabilities[6].state.value != 0 else state_attr(sensor,''color_temp_kelvin'')}}'
            color_temp: '{{ ((1000000 / response.content.payload.capabilities[6].state.value)
              | round(0) | int) if response.content.payload.capabilities[6].state.value
              != 0 else state_attr(sensor,''color_temp'') }}'
            snapshots: '{{ snapshot_dict }}'
            diy_scenes: '{{ diyscenes_dict }}'
            light_scenes: '{{ lightscenes_dict }}'
            effect_list: '{{ effect_list }}'
            last_updated: '{{ now() | string }}'
          value: '{{ ''on'' if response.content.payload.capabilities[1].state.value==1
            else ''off'' }}'
        target:
          entity_id: '{{ sensor }}'
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ response.status != 200 }}'
      sequence:
      - action: browser_mod.notification
        metadata: {}
        data:
          message: 'Error: Response status was {{ response.status }}'
          title: Scene Fetch Error
    enabled: true
  description: ''
  mode: queued
  max: 10
  fields:
    sensor:
      selector:
        entity: {}
      name: sensor
      required: true
webradio:
  alias: Webradio
  sequence:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ action == ''add'' }}'
      sequence:
      - condition: template
        value_template: '{{ has_value(''input_text.webradio_name'') and has_value(''input_text.webradio_url'')
          }}'
      - data:
          replace_attributes: false
          attributes:
            '{{ states(''input_text.webradio_name'') }}': '{{states(''input_text.webradio_url'')
              }}'
        target:
          entity_id: sensor.webradio_streams
        action: variable.update_sensor
      - condition: template
        value_template: "          {% set new_option = states('input_text.webradio_name')
          %}\n          {{ new_option not in state_attr('input_select.webradio_streams',
          'options') }}\n"
      - action: input_select.set_options
        metadata: {}
        data:
          options: '{% set current_options = state_attr(''input_select.webradio_streams'',
            ''options'') %} {{ (current_options + [states(''input_text.webradio_name'')])
            }}

            '
        target:
          entity_id: input_select.webradio_streams
      alias: add
    - conditions:
      - condition: template
        value_template: '{{ action == ''remove'' }}'
        alias: remove
      sequence:
      - condition: template
        value_template: '{{ states(''input_text.webradio_name'') in state_attr(''sensor.webradio_streams'',
          ''attributes'') }}'
    - conditions:
      - condition: template
        value_template: '{{ action == ''play'' }}'
        alias: play
      sequence:
      - data:
          media_content_type: music
          media_content_id: '{{ state_attr(''sensor.webradio_streams'', states(''input_select.webradio_streams''))
            }}'
          entity_id: '{{ state_attr(''sensor.media_players'', states(''input_select.media_player''))
            }}'
          extra:
            thumb: https://static-cdn.jtvnw.net/jtv_user_pictures/b6f05dc3-45f1-4bff-9c45-c6e86d5f6da7-profile_image-300x300.png
            title: '{{ states(''input_select.webradio_streams'') }}'
        target:
          entity_id: media_player.games_room_media_player_2
        action: media_player.play_media
  fields:
    action:
      description: Specify the action (add, remove, play)
      example: add
      selector:
        text:
save_restore_states:
  sequence:
  - action: input_select.set_options
    data:
      options: "{{ states.sensor \n   | selectattr('entity_id', 'search', '^sensor.scene_')\n
        \  | map(attribute='name')\n   | list }}\n"
    target:
      entity_id: input_select.scene_saves
  - variables:
      sensor: "{{ states.sensor\n   | selectattr('entity_id', 'search', '^sensor.scene_')\n
        \  | selectattr('name', 'eq', states('input_select.scene_saves'))\n   | map(attribute='entity_id')\n
        \  | first }}\n"
      action: '{{action if action is defined else ''save''}}'
  - if:
    - condition: template
      value_template: '{{action==''save''}}'
    then:
    - action: script.state_save
      metadata: {}
      data:
        entity: '{{ sensor }}'
    else:
    - action: script.state_restore
      metadata: {}
      data:
        entity: '{{ sensor }}'
  fields:
    action:
      selector:
        text:
      default: save
  alias: Save / Restore States
  description: From/to scene_sensor
scenes_control:
  sequence:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{scene=="musicfx"}}'
      sequence:
      - if:
        - condition: or
          conditions:
          - condition: state
            entity_id: light.ledfx_192_168_2_33_wled
            state: unavailable
          - condition: state
            entity_id: input_boolean.scene_musicfx
            state: 'on'
        then:
        - action: input_boolean.turn_off
          metadata: {}
          data: {}
          target:
            entity_id: input_boolean.scene_musicfx
        - action: select.select_option
          metadata: {}
          data:
            option: '1'
          target:
            entity_id: select.wled_live_override
      alias: musicfx
    - conditions:
      - condition: template
        value_template: '{{scene=="default"}}'
      sequence:
      - action: script.state_restore
        metadata: {}
        data:
          entity: '{{''sensor.scene_''+scene}}'
      alias: musicfx
    - conditions:
      - condition: template
        value_template: '{{scene=="minimal" or scene=="uv_only"}}'
      sequence:
      - if:
        - condition: template
          value_template: '{{is_state(''input_boolean.scene_''+scene,''on'')}}'
        then:
        - action: input_boolean.turn_off
          metadata: {}
          data: {}
          target:
            entity_id: '{{''input_boolean.scene_''+scene}}'
        - action: script.state_restore
          metadata: {}
          data:
            entity: sensor.scene_previous
        else:
        - action: script.state_save
          metadata: {}
          data:
            entity: sensor.scene_previous
        - action: script.state_restore
          metadata: {}
          data:
            entity: '{{''sensor.scene_''+scene}}'
        - action: input_boolean.turn_on
          metadata: {}
          data: {}
          target:
            entity_id: '{{''input_boolean.scene_''+scene}}'
      alias: musicfx
  fields:
    scene:
      selector:
        text:
      required: true
  alias: Scenes - Control
  description: ''
add_list_item_2:
  sequence:
  - action: todo.add_item
    metadata: {}
    data:
      item: '{{states(''input_text.add_list_item'')}}'
    target:
      entity_id: '{{entity}}'
  alias: Add List Item
  description: ''
  fields:
    entity:
      selector:
        text:
      name: entity
      required: true
pmg_catcher_time_record:
  sequence:
  - repeat:
      count: 20
      sequence:
      - action: input_datetime.set_datetime
        metadata: {}
        data:
          time: '{{states(''input_datetime.pmg_catcher_session_time'')+"00:00:05"}}

            '
        target:
          entity_id: input_datetime.pmg_catcher_session_time
      - delay:
          hours: 0
          minutes: 0
          seconds: 5
          milliseconds: 0
  alias: PMG Catcher Time record
  description: ''
mirror_light:
  sequence:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{mode=="cold"}}'
      sequence:
      - action: light.toggle
        metadata: {}
        data:
          kelvin: 5221
        target:
          entity_id: light.bathroom_mirror
    - conditions:
      - condition: template
        value_template: '{{mode=="warm"}}'
      sequence:
      - action: light.toggle
        metadata: {}
        data:
          kelvin: 3399
        target:
          entity_id: light.bathroom_mirror
  alias: Mirror Light
  description: ''
  fields:
    mode:
      selector:
        text:
      name: mode
      required: true
pmg_session_timer_2:
  sequence:
  - action: input_datetime.set_datetime
    metadata: {}
    data:
      time: '{{states(''input_datetime.pmg_session_timer'')+5}}'
    target:
      entity_id: input_datetime.pmg_session_timer
  alias: PMG - Session Timer
  description: ''
state_fuchsbau_light_states:
  sequence:
  - variables:
      is_debug: false
      lights: "{{ expand('light.fuchsbau_lights')\n   | map(attribute='entity_id')\n
        \  | list }}\n"
      entity: sensor.fuchsbau_light_states
  - repeat:
      for_each: '{{ lights }}'
      sequence:
      - alias: Save State
        if:
        - condition: template
          value_template: '{{ state_attr(entity, repeat.item) == None or state_attr(entity,
            repeat.item) != states(repeat.item) }}'
        then:
        - action: variable.update_sensor
          data:
            attributes:
              '{{ repeat.item }}': '{{ states(repeat.item) }}'
          target:
            entity_id: '{{ entity }}'
        - action: counter.increment
          metadata: {}
          data: {}
          target:
            entity_id: counter.state_changes
        - if:
          - condition: template
            value_template: '{{is_debug}}'
          then:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: Successfully updated {{ repeat.item }} {{ states(repeat.item)
                }} attributes of {{ entity }}.
              title: State Save
          alias: Debug
      - alias: Save Brightness
        if:
        - condition: template
          value_template: '{{ state_attr(repeat.item, ''brightness'') != None and
            state_attr(entity, repeat.item~".brightness") != state_attr(repeat.item,
            ''brightness'')}}'
        then:
        - action: variable.update_sensor
          data:
            attributes:
              '{{ repeat.item }}.brightness': '{{ state_attr(repeat.item,''brightness'')
                }}'
          target:
            entity_id: '{{ entity }}'
        - action: counter.increment
          metadata: {}
          data: {}
          target:
            entity_id: counter.state_changes
        - if:
          - condition: template
            value_template: '{{is_debug}}'
          then:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: Successfully updated {{ repeat.item }} {{ states(repeat.item)
                }} attributes of {{ entity }}.
              title: State Save
          alias: Debug
      - alias: Save Effect
        if:
        - condition: template
          value_template: '{{ state_attr(repeat.item, ''effect'') != None and state_attr(entity,
            repeat.item~".effect") != state_attr(repeat.item, ''effect'')}}'
        then:
        - action: variable.update_sensor
          data:
            attributes:
              '{{ repeat.item }}.effect': '{{ state_attr(repeat.item,''effect'') }}'
          target:
            entity_id: '{{ entity }}'
        - action: counter.increment
          metadata: {}
          data: {}
          target:
            entity_id: counter.state_changes
        - if:
          - condition: template
            value_template: '{{is_debug}}'
          then:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: Successfully updated {{ repeat.item }} {{ states(repeat.item)
                }} attributes of {{ entity }}.
              title: State Save
          alias: Debug
      - alias: Save color mode
        if:
        - condition: template
          value_template: '{{ state_attr(repeat.item, ''color_mode'') != None and
            state_attr(entity, repeat.item~".color_mode") != state_attr(repeat.item,
            ''color_mode'')}}'
        then:
        - action: variable.update_sensor
          data:
            attributes:
              '{{ repeat.item }}.color_mode': '{{ state_attr(repeat.item,''color_mode'')
                }}'
          target:
            entity_id: '{{ entity }}'
        - action: counter.increment
          metadata: {}
          data: {}
          target:
            entity_id: counter.state_changes
        - if:
          - condition: template
            value_template: '{{is_debug}}'
          then:
          - action: persistent_notification.create
            metadata: {}
            data:
              message: Successfully updated {{ repeat.item }} {{ states(repeat.item)
                }} attributes of {{ entity }}.
              title: State Save
          alias: Debug
    enabled: true
  - action: counter.increment
    metadata: {}
    data: {}
    target:
      entity_id: counter.state_changes
  - if:
    - condition: template
      value_template: '{{is_debug}}'
    then:
    - choose:
      - conditions:
        - condition: numeric_state
          entity_id: counter.state_changes
          below: 1
        sequence:
        - action: persistent_notification.create
          metadata: {}
          data:
            message: No changed detected.
            title: State Change
            notification_id: state_change
      default:
      - action: persistent_notification.create
        metadata: {}
        data:
          message: Successfully updated {{ states('counter.state_changes') }} attributes
            of {{ entity }}.
          title: State Save
          notification_id: state_change
    alias: Debug notify
  alias: State Fuchsbau light states
  fields: {}
  description: ''
  icon: mdi:content-save-check
alarm_ring:
  sequence:
  - repeat:
      sequence:
      - variables:
          remaining_sec: "{{\n  (as_timestamp(state_attr('timer.kitchen_timer','finishes_at'))
            - as_timestamp(now()))\n| int }}\n"
          minutes: '{{ (remaining_sec // 60) | int }}'
          seconds: '{{ (remaining_sec % 60) | int }}'
          payload: '{{ ''%02d:%02d'' | format(minutes, seconds) }}'
      - action: mqtt.publish
        data:
          topic: kitchen/hub/digiclock/text
          payload: '{{payload}}'
          qos: '0'
          retain: true
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
          milliseconds: 0
      while:
      - condition: state
        entity_id: timer.kitchen_timer
        state: active
    enabled: false
  - action: mqtt.publish
    data:
      topic: kitchen/hub/buzzer
      qos: '0'
      payload: 'true'
  - repeat:
      count: 10
      sequence:
      - action: mqtt.publish
        data:
          topic: kitchen/hub/digiclock/text
          payload: --:--
          qos: '0'
          retain: true
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
          milliseconds: 0
      - action: mqtt.publish
        data:
          topic: kitchen/hub/digiclock/text
          payload: 00:00
          qos: '0'
          retain: true
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
          milliseconds: 0
    enabled: true
  - action: mqtt.publish
    data:
      topic: kitchen/hub/buzzer
      qos: '0'
      payload: 'false'
  alias: Alarm Ring
  description: ''
reload_config:
  sequence:
  - action: homeassistant.restart
    data: {}
  alias: Reload Config
  description: ''
