Using variables for Ikea light bulb in automations

Hi

I’m newbie to HA and YAML.

I got this automation and it’s working.

alias: Ikea Light button
description: “”
trigger:

  • platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: arrow_right_click
    id: kelvin cold
  • platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: arrow_left_click
    id: kelvin warm
    condition:
    action:
  • choose:
    • conditions:
      • condition: trigger
        id:
        • kelvin cold
          sequence:
      • service: light.turn_on
        data:
        kelvin: 3240
        target:
        area_id: stue
    • conditions:
      • condition: trigger
        id:
        • kelvin warm
          sequence:
      • service: light.turn_on
        data:
        kelvin: 2010
        target:
        area_id: stue
        mode: single

I have made a helper var called “Kelvin stue” and Entity ID: input_number.colortone
I wat tow things:

  1. In my automation I want to set var “Kelvin Stue” to the current state of kelvin on my light bulb, before I do anything to mig light bulb.
  2. The when I do the sequence, i want to set kelvin to value of the var to
    “kelvin stue” + 100 (trigger id: kelvin warm) and
    “kelvin stue” - 100 (trigger id: kelvin cold)

I have tried sevarel things, but not succeded yet.

My light bulb is a Ikea LED1732G11

Thanks in advance

Bjarne

Format your code properly: How to help us help you - or How to ask a good question

Ok I´ll studdy that :wink:

I found a solution for my problem.

# Step kelvin on bulbs when holding down button

service: light.turn_on
metadata: {}
data:
  kelvin: >-
    {{ (state_attr('light.0xec1bbdfffee5f8de', 'color_temp_kelvin') | int + 100)
    }}
target:
  device_id:
    - ef8cf8c80ed65a6e6bae9ceaeb7daccb
    - 3144a371d5056e9c3779325db2a3d930
    - 22b84414692ad827a8e3c16aa744802d
    - 4ad4dfade9da9d74d4dd632784f0cb51

So my whole automation, using the IKEA traadfri button is now working.
Here is the code if off interest :wink:

alias: IKEA Remote control. Model E1524/E1810
description: "All button works in zigbee2mqtt"
trigger:
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: toggle
    id: On/off
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: brightness_up_click
    id: brightness_up_click
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: brightness_up_hold
    id: brightness_up_hold
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: brightness_up_release
    id: brightness_up_release
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: brightness_down_click
    id: brightness_down_click
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: brightness_down_hold
    id: brightness_down_hold
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: brightness_down_release
    id: brightness_down_release
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: arrow_right_click
    id: kelvin_up_click
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: arrow_right_hold
    id: kelvin_up_hold
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: arrow_right_release
    id: kelvin_up_hold_release
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: arrow_left_click
    id: kelvin_down_click
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: arrow_left_hold
    id: kelvin_down_hold
  - platform: device
    domain: mqtt
    device_id: 29b32ae30f008d8c29198a7801c23b32
    type: action
    subtype: arrow_left_release
    id: kelvin_down_hold_release
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - On/off
          - condition: state
            entity_id: light.0x8c6fb9fffe140528
            state: "on"
          - condition: state
            entity_id: light.0x14b457fffe33d8eb
            state: "on"
          - condition: state
            entity_id: light.0xec1bbdfffee5f8de
            state: "on"
          - condition: state
            entity_id: light.0x14b457fffe336199
            state: "on"
        sequence:
          - service: light.turn_off
            metadata: {}
            data: {}
            target:
              area_id: stue
      - conditions:
          - condition: trigger
            id:
              - On/off
          - condition: state
            entity_id: light.0x8c6fb9fffe140528
            state: "off"
          - condition: state
            entity_id: light.0x14b457fffe33d8eb
            state: "off"
          - condition: state
            entity_id: light.0xec1bbdfffee5f8de
            state: "off"
          - condition: state
            entity_id: light.0x14b457fffe336199
            state: "off"
        sequence:
          - service: light.turn_on
            metadata: {}
            data: {}
            target:
              area_id: stue
      - conditions:
          - condition: trigger
            id:
              - ´brightness_up_click
        sequence:
          - service: light.turn_on
            data:
              brightness_step_pct: 10
            target:
              area_id: stue
      - conditions:
          - condition: trigger
            id:
              - brightness_down_click
        sequence:
          - service: light.turn_on
            data:
              brightness_step_pct: -10
            target:
              area_id: stue
  - choose:
      - conditions:
          - condition: trigger
            id:
              - brightness_up_hold
        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  metadata: {}
                  data:
                    brightness_step: 50
                  target:
                    area_id: stue
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
              while:
                - condition: trigger
                  id:
                    - brightness_up_hold
      - conditions:
          - condition: trigger
            id:
              - brightness_down_hold
        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  metadata: {}
                  data:
                    brightness_step: -50
                  target:
                    area_id: stue
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
              while:
                - condition: trigger
                  id:
                    - brightness_down_hold
  - choose:
      - conditions:
          - condition: trigger
            id:
              - kelvin_up_click
        sequence:
          - service: light.turn_on
            data:
              kelvin: >-
                {{ (state_attr('light.0xec1bbdfffee5f8de', 'color_temp_kelvin')
                | int + 100) }}
            target:
              device_id:
                - 3144a371d5056e9c3779325db2a3d930
                - 4ad4dfade9da9d74d4dd632784f0cb51
                - 22b84414692ad827a8e3c16aa744802d
                - ef8cf8c80ed65a6e6bae9ceaeb7daccb
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 500
      - conditions:
          - condition: trigger
            id:
              - kelvin_down_click
        sequence:
          - service: light.turn_on
            data:
              kelvin: >-
                {{ (state_attr('light.0xec1bbdfffee5f8de', 'color_temp_kelvin')
                | int - 100) }}
            target:
              device_id:
                - 3144a371d5056e9c3779325db2a3d930
                - 4ad4dfade9da9d74d4dd632784f0cb51
                - 22b84414692ad827a8e3c16aa744802d
                - ef8cf8c80ed65a6e6bae9ceaeb7daccb
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 500
      - conditions:
          - condition: trigger
            id:
              - kelvin_up_hold
        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  metadata: {}
                  data:
                    kelvin: >-
                      {{ (state_attr('light.0xec1bbdfffee5f8de',
                      'color_temp_kelvin') | int + 100) }}
                  target:
                    device_id:
                      - ef8cf8c80ed65a6e6bae9ceaeb7daccb
                      - 3144a371d5056e9c3779325db2a3d930
                      - 22b84414692ad827a8e3c16aa744802d
                      - 4ad4dfade9da9d74d4dd632784f0cb51
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
              while:
                - condition: trigger
                  id:
                    - kelvin_up_hold
      - conditions:
          - condition: trigger
            id:
              - kelvin_down_hold
        sequence:
          - repeat:
              sequence:
                - service: light.turn_on
                  metadata: {}
                  data:
                    kelvin: >-
                      {{ (state_attr('light.0xec1bbdfffee5f8de',
                      'color_temp_kelvin') | int - 100) }}
                  target:
                    device_id:
                      - ef8cf8c80ed65a6e6bae9ceaeb7daccb
                      - 3144a371d5056e9c3779325db2a3d930
                      - 22b84414692ad827a8e3c16aa744802d
                      - 4ad4dfade9da9d74d4dd632784f0cb51
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
              while:
                - condition: trigger
                  id:
                    - kelvin_down_hold
mode: restart

Regards Bjarne