automation:
  - alias: Trust remote · Guest bedroom
    trigger:
      - platform: state
        entity_id: sensor.trust_remote_action
    action:
      - choose:
        - conditions: "{{ trigger.to_state.state == 'up-press' }}"
          sequence:
            - service: light.turn_on
              entity_id: light.tradfri_large
              data_template:
                brightness_pct: "{{ is_state('input_select.guest_bedroom_mode', 'day') | iif(100, 10) }}"
                color_temp: "{{ states('input_number.guest_bedroom_light_temp') }}"
        - conditions: "{{ trigger.to_state.state == 'down-press' }}"
          sequence:
            - service: light.turn_off
              entity_id: light.tradfri_large
        - conditions: "{{ trigger.to_state.state == 'on' or trigger.to_state.state == 'off' }}"
          sequence:
            - service: script.guest_bedroom_bedside_confirm
            - service: input_select.select_next
              entity_id: input_select.guest_bedroom_mode

  - alias: Trust remote · Dimming
    trigger:
      - platform: state
        entity_id: sensor.trust_remote_action
        to: "down-press"
      - platform: state
        entity_id: sensor.trust_remote_action
        to: "up-press"
    action:
      - service: light.turn_on
        data_template:
          entity_id: >-
            {% set groupId = states('sensor.trust_remote_group')[4] | int %}
            {% if groupId == 5 %}
              {% set entityId = 'light.living_room' %}
            {% elif groupId == 0 %}
              {% set entityId = 'light.living_room_main' %}
            {% elif groupId == 1 %}
              {% set entityId = 'light.hue_ambiance_7' %}
            {% elif groupId == 2 %}
              {% set entityId = 'light.living_room_ambient' %}
            {% elif groupId == 3 %}
              {% set entityId = 'light.living_room_ambient_main' %}
            {% elif groupId == 4 %}
              {% set entityId = 'light.light_lohas_2' %}
            {% endif %}

            {{ entityId }}

          brightness_step_pct: >-
            {% if trigger.to_state.state == "up-press" %}
              20
            {% else %}
              -20
            {% endif %}
