- alias: Set duration
  id: "1728899371987"
  description: ""
  triggers:
    - trigger: state
      entity_id:
        - input_number.timer_seconds
        - input_number.timer_hours
        - input_number.timer_minutes
      for:
        hours: 0
        minutes: 0
        seconds: 1
  conditions: []
  actions:
    - action: input_number.set_value
      metadata: {}
      data:
        value:
          "{% set sec = states('input_number.timer_seconds') | int %} {% set
          min = states('input_number.timer_minutes') | int %} {% set h = states('input_number.timer_hours')
          | int %} {% set duration = sec + min * 60 + h * 60 * 60 %} {{ duration }}

          "
      target:
        entity_id: input_number.timer_duration
  mode: single

- id: "1731586186613"
  alias: Voice Assist
  description: ""
  triggers:
    - trigger: conversation
      command:
        - Fuchslampe weiß
        - Fuchslampe auf weiß
        - Stelle die Fuchslampe auf weiß
        - Deckenlicht weiß
        - Hell bitte
        - Weißes Licht bitte
        - Weißes Licht
        - Lichtfarbe Weiß
      id: ceiling_white
    - trigger: conversation
      command:
        - UV Licht bitte
        - UV bitte
        - UV Licht
        - "UV "
        - Schwarzlicht bitte
        - Schwarzlicht
      id: scene_uv
    - trigger: conversation
      command:
        - Schwebender Fuchs
        - Schwebe Fuchs
      id: scene_floating_foxx
    - trigger: conversation
      command:
        - Tanzender Fuchs
        - Tanz Fuchs
      id: scene_dancing_foxx
    - trigger: conversation
      command:
        - Katze müde
      id: scene_katzi_müdi
    - trigger: conversation
      command:
        - "Guten Morgen "
        - Aufstehen
        - Default
        - Lucy's Licht an
      id: wake_up
    - trigger: conversation
      command:
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {minute} Minute[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {second} Sekunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {hour} Stunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {hour} Stunde[n]
          [und] {minute} Minute[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {minute} Minute[n]
          [und] {second} Sekunde[n]"
      id: kitchen_timer_start
      enabled: false
    - trigger: conversation
      command:
        - Wie lange [läuft|geht] der [Küchentimer|Timer] noch
        - Verbleibende Zeit [für den|des] [Küchentimer[s]|Timer[s]]
        - Wie viel Zeit hat der [Küchentimer|Timer] noch
        - "[Status] [des] [Küchentimer[s]|Timer[s]] [Status]"
      id: kitchen_timer_status
      enabled: false
    - trigger: conversation
      command:
        - "[Stoppe] [den] [Küchentimer|Timer] [stop[pen]]"
        - Küchentimer stoppen
        - Beende den Küchentimer
        - Cancel Küchentimer
        - "[stoppe] [den] Timer [stop|stoppen]"
      id: kitchen_timer_cancel
      enabled: false
    - trigger: conversation
      command:
        - "[Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {duration}"
      id: kitchen_timer_start
      enabled: false
  conditions: []
  actions:
    - choose:
        - conditions:
            - condition: trigger
              id:
                - ceiling_white
          sequence:
            - action: light.turn_on
              metadata: {}
              data:
                kelvin: 4442
                brightness_pct: 74
              target:
                entity_id: light.lucy_ceiling
            #- set_conversation_response: "Erledigt      "
        - conditions:
            - condition: trigger
              id:
                - scene_uv
          sequence:
            - action: switch.toggle
              metadata: {}
              target:
                entity_id: switch.ultraviolet_stateful_scene
              data: {}
            #- set_conversation_response: "Erledigt      "
        - conditions:
            - condition: trigger
              id:
                - scene_floating_foxx
          sequence:
            - action: switch.toggle
              metadata: {}
              data: {}
              target:
                entity_id: switch.musicfx_stateful_scene
            #- set_conversation_response: "Erledigt      "
        - conditions:
            - condition: trigger
              id:
                - scene_floating_foxx
          sequence:
            # - set_conversation_response: "Erledigt      "
            - action: input_select.select_option
              metadata: {}
              data:
                option: Floating Foxx
              target:
                entity_id: input_select.light_scenes
        - conditions:
            - condition: trigger
              id:
                - scene_katzi_müdi
          sequence:
            - action: script.global_light_control
              metadata: {}
              data: {}
            #- set_conversation_response: Katzi schlafi
        - conditions:
            - condition: trigger
              id:
                - wake_up
          sequence:
            - action: switch.turn_on
              metadata: {}
              data: {}
              target:
                entity_id:
                  - switch.default_stateful_scene
        - conditions:
            - condition: trigger
              id: kitchen_timer_start
          sequence:
            - data:
                duration:
                  '{% set hour = trigger.slots.hour | default(0) | int %} {% set
                  minute = trigger.slots.minute | default(0) | int %} {% set second = trigger.slots.second
                  | default(0) | int %} {{ "%02d:%02d:%02d" | format(hour, minute, second)
                  }}

                  '
              target:
                entity_id: timer.kitchen_timer
              action: timer.start
            #- set_conversation_response:
            #    "Timer gestartet für {{ trigger.slots.hour| default(0)
            #    }} Stunden {{ trigger.slots.minute| default(0) }} Minuten {{ trigger.slots.second|
            #   default(0) }} Sekunden.

          #      "
        - conditions:
            - condition: trigger
              id: kitchen_timer_status
          sequence:
            - choose:
                - conditions:
                    - condition: state
                      entity_id: timer.kitchen_timer
                      state: active
                  sequence:
                    - variables:
                        remaining:
                          "{% set t = state_attr('timer.kitchen_timer','remaining')
                          %} {% if t %}\n  {% set hours = t.total_seconds() // 3600 %}\n  {%
                          set minutes = (t.total_seconds() % 3600) // 60 %}\n  {% set seconds
                          = t.total_seconds() % 60 %}\n  {% if hours > 0 %}\n    {{ hours }}
                          Stunden {{ minutes }} Minuten {{ seconds }} Sekunden\n  {% elif minutes
                          > 0 %}\n    {{ minutes }} Minuten {{ seconds }} Sekunden\n  {% else
                          %}\n    {{ seconds }} Sekunden\n  {% endif %}\n{% else %}\n  unbekannt\n{%
                          endif %}\n"
                  #  - set_conversation_response: "Verbleibende Zeit: {{ remaining }}."
              # default:
              #  - set_conversation_response: Aktuell läuft kein Timer.
        - conditions:
            - condition: trigger
              id: kitchen_timer_cancel
          sequence:
            - target:
                entity_id: timer.kitchen_timer
              action: timer.cancel
              data: {}
          #   - set_conversation_response: Timer wurde gestoppt.
      enabled: true
  mode: single

- id: "1747753322941"
  alias: Keep Playing Media
  description: ""
  triggers:
    - trigger: state
      entity_id:
        - media_player.vlc_foxxbook_2
        - media_player.spotify_player
        - media_player.vlc_cuddle_cave_2
        - media_player.vlc_lucy_s_room_2
      from: playing
      to: idle
  conditions:
    - condition: state
      entity_id: input_boolean.vlc_foxxbook_keep_playing
      state: "on"
  actions:
    - action: media_player.media_play
      metadata: {}
      data: {}
      target:
        entity_id: "{{trigger.entity_id}}"
  mode: single
- id: "1748953936069"
  alias: Kitchen Display
  description: ""
  triggers:
    - trigger: event
      event_type: timer.started
      event_data:
        entity_id: timer.kitchen_timer
      id: timer_started
    - trigger: event
      event_type: timer.finished
      event_data:
        entity_id: timer.kitchen_timer
      id: timer_finished
      enabled: true
    - trigger: time_pattern
      seconds: /10
      enabled: true
    - trigger: state
      entity_id:
        - timer.kitchen_timer
      to: active
      from:
      id: timer_running
      enabled: false
    - trigger: conversation
      command:
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {minute} Minute[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] [eine] {second}
          Sekunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] [eine] {hour}
          Stunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] [eine] {hour}
          Stunde[n] [und] {minute} Minute[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] [eine] {minute}
          Minute[n] [und] {second} Sekunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {minute} Minute[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {second} Sekunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {hour} Stunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {hour} Stunde[n]
          [und] {minute} Minute[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {minute} Minute[n]
          [und] {second} Sekunde[n]"
      id: kitchen_timer_start
      enabled: false
    - trigger: conversation
      command:
        - Wie lange [läuft|geht] der [Küchentimer|Timer] noch
        - Verbleibende Zeit [für den|des] [Küchentimer[s]|Timer[s]]
        - Wie viel Zeit hat der [Küchentimer|Timer] noch
        - "[Status] [des] [Küchentimer[s]|Timer[s]] [Status]"
      id: kitchen_timer_status
    - trigger: conversation
      command:
        - "[Stoppe] [den] [Küchentimer|Timer] [stop[pen]]"
        - Küchentimer stoppen
        - Beende den Küchentimer
        - Cancel Küchentimer
        - "[stoppe] [den] Timer [stop|stoppen]"
      id: kitchen_timer_cancel
  conditions: []
  actions:
    - choose:
        - conditions:
            - condition: trigger
              id: kitchen_timer_cancel
          sequence:
            - target:
                entity_id: timer.kitchen_timer
              action: timer.cancel
              data: {}
          #  - set_conversation_response: Timer wurde gestoppt.
        - conditions:
            - condition: trigger
              id: kitchen_timer_status
          sequence:
            - choose:
                - conditions:
                    - condition: state
                      entity_id: timer.kitchen_timer
                      state: active
                  sequence:
                    - variables:
                        remaining:
                          "{% set remaining = (as_datetime(state_attr('timer.kitchen_timer','finishes_at'))
                          - now()).total_seconds() | int %}\n{% set hours = remaining // 3600
                          %}\n{% set minutes = (remaining % 3600) // 60 %}\n{% set seconds =
                          remaining % 60 %}\n\n{% if remaining < 0 %}\n  Abgelaufen\n{% else
                          %}\n  {%- if hours > 0 -%}\n    {{ hours }} Stunde{% if hours > 1
                          %}n{% endif %}\n  {%- endif -%}\n  {%- if minutes > 0 or hours > 0
                          -%}\n     {{ minutes }} Minute{% if minutes != 1 %}n{% endif %} \n
                          \ {%- endif -%}\n  {{ seconds }} Sekunde{% if seconds != 1 %}n{% endif
                          %}\n{% endif %}\n"
                #    - set_conversation_response: "Verbleibende Zeit: {{ remaining }}."
              # default:
              #  - set_conversation_response: Aktuell läuft kein Timer.
        - conditions:
            - condition: trigger
              id:
                - timer_started
          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"
              enabled: false
            - 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: false
            - action: mqtt.publish
              data:
                topic: kitchen/hub/buzzer
                qos: "0"
                payload: "false"
              enabled: false
            - 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
            - action: script.alarm_ring
              metadata: {}
              data: {}
      enabled: true
      default:
        - variables:
            seconds: "{{ now().second }}"
            time: "{{ now().strftime('%H:%M') }}"
            temp:
              "{{ state_attr('weather.forecast_home','temperature')|round(0)|string
              ~ ' C' }}"
            uv:
              "{{ state_attr('weather.forecast_home','uv_index') | round(1) | string
              }}"
            wind:
              "{{ state_attr('weather.forecast_home','wind_speed') | round(0)
              | string ~ ' km/h' }}"
            humidity:
              "{{ state_attr('weather.forecast_home','humidity') | round(0)
              ~ ' %' }}"
            state: "{{ states('weather.forecast_home') | title }}"
        - action: mqtt.publish
          data:
            topic: kitchen/hub/digiclock/text
            payload:
              "{% if is_state('input_boolean.kitchen_display_helper','on') %}\n
              \ {{ time }}\n{% else %}\n  {{ temp }}\n{% endif %}\n"
            qos: "0"
        - action: mqtt.publish
          data:
            topic: kitchen/hub/lcd/temp
            payload: "{{ temp }}"
            qos: "0"
            retain: true
        - action: mqtt.publish
          data:
            topic: kitchen/hub/lcd/time
            payload: "{{ time }}"
            qos: "0"
            retain: true
        - action: mqtt.publish
          data:
            topic: kitchen/hub/lcd/uv
            payload: "{{ uv }}"
            qos: "0"
            retain: true
        - action: mqtt.publish
          data:
            topic: kitchen/hub/lcd/wind
            payload: "{{ wind }}"
            qos: "0"
            retain: true
        - action: mqtt.publish
          data:
            topic: kitchen/hub/lcd/humidity
            payload: "{{ humidity }}"
            qos: "0"
            retain: true
        - action: mqtt.publish
          data:
            topic: kitchen/hub/lcd/state
            payload: "{{ state }}"
            qos: "0"
            retain: true
        - action: input_boolean.toggle
          metadata: {}
          data: {}
          target:
            entity_id: input_boolean.kitchen_display_helper
  mode: single

- id: "1749828191399"
  alias: Start Timer
  description: ""
  triggers:
    - trigger: conversation
      command:
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {minute} Minute[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] [eine] {second}
          Sekunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] [eine] {hour}
          Stunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] [eine] {hour}
          Stunde[n] [und] {minute} Minute[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] [eine] {minute}
          Minute[n] [und] {second} Sekunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {minute} Minute[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {second} Sekunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {hour} Stunde[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {hour} Stunde[n]
          [und] {minute} Minute[n]"
        - "[Stelle|Starte|Setze] [den|einen] [Timer|Küchentimer] [für|auf] {minute} Minute[n]
          [und] {second} Sekunde[n]"
      id: kitchen_timer_start
      enabled: true
  conditions: []
  actions:
    - data:
        duration:
          '{% set hour = trigger.slots.hour | default(0) | int %} {% set minute
          = trigger.slots.minute | default(0) | int %} {% set second = trigger.slots.second
          | default(0) | int %} {{ "%02d:%02d:%02d" | format(hour, minute, second) }}

          '
      target:
        entity_id: timer.kitchen_timer
      action: timer.start
    # - set_conversation_response:
    #   "Timer gestartet für {{ trigger.slots.hour| default(0)
    #   }} Stunden {{ trigger.slots.minute| default(0) }} Minuten {{ trigger.slots.second|
    #  default(0) }} Sekunden.

    #  "
    - 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
  mode: parallel
  max: 10
