Hi!
So I’m nearing the end of how my automation should controll lights based on 4 buttons with 2 modes each (press/hold, ikea styrbar).
I would love to use the parallell mode so that multiple controllers can work simultaneously, but in order to do that I need to get rid of this static input_boolean that detects if a button is held, in order to have some sort of dynamic “is button held on device X” tracking. Is this possible? I’ve been looking into namespace variables but falling short on how to implement it.
The way my code is now will block multiple devices from acting simultaneously because of the “restart” mode. And I need to make separate input_booelans per device…
input_boolean:
ikea_e2002_01_isheld:
name: Button is held
initial: false
# Add eligible devices here with ieee followed by entity to control
automation:
- alias: Zigbee|IkeaButtons|ClickEvents
id: Zigbee|IkeaButtons|ClickEvents
mode: restart
#max: 5
trigger:
event_type: zha_event
platform: event
# Populate with valid device_ieee for Ikea_E2002 buttons
action:
- variables:
# key value { 'ieee' : 'entity_id'}
device_id: >
{% set devices = {'ChangedForObviousReasons': 'light.office_ceiling',
'XX:YY:XX:YY:XX:DD:AA:SS': '02',
'XX:YY:XX:YY:XX:DD:AA:SS': '03',
'XX:YY:XX:YY:XX:DD:AA:SS': '04'
}
%}
{{ devices[trigger.event.data.device_ieee] }}
command: >
{% set commands = { 'on' : 'up_click',
'move_with_on_off083' : 'up_hold',
'off' : 'down_click',
'move183' : 'down_hold',
'press257130' : 'left_click',
'hold33290' : 'left_hold',
'press256130' : 'right_click',
'hold33280' : 'right_hold',
}
%}
{{commands[trigger.event.data.command + trigger.event.data.args|join]}}
- service: >
input_boolean.turn_{{ 'on' if 'hold' in command else 'off'}}
entity_id: input_boolean.ikea_e2002_01_isheld
- variables:
bIncr: 20 # Increment value for brightness change
cIncr: 40 # Increment value for temperature change
smoothDim: "{{ 2 if 'hold' in command else 0 }}"
bMin: 10 # Min brightness
bMax: 255 # Max brightness
cMin: "{{ state_attr(device_id, 'min_mireds')|int }}" # Min color_temp
cMax: "{{ state_attr(device_id, 'max_mireds')|int }}" # Max color_temp
hardLimit: 10 # Loop block
- alias: "Repeat while in MinMax or until release"
repeat:
sequence:
- choose:
- conditions: "{{ is_state(device_id, 'off') }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ device_id }}"
- conditions: "{{ is_state(device_id, 'on') }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ device_id }}"
transition: "{{ smoothDim }}"
brightness: >
{% set b = state_attr(device_id, 'brightness')|int %}
{% if command == 'up_click' %} {%set b = b + bIncr if b + bIncr <= bMax else bMax %} {% endif %}
{% if command == 'up_hold' %} {%set b = b + bIncr / 2 if b + bIncr / 2 <= bMax else bMax %} {% endif %}
{% if command == 'down_click' %} {%set b = b - bIncr if b - bIncr >= bMin else bMin %} {% endif %}
{% if command == 'down_hold' %} {%set b = b - bIncr / 2 if b - bIncr / 2 >= bMin else bMin %} {% endif %}
{{ b }}
color_temp: >
{% set c = state_attr(device_id, 'color_temp')|int %}
{% if command == 'left_click' %} {%set c = c - cIncr if c - cIncr >= cMin else cMin %} {% endif %}
{% if command == 'left_hold' %} {%set c = c - cIncr / 2 if c - cIncr / 2 >= cMin else cMin %} {% endif %}
{% if command == 'right_click' %} {%set c = c + cIncr if c + cIncr <= cMax else cMax %} {% endif %}
{% if command == 'right_hold' %} {%set c = c + cIncr / 2 if c + cIncr / 2 <= cMax else cMax %} {% endif %}
{{ c }}
- delay:
seconds: "{{ smoothDim }}"
until: >
{{ not (is_state('input_boolean.ikea_e2002_01_isheld', 'on') and repeat.index < hardLimit ) }}