- alias: Auto TurnOn WLED Controller
  id: "1721917069437"
  description: Auto turns on WLED Controller when switching any child to ON
  triggers:
    - trigger: event
      event_type: state_changed
      event_data:
        domain: light
  conditions:
    - condition: template
      value_template: |-
        {% set entity_id = trigger.event.data.entity_id %}
        {{ entity_id in label_entities('WLED') and is_state(entity_id,'on') and is_state('light.wled_controller','off') }}
  actions:
    - metadata: {}
      data: {}
      target:
        entity_id: light.wled_controller
      action: light.turn_on
  mode: single
- alias: WLED Group Options
  id: "1725183657980"
  description: ""
  triggers:
    - trigger: state
      entity_id:
        - input_select.wled_group_color_palette
        - input_number.wled_group_intensity
        - input_number.wled_group_speed
        - input_select.wled_group_effect_select
  condition: []
  action:
    - choose:

        - conditions:
            - condition: template
              value_template:
                "{{ trigger.entity_id == 'input_select.wled_group_effect_select'
                }}"
          sequence:
            - action: input_select.select_option
              metadata: {}
              data:
                option: "{{ states(trigger.entity_id) }}"
              target:
                entity_id:
                  - input_select.wled_tv_effect_select
                  - input_select.wled_ceiling_effect_select
                  - input_select.wled_desktop_effect_select
                  - input_select.wled_umbreon_effect_select
                  - input_select.wled_ghost_effect_select
          alias: effect select
        - conditions:
            - condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.wled_group_intensity'
                }}"
          sequence:
            - action: number.set_value
              metadata: {}
              data:
                value: "{{ states(trigger.entity_id) }}"
              target:
                entity_id:
                  - number.wled_ceiling_intensity
                  - number.wled_desktop_intensity
                  - number.wled_tv_intensity
                  - number.wled_ghost_intensity
                  - number.wled_umbreon_intensity
          alias: intensity
        - conditions:
            - condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.wled_group_speed'
                }}"
          sequence:
            - action: number.set_value
              metadata: {}
              data:
                value: "{{ states(trigger.entity_id) }}"
              target:
                entity_id:
                  - number.wled_ceiling_speed
                  - number.wled_desktop_speed
                  - number.wled_tv_speed
                  - number.wled_ghost_speed
                  - number.wled_umbreon_speed
          alias: speed
  mode: parallel
  max: 10
- alias: Kitchen - ECHO Button Toggle Light
  id: "d2cbdbd8-d630-4e27-b66b-a17dcd890eea"
  description: ""
  triggers:
    - entity_id:
        - binary_sensor.m5_echo_assistant_button
      from: null
      to: null
      trigger: state
  conditions: []
  actions:
    - action: light.toggle
      metadata: {}
      target:
        entity_id:
          - light.group_kitchen
  mode: single

# -- needs rework :
- alias: Light Effects
  id: "1725013421680"
  description:
    Updates the WLED effect in the input select based on the current state
    of the light and preset entities.
  triggers:
    - entity_id:
        - light.hexagon_2
      from: "off"
      to: "on"
      enabled: true
      trigger: state
    - entity_id:
        - input_select.wled_group_effect_select
        - input_select.wled_ghost_effect_select
        - input_select.wled_tv_effect_select
        - input_select.wled_desktop_effect_select
        - input_select.wled_umbreon_effect_select
        - input_select.wled_ceiling_effect_select
        - input_select.hexagon_effects
      trigger: state
  conditions:
    - condition: template
      value_template:
        "{{ not states(trigger.entity_id) == 'off' and state_attr(trigger.entity_id,
        'effect') is not none  }}"
      enabled: true
  actions:
    - choose:
        - conditions:
            - condition: template
              value_template:
                "          {{ trigger.entity_id in [\n           'input_select.wled_group_effect_select',\n\n
                \           'input_select.hexagon_effects',\n            'light.hexagon_2'\n
                \         ] }}"
          sequence:
            - choose:
                - conditions:
                    - condition: template
                      value_template:
                        "{{ trigger.entity_id == 'input_select.wled_group_effect_select'
                        }}"
                  sequence:
                    - data:
                        device_ip: 192.168.2.69
                        payload:
                          "{\n  \"seg\": [\n    {\"id\": 0, \"fx\": \"{{ state_attr(trigger.entity_id,
                          'options').index(states(trigger.entity_id)) | int }}\"},\n    {\"id\":
                          1, \"fx\": \"{{ state_attr(trigger.entity_id, 'options').index(states(trigger.entity_id))
                          | int }}\"},\n    {\"id\": 2, \"fx\": \"{{ state_attr(trigger.entity_id,
                          'options').index(states(trigger.entity_id)) | int }}\"},\n    {\"id\":
                          3, \"fx\": \"{{ state_attr(trigger.entity_id, 'options').index(states(trigger.entity_id))
                          | int }}\"},\n    {\"id\": 4, \"fx\": \"{{ state_attr(trigger.entity_id,
                          'options').index(states(trigger.entity_id)) | int }}\"}\n  ]\n}\n"
                      action: shell_command.set_wled_effect
                - conditions:
                    - condition: template
                      value_template:
                        "{{ trigger.entity_id == 'input_select.wled_desktop_effect_select'
                        }}"
                  sequence:
                    - data:
                        device_ip: 192.168.2.69
                        payload:
                          "{\n  \"seg\": [\n    {\"id\": 0, \"fx\": \"{{ state_attr(trigger.entity_id,
                          'options').index(states(trigger.entity_id)) | int }}\"}\n  ]\n}\n"
                      action: shell_command.set_wled_effect
                - conditions:
                    - condition: template
                      value_template:
                        "{{ trigger.entity_id == 'input_select.wled_umbreon_effect_select'
                        }}"
                  sequence:
                    - data:
                        device_ip: 192.168.2.69
                        payload:
                          "{\n  \"seg\": [\n    {\"id\": 1, \"fx\": \"{{ state_attr(trigger.entity_id,
                          'options').index(states(trigger.entity_id)) | int }}\"}\n  ]\n}\n"
                      action: shell_command.set_wled_effect
                - conditions:
                    - condition: template
                      value_template:
                        "{{ trigger.entity_id == 'input_select.wled_ceiling_effect_select'
                        }}"
                  sequence:
                    - data:
                        device_ip: 192.168.2.69
                        payload:
                          "{\n  \"seg\": [\n    {\"id\": 2, \"fx\": \"{{ state_attr(trigger.entity_id,
                          'options').index(states(trigger.entity_id)) | int }}\"}\n  ]\n}\n"
                      action: shell_command.set_wled_effect
                - conditions:
                    - condition: template
                      value_template:
                        "{{ trigger.entity_id == 'input_select.wled_tv_effect_select'
                        }}"
                  sequence:
                    - data:
                        device_ip: 192.168.2.69
                        payload:
                          "{\n  \"seg\": [\n    {\"id\": 3, \"fx\": \"{{ state_attr(trigger.entity_id,
                          'options').index(states(trigger.entity_id)) | int }}\"}\n  ]\n}\n"
                      action: shell_command.set_wled_effect
                - conditions:
                    - condition: template
                      value_template:
                        "{{ trigger.entity_id == 'input_select.wled_ghost_effect_select'
                        }}"
                  sequence:
                    - data:
                        device_ip: 192.168.2.69
                        payload:
                          "{\n  \"seg\": [\n    {\"id\": 4, \"fx\": \"{{ state_attr(trigger.entity_id,
                          'options').index(states(trigger.entity_id)) | int }}\"}\n  ]\n}\n"
                      action: shell_command.set_wled_effect
                - conditions:
                    - condition: template
                      value_template:
                        "{{ trigger.entity_id == 'input_select.hexagon_effects'
                        }}"
                  sequence:
                    - if:
                        - condition: template
                          value_template:
                            '{{is_state(''input_select.hexagon_effects'',"Dancin''
                            Foxx")}}'
                      then:
                        - action: scene.turn_on
                          metadata: {}
                          target:
                            entity_id: scene.govee_to_mqtt_one_click_default_dancing_foxx
                    - action: light.turn_on
                      metadata: {}
                      data:
                        effect: "{{states('input_select.hexagon_effects') }}"
                      target:
                        entity_id: light.hexagon_2
                - conditions:
                    - condition: template
                      value_template:
                        '{{ (trigger.entity_id == ''light.hexagon_2'' and trigger.to_state.state
                        == ''on'') and is_state(''input_select.hexagon_effects'',"Dancin'' Foxx")}}'
                  sequence:
                    - action: scene.turn_on
                      metadata: {}
                      target:
                        entity_id: scene.govee_to_mqtt_one_click_default_dancing_foxx
              enabled: true
        - conditions:
            - condition: template
              value_template:
                "{{ trigger.entity_id =='input_select.wled_preset_helper'

                }}"
          sequence:
            - target:
                entity_id: input_select.wled_ceiling_effect_select
              data:
                option: "{{ state_attr('light.wled_ceiling', 'effect') }}"
              action: input_select.select_option
            - target:
                entity_id: input_select.wled_tv_effect_select
              data:
                option: "{{ state_attr('light.wled_tv', 'effect') }}"
              action: input_select.select_option
            - target:
                entity_id: input_select.wled_desktop_effect_select
              data:
                option: "{{ state_attr('light.wled_desktop', 'effect') }}"
              action: input_select.select_option
            - target:
                entity_id: input_select.wled_umbreon_effect_select
              data:
                option: "{{ state_attr('light.wled_umbreon', 'effect') }}"
              action: input_select.select_option
            - target:
                entity_id: input_select.wled_ghost_effect_select
              data:
                option: "{{ state_attr('light.wled_ghost', 'effect') }}"
              action: input_select.select_option
        - conditions:
            - condition: template
              value_template:
                "          {{ trigger.entity_id in [\n          \n            'input_select.wled_ceiling_effect_select',\n
                \           'input_select.wled_tv_effect_select',\n            'input_select.wled_desktop_effect_select',\n
                \           'input_select.wled_umbreon_effect_select',\n            'input_select.wled_ghost_effect_select',\n
                \          \n           \n          ] }}"
          sequence:
            - data:
                device_ip: 192.168.2.69
                payload:
                  "{\n  \"seg\": [\n    {\"id\": 0, \"fx\": \"{{ state_attr(trigger.entity_id,
                  'options').index(states(trigger.entity_id)) | int }}\"}\n  ]\n}\n"
              action: shell_command.set_wled_effect
        - conditions:
            - condition: template
              value_template:
                "{{ trigger.entity_id in [\n \n  'light.wled_ceiling',\n  'light.wled_tv',\n
                \ 'light.wled_desktop',\n  'light.wled_umbreon',\n  'light.wled_ghost',\n
                \ 'light.hexagon_2'\n] }}\n"
              enabled: false
          sequence:
            - if:
                - condition: template
                  value_template:
                    "{{ not state_attr(trigger.entity_id, 'effect') == 'None'
                    }}"
              then:
                - target:
                    entity_id:
                      "\n{% if trigger.entity_id == 'light.wled_ceiling' %}\n  input_select.wled_ceiling_effect_select\n{%
                      elif trigger.entity_id == 'light.wled_tv' %}\n  input_select.wled_tv_effect_select\n{%
                      elif trigger.entity_id == 'light.wled_desktop' %}\n  input_select.wled_desktop_effect_select\n{%
                      elif trigger.entity_id == 'light.wled_umbreon' %}\n  input_select.wled_umbreon_effect_select\n{%
                      elif trigger.entity_id == 'light.wled_ghost' %}\n  input_select.wled_ghost_effect_select\n{%
                      elif trigger.entity_id == 'light.hexagon_2' %}\n  input_select.hexagon_effects
                      \     \n{% endif %}\n"
                  data:
                    option: "{{ state_attr(trigger.entity_id, 'effect') }}"
                  action: input_select.select_option
              enabled: false
  mode: parallel
- alias: Cuddle Cave - Switch
  id: "1749045323773"
  description: "When pressing Wall Switch will behave differently depending on rooms current light state.
                - when any light is on, will save which and switch all off
                - when all lights are off, will restore previously saved state
                - will failsafe switch main light on, when in looping all-off states"
  triggers:
    - trigger: state
      entity_id:
        - switch.cave_logical # logical switch toggled by app actions etc.
      id: logical
    - trigger: state
      entity_id:
        - binary_sensor.cave_physical # physical wall switch state
      id: physical
        
  conditions: []
  actions:
    - choose:
        - conditions:
            - condition: template
              value_template: >
                {{ trigger.id=='physical' }}
          sequence:
            - action: switch.toggle
              target:
                  entity_id: switch.cave_logical
        - conditions:
            - condition: template
              value_template: >
                {{ is_state('light.group_cave','on') }}
          sequence:
      
            - action: saver.save_state
              data:
                entity_id: |-
                  {%- set list= expand('light.group_cave') | map(attribute='entity_id') | list -%}
                  {%-for i in list-%}
                  {{i}}{{',' if not loop.last else ''}}
                  {%-endfor-%}
            - action: light.turn_off
              target:
                entity_id: light.group_cave
              data:
                transition: 2
      default:
        - repeat:
            for_each: >-
              {{ expand('light.group_cave') | map(attribute='entity_id') | list }}
            sequence:
              - if:
                  - condition: template
                    value_template: >-
                      {{ saver_entity(repeat.item) == 'on' }}
                then:
                  - action: light.turn_on
                    target:
                        entity_id: "{{ repeat.item }}"
              - condition: template
                value_template: >-
                  {{ saver_entity(repeat.item) != None }}                        
              - action: saver.delete
                data:
                  entity_id: >-
                    {{ repeat.item }}          
        - condition: template
          value_template: >-
            {{ is_state('light.group_cave','off') }}
        - action: light.turn_on
          target:
            entity_id: light.cave_main         
  mode: queued
  max: 4
- alias: Scenes - Load Save Sensors
  id: "1737129893335"
  description: ""
  triggers:
    - trigger: state
      entity_id:
        - input_select.scene_saves
      to: <Load Scenes>
  conditions: []
  actions:
    - 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
  mode: single
- alias: Global Fade
  id: "1727990814546"
  description: ""
  triggers:
    - trigger: state
      entity_id:
        - input_number.fade_target
      from:
      to:
      for:
        hours: 0
        minutes: 0
        seconds: 1
    - trigger: state
      entity_id:
        - light.group_lucy
      attribute: brightness
      for:
        hours: 0
        minutes: 0
        seconds: 5
  conditions: []
  actions:
    - if:
        - condition: template
          value_template: "{{trigger.entity_id=='input_number.fade_target'}}"
      then:
        - action: script.automatic_lights_fading
          metadata: {}
          data: {}
      else:
        - action: script.update_fader_value
          metadata: {}
          data: {}
  mode: single
- alias: Change WLED Color Palette
  id: "1728245150035"
  description: ""
  triggers:
    - trigger: state
      entity_id:
        - input_select.wled_tv_color_palettes
        - input_select.wled_ghost_color_palettes
        - input_select.wled_desktop_color_palettes
        - input_select.wled_umbreon_color_palettes
        - input_select.wled_ceiling_color_palettes
        - input_select.wled_color_palettes
  conditions: []
  actions:
    - action: script.notify
      metadata: {}
      data:
        duration:
          hours: 0
          minutes: 0
          seconds: 5
        silent: false
        content:
          "{{state_attr(trigger.entity_id,'friendly_name')}} changed to {{states(trigger.entity_id)}}
          (id:  {{state_attr('sensor.color_palettes', states(trigger.entity_id))}})"
      enabled: false
    - if:
        - condition: template
          value_template: "{{trigger.entity_id=='input_select.wled_color_palettes'}}"
      then:
        - action: shell_command.set_wled_palette
          data:
            seg_id: 0
            palette_id: "{{state_attr('sensor.color_palettes', states(trigger.entity_id))}}"
          enabled: true
        - action: shell_command.set_wled_palette
          data:
            seg_id: 1
            palette_id: "{{state_attr('sensor.color_palettes', states(trigger.entity_id))}}"
          enabled: true
        - action: shell_command.set_wled_palette
          data:
            seg_id: 2
            palette_id: "{{state_attr('sensor.color_palettes', states(trigger.entity_id))}}"
          enabled: true
        - action: shell_command.set_wled_palette
          data:
            seg_id: 3
            palette_id: "{{state_attr('sensor.color_palettes', states(trigger.entity_id))}}"
          enabled: true
        - action: shell_command.set_wled_palette
          data:
            seg_id: 4
            palette_id: "{{state_attr('sensor.color_palettes', states(trigger.entity_id))}}"
          enabled: true
        - action: shell_command.set_wled_palette
          data:
            seg_id: 5
            palette_id: "{{state_attr('sensor.color_palettes', states(trigger.entity_id))}}"
          enabled: true
      else:
        - variables:
            id:
              "{%if trigger.entity_id=='input_select.wled_desktop_color_palettes'%}
              0 {%elif trigger.entity_id=='input_select.wled_umbreon_color_palettes'%}
              1 {%elif trigger.entity_id=='input_select.wled_ceiling_color_palettes'%}
              2 {%elif trigger.entity_id=='input_select.wled_tv_color_palettes'%} 3
              {%elif trigger.entity_id=='input_select.wled_ghost_color_palettes'%} 4
              {%endif%}

              "
        - action: shell_command.set_wled_palette
          data:
            seg_id: "{{id}}"
            palette_id: "{{state_attr('sensor.color_palettes', states(trigger.entity_id))}}"
          enabled: true
  mode: single
- alias: Effect Presets
  id: "1728311633541"
  description: ""
  triggers:
    - trigger: state
      entity_id:
        - input_select.light_scenes
        - input_select.presets_ceiling
        - input_select.presets_hexagon
        - input_select.presets_wled
      from:
      to:
      alias: Effect Presets Selected
  conditions:
    - condition: template
      value_template: " {{trigger.to_state.state != 'None'}}"
  actions:
    - choose:
        - conditions:
            - condition: template
              value_template: "{{trigger.entity_id == 'input_select.light_scenes'}}"
          sequence:
            - action: script.notify
              metadata: {}
              data:
                duration:
                  hours: 0
                  minutes: 0
                  seconds: 3
                play_sound: false
                show_popup: false
                title: "Activating Preset: {{states('input_select.light_scenes')}}"
                id: light_scene
                content: activation initiated...
              enabled: true
            - action: input_select.select_option
              metadata: {}
              data:
                option: "{{states('input_select.light_scenes')}}"
              target:
                entity_id:
                  - input_select.presets_hexagon
                  - input_select.presets_wled
            - delay:
                hours: 0
                minutes: 0
                seconds: 2
                milliseconds: 0
            - action: script.notify
              metadata: {}
              data:
                duration:
                  hours: 0
                  minutes: 0
                  seconds: 5
                show_popup: false
                play_sound: false
                id: light_scene
                title: Light Scene
                content: "{{states(trigger.entity_id)}} activated."
            - action: select.select_option
              metadata: {}
              data:
                option: "{{states('input_select.light_scenes')}}"
              target:
                entity_id:
                  - select.lucy_s_ceiling_light_effect
          alias: Light Scene
        - conditions:
            - condition: template
              value_template: "{{trigger.entity_id == 'input_select.presets_hexagon'}}"
          sequence:
            - action: script.set_preset_hexagon
              data: {}
          alias: Hexagon
        - conditions:
            - condition: template
              value_template: "{{trigger.entity_id == 'input_select.presets_ceiling'}}"
          sequence:
            - action: script.lucy_ceiling_gradient_effect
              data:
                preset: "{{states(trigger.entity_id)}}"
          alias: Ceiling
        - conditions:
            - condition: template
              value_template: "{{trigger.entity_id == 'input_select.presets_wled'}}"
              alias: WLED
          sequence:
            - action: script.custom_wled_preset
              data:
                preset: "{{states(trigger.entity_id)}}"
            - delay:
                hours: 0
                minutes: 0
                seconds: 1
                milliseconds: 0
            - action: input_select.select_option
              metadata: {}
              data:
                option:
                  "{{state_attr('sensor.wled_palette_preset',states('input_select.light_scenes'))
                  }}"
              target:
                entity_id:
                  - input_select.wled_color_palettes
  mode: parallel
  max: 10
- alias: Update State Sensors
  id: "1731046764588"
  description: ""
  triggers:
    - trigger: time_pattern
      minutes: /5
      enabled: false
    - trigger: state
      entity_id:
        - sensor.hexagon_light_status
        - sensor.bathroom_mirror_light_status
        - sensor.lucy_ceiling_light_status
        - sensor.cuddle_cave_light_status
        - sensor.floor_light_faelis_status
        - sensor.floor_light_kitchen_status
        - sensor.floor_light_lucy_status
        - sensor.floor_light_entrance_status
  conditions: []
  actions:
    - variables:
        sensors:
          "{% set sensors = states.sensor | selectattr('entity_id', 'search',
          '_attributes$') | rejectattr('entity_id', 'search', 'master')| map(attribute='entity_id')
          | list %} {{ sensors }}

          "
      enabled: false
    - repeat:
        sequence:
          - variables:
              sensor: "{{ repeat.item }}"
              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
            alias: Get General Device State
          - 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
          - 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
          - action: rest_command.govee_api_devices
            data: {}
            response_variable: snapshots
          - action: script.govee_get_states
            metadata: {}
            data:
              sensor: "{{ repeat.item }}"
          - variables:
              last_updated: "{{ now() | string }}"
              value:
                "{% if response.content.payload.capabilities|length > 1\n      and
                response.content.payload.capabilities[1].state is defined\n      and response.content.payload.capabilities[1].state.value|is_number
                %}\n  {{ 'on' if response.content.payload.capabilities[1].state.value
                == 1 else 'off' }}\n{% else %}\n  {{ state_attr(sensor, 'state') or 'off'
                }}\n{% endif %}\n"
              state: "{{ value }}"
              entity_id: "{{ sensor }}"
              online:
                "{% if response.content.payload.capabilities|length > 0\n      and
                response.content.payload.capabilities[0].state is defined %}\n  {{ response.content.payload.capabilities[0].state.value
                }}\n{% else %}\n  {{ state_attr(sensor, 'online') or 'unknown' }}\n{%
                endif %}\n"
              brightness:
                "{% set fallback = state_attr(sensor, 'brightness') or 0 %}
                {% if response.content.payload.capabilities|length > 2\n      and response.content.payload.capabilities[2].state
                is defined\n      and (response.content.payload.capabilities[2].state.value|is_number)
                %}\n  {{ response.content.payload.capabilities[2].state.value }}\n{% else
                %}\n  {{ fallback }}\n{% endif %}\n"
              color_rgb:
                "{% set fallback = state_attr(sensor, 'color_rgb') %} {% if response.content.payload.capabilities|length
                > 5\n      and response.content.payload.capabilities[5].state is defined\n
                \     and response.content.payload.capabilities[5].state.value|is_number\n
                \     and response.content.payload.capabilities[5].state.value != 0 %}\n
                \ {{ response.content.payload.capabilities[5].state.value }}\n{% else
                %}\n  {{ fallback }}\n{% endif %}\n"
              color_temp:
                "{% set fallback = state_attr(sensor, 'color_temp') %} {% if
                (\n    response.content.payload.capabilities|length > 6 and\n    response.content.payload.capabilities[6].state
                is defined and\n    response.content.payload.capabilities[6].state.value|is_number
                and\n    response.content.payload.capabilities[6].state.value != 0\n  )\n%}\n
                \ {{ (1000000 / response.content.payload.capabilities[6].state.value)
                | round(0) | int }}\n{% else %}\n  {{ fallback }}\n{% endif %}\n"
              color_temp_kelvin:
                "{% set fallback = state_attr(sensor, 'color_temp_kelvin')
                %} {% if (\n    response.content.payload.capabilities|length > 6 and\n
                \   response.content.payload.capabilities[6].state is defined and\n    response.content.payload.capabilities[6].state.value|is_number
                and\n    response.content.payload.capabilities[6].state.value != 0\n  )\n%}\n
                \ {{ response.content.payload.capabilities[6].state.value | round(0) |
                int }}\n{% else %}\n  {{ fallback }}\n{% endif %}\n"
              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 +\n    lightscenes_dict.keys() | list ) | unique | sort }}\n"
          - if:
              - condition: template
                value_template:
                  "{{\n  (\n    color_temp_kelvin != state_attr(sensor, 'color_temp_kelvin')\n
                  \   or color_temp != state_attr(sensor, 'color_temp')\n    or brightness
                  != state_attr(sensor, 'brightness')\n    or color_rgb != state_attr(sensor,
                  'color_rgb')\n    or state != state_attr(sensor, 'state')\n    or online
                  != state_attr(sensor, 'online')\n    or snapshot_dict != state_attr(sensor,
                  'snapshots')\n    or diyscenes_dict != state_attr(sensor, 'diy_scenes')\n
                  \   or lightscenes_dict != state_attr(sensor, 'light_scenes')\n    or
                  effect_list != state_attr(sensor, 'effect_list')\n  )\n}}\n"
            then:
              - action: variable.update_sensor
                metadata: {}
                data:
                  replace_attributes: false
                  attributes:
                    online: "{{ online }}"
                    state: "{{ state }}"
                    brightness: "{{ brightness }}"
                    color_rgb: "{{ color_rgb }}"
                    color_temp: "{{ color_temp }}"
                    color_temp_kelvin: "{{ color_temp_kelvin }}"
                    snapshots: "{{ snapshot_dict }}"
                    diy_scenes: "{{ diyscenes_dict }}"
                    light_scenes: "{{ lightscenes_dict }}"
                    effect_list: "{{ effect_list }}"
                    last_updated: "{{ last_updated }}"
                  value: "{{ value }}"
                target:
                  entity_id: "{{ sensor }}"
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 150
        for_each: "{{ sensors }}"
      enabled: false
    - sequence:
        - variables:
            sensor: "{{ trigger.entity_id }}"
            sku: "{{state_attr(sensor,'info')['sku']}}

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

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

              "
            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
              +\n    lightscenes_dict.keys() | list ) | unique | sort }}\n    \n"
        - 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
          alias: Get General Device State
        - 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
        - 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
        - action: rest_command.govee_api_devices
          data: {}
          response_variable: snapshots
        - action: script.govee_get_states
          metadata: {}
          data:
            sensor: "{{ sensor }}"
        - variables:
            last_updated: "{{ now() | string }}"
            value:
              "{% if response.content.payload.capabilities|length > 1\n      and
              response.content.payload.capabilities[1].state is defined\n      and response.content.payload.capabilities[1].state.value|is_number
              %}\n  {{ 'on' if response.content.payload.capabilities[1].state.value ==
              1 else 'off' }}\n{% else %}\n  {{ state_attr(sensor, 'state') or 'off' }}\n{%
              endif %}\n"
            state: "{{ value }}"
            online:
              "{% if response.content.payload.capabilities|length > 0\n      and
              response.content.payload.capabilities[0].state is defined %}\n  {{ response.content.payload.capabilities[0].state.value
              }}\n{% else %}\n  {{ state_attr(sensor, 'online') or 'unknown' }}\n{% endif
              %}\n"
            brightness:
              "{% set fallback = state_attr(sensor, 'brightness') or 0 %} {%
              if response.content.payload.capabilities|length > 2\n      and response.content.payload.capabilities[2].state
              is defined\n      and (response.content.payload.capabilities[2].state.value|is_number)
              %}\n  {{ response.content.payload.capabilities[2].state.value }}\n{% else
              %}\n  {{ fallback }}\n{% endif %}\n"
            color_rgb:
              "{% set fallback = state_attr(sensor, 'color_rgb') %} {% if response.content.payload.capabilities|length
              > 5\n      and response.content.payload.capabilities[5].state is defined\n
              \     and response.content.payload.capabilities[5].state.value|is_number\n
              \     and response.content.payload.capabilities[5].state.value != 0 %}\n
              \ {{ response.content.payload.capabilities[5].state.value }}\n{% else %}\n
              \ {{ fallback }}\n{% endif %}\n"
            color_temp:
              "{% set fallback = state_attr(sensor, 'color_temp') %} {% if (\n
              \   response.content.payload.capabilities|length > 6 and\n    response.content.payload.capabilities[6].state
              is defined and\n    response.content.payload.capabilities[6].state.value|is_number
              and\n    response.content.payload.capabilities[6].state.value != 0\n  )\n%}\n
              \ {{ (1000000 / response.content.payload.capabilities[6].state.value) |
              round(0) | int }}\n{% else %}\n  {{ fallback }}\n{% endif %}\n"
            color_temp_kelvin:
              "{% set fallback = state_attr(sensor, 'color_temp_kelvin')
              %} {% if (\n    response.content.payload.capabilities|length > 6 and\n    response.content.payload.capabilities[6].state
              is defined and\n    response.content.payload.capabilities[6].state.value|is_number
              and\n    response.content.payload.capabilities[6].state.value != 0\n  )\n%}\n
              \ {{ response.content.payload.capabilities[6].state.value | round(0) | int
              }}\n{% else %}\n  {{ fallback }}\n{% endif %}\n"
            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
              +\n    lightscenes_dict.keys() | list ) | unique | sort }}\n"
        - if:
            - condition: template
              value_template:
                "{{\n  (\n    color_temp_kelvin != state_attr(sensor, 'color_temp_kelvin')\n
                \   or color_temp != state_attr(sensor, 'color_temp')\n    or brightness
                != state_attr(sensor, 'brightness')\n    or color_rgb != state_attr(sensor,
                'color_rgb')\n    or state != state_attr(sensor, 'state')\n    or online
                != state_attr(sensor, 'online')\n    or snapshot_dict != state_attr(sensor,
                'snapshots')\n    or diyscenes_dict != state_attr(sensor, 'diy_scenes')\n
                \   or lightscenes_dict != state_attr(sensor, 'light_scenes')\n    or effect_list
                != state_attr(sensor, 'effect_list')\n  )\n}}\n"
          then:
            - action: variable.update_sensor
              metadata: {}
              data:
                replace_attributes: false
                attributes:
                  online: "{{ online }}"
                  state: "{{ state }}"
                  brightness: "{{ brightness }}"
                  color_rgb: "{{ color_rgb }}"
                  color_temp: "{{ color_temp }}"
                  color_temp_kelvin: "{{ color_temp_kelvin }}"
                  snapshots: "{{ snapshot_dict }}"
                  diy_scenes: "{{ diyscenes_dict }}"
                  light_scenes: "{{ lightscenes_dict }}"
                  effect_list: "{{ effect_list }}"
                  last_updated: "{{ last_updated }}"
                value: "{{ value }}"
              target:
                entity_id: "{{ sensor }}"
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 150
  mode: single
- alias: Refresh Global Fader Brightness
  id: "1729042659913"
  description: ""
  triggers:
    - trigger: state
      entity_id:
        - light.real_light_entities
      attribute: brightness
      for:
        hours: 0
        minutes: 0
        seconds: 5
  conditions: []
  actions:
    - action: automation.turn_off
      target:
        entity_id:
          - automation.combined_brightness_change
      data:
        stop_actions: true
    - action: input_number.set_value
      metadata: {}
      data:
        value: "{{state_attr('light.real_light_entities','brightness') | int | default(0)}}"
      target:
        entity_id: input_number.fade_target
    - delay:
        hours: 0
        minutes: 0
        seconds: 1
        milliseconds: 0
    - action: automation.turn_on
      target:
        entity_id:
          - automation.combined_brightness_change
      data: {}
  mode: single
- alias: Floor Lights Settings
  id: "1729128250033"
  description: ""
  triggers:
    - entity_id:
        - input_number.floor_light_entrance_brightness
        - input_number.floor_light_entrance_color_temperature
        - input_number.floor_light_faelis_color_temperature
        - input_number.floor_light_kitchen_brightness
        - input_number.floor_light_faelis_brightness
        - input_number.floor_light_kitchen_color_temperature
        - input_number.floor_light_lucy_brightness
        - input_number.floor_light_lucy_color_temperature
        - input_number.floor_lights_group_brightness
        - input_number.floor_lights_group_color_temperature
      for:
        hours: 0
        minutes: 0
        seconds: 1
      trigger: state
  conditions: []
  actions:
    - choose:
        - conditions:
            - alias: Group Brightness
              condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.floor_lights_group_brightness'
                }}"
          sequence:
            - data:
                value: "{{ states('input_number.floor_lights_group_brightness') }}"
              target:
                entity_id:
                  - input_number.floor_light_entrance_brightness
                  - input_number.floor_light_faelis_brightness
                  - input_number.floor_light_lucy_brightness
                  - input_number.floor_light_kitchen_brightness
              action: input_number.set_value
        - conditions:
            - condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.floor_light_entrance_brightness'
                }}"
          sequence:
            - data:
                payload:
                  "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
                  \"H600D\",\n    \"device\": \"28:3D:E8:06:90:06:40:C4\",\n    \"capability\":
                  {\n      \"type\": \"devices.capabilities.range\",\n      \"instance\":
                  \"brightness\",\n      \"value\": {{ states('input_number.floor_light_entrance_brightness')
                  }}\n    }\n  }\n}"
              action: rest_command.govee_api_post
          alias: Floor Entrance Brightness
        - conditions:
            - condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.floor_light_faelis_brightness'
                }}"
          sequence:
            - data:
                payload:
                  "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
                  \"H600D\",\n    \"device\": \"0C:0F:E8:06:90:06:3F:4C\",\n    \"capability\":
                  {\n      \"type\": \"devices.capabilities.range\",\n      \"instance\":
                  \"brightness\",\n      \"value\": {{ states('input_number.floor_light_faelis_brightness')
                  }}\n    }\n  }\n}"
              action: rest_command.govee_api_post
          alias: Floor Faelis Brightness
        - conditions:
            - condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.floor_light_kitchen_brightness'
                }}"
          sequence:
            - data:
                payload:
                  "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
                  \"H600D\",\n    \"device\": \"ED:8B:E8:06:90:06:14:C0\",\n    \"capability\":
                  {\n      \"type\": \"devices.capabilities.range\",\n      \"instance\":
                  \"brightness\",\n      \"value\": {{ states('input_number.floor_light_kitchen_brightness')
                  }}\n    }\n  }\n}"
              action: rest_command.govee_api_post
          alias: Floor Kitchen Brightness
        - conditions:
            - alias: Floor Lucy Brightness
              condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.floor_light_lucy_brightness'
                and states('light.floor_light_lucy') == 'on' }}"
          sequence:
            - data:
                payload:
                  "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
                  \"H600D\",\n    \"device\": \"EF:C2:E8:06:90:06:40:A0\",\n    \"capability\":
                  {\n      \"type\": \"devices.capabilities.range\",\n      \"instance\":
                  \"brightness\",\n      \"value\": {{ states('input_number.floor_light_lucy_brightness')
                  }}\n    }\n  }\n}"
              action: rest_command.govee_api_post
        - conditions:
            - alias: Group Color Temperature
              condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.floor_lights_group_color_temperature'
                }}"
          sequence:
            - data:
                value:
                  "{{ states('input_number.floor_lights_group_color_temperature')
                  }}"
              target:
                entity_id:
                  - input_number.floor_light_entrance_color_temperature
                  - input_number.floor_light_faelis_color_temperature
                  - input_number.floor_light_lucy_color_temperature
                  - input_number.floor_light_kitchen_color_temperature
              action: input_number.set_value
        - conditions:
            - alias: Floor Entrance Color Temperature
              condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.floor_light_entrance_color_temperature'
                and states('light.floor_light_entrance') == 'on' }}"
          sequence:
            - data:
                payload:
                  "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
                  \"H600D\",\n    \"device\": \"28:3D:E8:06:90:06:40:C4\",\n    \"capability\":
                  {\n      \"type\": \"devices.capabilities.color_setting\",\n      \"instance\":
                  \"colorTemperatureK\",\n      \"value\": {{ states('input_number.floor_light_entrance_color_temperature')
                  }}\n    }\n  }\n}"
              action: rest_command.govee_api_post
        - conditions:
            - alias: Floor Faelis Color Temperature
              condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.floor_light_faelis_color_temperature'
                and states('light.floor_light_faelis') == 'on' }}"
          sequence:
            - data:
                payload:
                  "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
                  \"H600D\",\n    \"device\": \"0C:0F:E8:06:90:06:3F:4C\",\n    \"capability\":
                  {\n      \"type\": \"devices.capabilities.color_setting\",\n      \"instance\":
                  \"colorTemperatureK\",\n      \"value\": {{ states('input_number.floor_light_faelis_color_temperature')
                  }}\n    }\n  }\n}"
              action: rest_command.govee_api_post
        - conditions:
            - alias: Floor Kitchen Color Temperature
              condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.floor_light_kitchen_color_temperature'
                and states('light.floor_light_kitchen') == 'on' }}"
          sequence:
            - data:
                payload:
                  "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
                  \"H600D\",\n    \"device\": \"ED:8B:E8:06:90:06:14:C0\",\n    \"capability\":
                  {\n      \"type\": \"devices.capabilities.color_setting\",\n      \"instance\":
                  \"colorTemperatureK\",\n      \"value\": {{ states('input_number.floor_light_kitchen_color_temperature')
                  }}\n    }\n  }\n}"
              action: rest_command.govee_api_post
        - conditions:
            - alias: Floor Lucy Color Temperature
              condition: template
              value_template:
                "{{ trigger.entity_id == 'input_number.floor_light_lucy_color_temperature'
                and states('light.floor_light_lucy') == 'on' }}"
          sequence:
            - data:
                payload:
                  "{\n  \"requestId\": \"uuid\",\n  \"payload\": {\n    \"sku\":
                  \"H600D\",\n    \"device\": \"EF:C2:E8:06:90:06:40:A0\",\n    \"capability\":
                  {\n      \"type\": \"devices.capabilities.color_setting\",\n      \"instance\":
                  \"colorTemperatureK\",\n      \"value\": {{ states('input_number.floor_light_lucy_color_temperature')
                  }}\n    }\n  }\n}"
              action: rest_command.govee_api_post
  mode: parallel
  max: 10
