# Reference: Home Assistant Core 2026.10.4. Virtual helpers only.
# Load as a package, not directly as an automation-editor snippet.
input_boolean:
  local_voice_allow_bedtime:
    name: 允许睡前演练
    initial: false
  local_voice_guest_mode:
    name: 访客限制模式
    initial: true
  lab_living_main:
    name: 演练客厅主灯状态
    initial: true

input_number:
  local_voice_night_level:
    name: 睡前演练目标亮度
    min: 5
    max: 35
    step: 1
    initial: 15
  lab_bedroom_level:
    name: 演练卧室灯亮度
    min: 0
    max: 100
    step: 1
    initial: 60

script:
  local_voice_bedtime_lab:
    alias: 睡前灯光演练
    description: 只更新两项虚拟灯光状态，不操作真实设备，不保存或修改策略
    mode: single
    sequence:
      - variables:
          level: "{{ states('input_number.local_voice_night_level') }}"
      - choose:
          - conditions:
              - condition: template
                value_template: >-
                  {{ is_state('input_boolean.local_voice_allow_bedtime', 'on')
                     and is_state('input_boolean.local_voice_guest_mode', 'off')
                     and is_number(level)
                     and 5 <= (level | float(-1)) <= 35
                     and states('input_boolean.lab_living_main') in ['on', 'off']
                     and is_number(states('input_number.lab_bedroom_level')) }}
            sequence:
              - action: input_boolean.turn_off
                target:
                  entity_id: input_boolean.lab_living_main
              - action: input_number.set_value
                target:
                  entity_id: input_number.lab_bedroom_level
                data:
                  value: "{{ level | float }}"
              - variables:
                  result:
                    status: simulated
                    message: 已更新虚拟灯光状态，未操作真实设备
              - stop: 虚拟演练步骤结束
                response_variable: result
        default:
          - variables:
              result:
                status: rejected
                message: 未执行演练，请检查允许开关、访客模式与实体参数状态
          - stop: 策略或状态检查未通过
            response_variable: result

automation:
  - id: local_voice_bedtime_lab_sentence
    alias: 睡前演练语句入口
    triggers:
      - trigger: conversation
        command:
          - 准备睡觉演练
          - 执行睡前灯光演练
    actions:
      - action: script.local_voice_bedtime_lab
        response_variable: outcome
      - set_conversation_response: "{{ outcome.message }}"
    mode: single
