2025/08/06

Tuya Knob 색온도 조절 자동화



노브를 누른채 돌리면 color_temperature_step_up, color_temperature_step_down 이벤트가 발생하고 그걸 이용해 색온도 조절하는 자동화 추가.

input_number를 설정하고 현재설정 값을 불러와 action_step_size에 적당한 상수값으로 곱한 값과 더해 최종 노브변화값으로 색온도 결정하는 자동화.

** 색온도는 color_temp, color_temp_kalvin으로 조절할 수 있는데 노브에 사용하기에는 color_temp가 편하지만 사용중단 예정이라 color_temp_kalvin으로 설정.


input_number.yaml
color_temperature:
  name: 색온도
  min: 2000
  max: 6500
  step: 50

automations.yaml
- id: 버튼-Knob-1st
  alias: 버튼-Knob-1st
  mode: parallel
  triggers:
    - trigger: state
      entity_id: event.knob_1st_action
      to: ~
  conditions:
      - condition: template
        value_template: "{{ trigger.from_state.state != 'unavailable' }}"
  actions:
    - choose:
        - conditions: # 색온도 올림
            - condition: template
              value_template: "{{ trigger.to_state.attributes.event_type == 'color_temperature_step_up'}}"
          sequence:
            - service: input_number.set_value
              data:
                value: >
                  {% set current_value = states('input_number.color_temperature') | int %}
                  {% set step = states('sensor.knob_1st_action_step_size') | int * 10 %}
                  {{ [current_value + step, 6500] | min }}
              target:
                entity_id: input_number.color_temperature
        - conditions: # 색온도 내림
            - condition: template
              value_template: "{{ trigger.to_state.attributes.event_type == 'color_temperature_step_down'}}"
          sequence:
            - service: input_number.set_value
              data:
                value: >
                  {% set current_value = states('input_number.color_temperature') | int %}
                  {% set step = states('sensor.knob_1st_action_step_size') | int * 10 %}
                  {{ [current_value - step, 2000] | max }}
              target:
                entity_id: input_number.color_temperature

- id: knob/color-temp
  alias: knob/color-temp
  mode: queued
  description: 색온도 업데이트
  trigger:
    - platform: state
      entity_id: input_number.color_temperature
  action:
    - service: light.turn_on
      data:
        color_temp_kelvin: "{{ states('input_number.color_temperature') | int }}"
      target:
        entity_id: >
          {{ expand([
            'light.geosildeung1',
            'light.geosildeung2',
            'light.geosildeung3',
            'light.geosildeung4',
            'light.geosildeung5',
            'light.geosildeung6',
            'light.geosiltvdeung'
          ]) | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}