add: for each loop to init buttons

This commit is contained in:
Chris
2022-10-30 21:42:32 +01:00
parent 6af933c013
commit 03e7b6d651

View File

@@ -885,6 +885,12 @@ variables:
#########################################
trigger:
###### DELME ######
- platform: state
entity_id: input_boolean.trigger_nspanel_boot
to: "on"
id: nspanel_boot_btn_init
##### TFT Upload #####
- platform: event
event_type: folder_watcher
@@ -1607,6 +1613,185 @@ action:
{% endif %}
data:
entity_id: "{{ right_button_entity }}"
### NSPanel boot test
- conditions:
- condition: trigger
id: nspanel_boot_btn_init
sequence:
- repeat:
for_each:
- entity: "{{ entity01 }}"
button_label: "{{ entity01_name }}"
button: buttonpage01.button01
- entity: "{{ entity02 }}"
button_label: "{{ entity02_name }}"
button: buttonpage01.button02
- entity: "{{ entity03 }}"
button_label: "{{ entity03_name }}"
button: buttonpage01.button03
- entity: "{{ entity04 }}"
button_label: "{{ entity04_name }}"
button: buttonpage01.button04
- entity: "{{ entity05 }}"
button_label: "{{ entity05_name }}"
button: buttonpage01.button05
- entity: "{{ entity06 }}"
button_label: "{{ entity06_name }}"
button: buttonpage01.button06
- entity: "{{ entity07 }}"
button_label: "{{ entity07_name }}"
button: buttonpage01.button07
- entity: "{{ entity08 }}"
button_label: "{{ entity08_name }}"
button: buttonpage01.button08
- entity: "{{ entity09 }}"
button_label: "{{ entity09_name }}"
button: buttonpage02.button01
- entity: "{{ entity10 }}"
button_label: "{{ entity10_name }}"
button: buttonpage02.button02
- entity: "{{ entity11 }}"
button_label: "{{ entity11_name }}"
button: buttonpage02.button03
- entity: "{{ entity12 }}"
button_label: "{{ entity12_name }}"
button: buttonpage02.button04
- entity: "{{ entity13 }}"
button_label: "{{ entity13_name }}"
button: buttonpage02.button05
- entity: "{{ entity14 }}"
button_label: "{{ entity14_name }}"
button: buttonpage02.button06
- entity: "{{ entity15 }}"
button_label: "{{ entity15_name }}"
button: buttonpage02.button07
- entity: "{{ entity16 }}"
button_label: "{{ entity16_name }}"
button: buttonpage02.button08
- entity: "{{ entity17 }}"
button_label: "{{ entity17_name }}"
button: buttonpage03.button01
- entity: "{{ entity18 }}"
button_label: "{{ entity18_name }}"
button: buttonpage03.button02
- entity: "{{ entity19 }}"
button_label: "{{ entity19_name }}"
button: buttonpage03.button03
- entity: "{{ entity20 }}"
button_label: "{{ entity20_name }}"
button: buttonpage03.button04
- entity: "{{ entity21 }}"
button_label: "{{ entity21_name }}"
button: buttonpage03.button05
- entity: "{{ entity22 }}"
button_label: "{{ entity22_name }}"
button: buttonpage03.button06
- entity: "{{ entity23 }}"
button_label: "{{ entity23_name }}"
button: buttonpage03.button07
- entity: "{{ entity24 }}"
button_label: "{{ entity24_name }}"
button: buttonpage03.button08
- entity: "{{ entity25 }}"
button_label: "{{ entity17_name }}"
button: buttonpage04.button01
- entity: "{{ entity26 }}"
button_label: "{{ entity26_name }}"
button: buttonpage04.button02
- entity: "{{ entity27 }}"
button_label: "{{ entity27_name }}"
button: buttonpage04.button03
- entity: "{{ entity28 }}"
button_label: "{{ entity28_name }}"
button: buttonpage04.button04
- entity: "{{ entity29 }}"
button_label: "{{ entity29_name }}"
button: buttonpage04.button05
- entity: "{{ entity30 }}"
button_label: "{{ entity30_name }}"
button: buttonpage04.button06
- entity: "{{ entity31 }}"
button_label: "{{ entity31_name }}"
button: buttonpage04.button07
- entity: "{{ entity32 }}"
button_label: "{{ entity32_name }}"
button: buttonpage04.button08
sequence:
- if:
- condition: template
value_template: '{{ repeat.item.entity|length > 0 }}'
then:
- variables:
component_to_update: "{{ repeat.item.button }}"
# Button PIC
btn_pic: >-
{%- if repeat.item.entity is match "light." and states[repeat.item.entity].state == 'on' -%} {{ button_light_on }}
{%- elif repeat.item.entity is match "light." and states[repeat.item.entity].state == 'off' -%} {{ button_light_off }}
{%- elif repeat.item.entity is match "switch." and states[repeat.item.entity].state == 'on' -%} {{ button_switch_on }}
{%- elif repeat.item.entity is match "switch." and states[repeat.item.entity].state == 'off' -%} {{ button_switch_off }}
{%- elif repeat.item.entity is match "input_boolean." and states[repeat.item.entity].state == 'on' -%} {{ button_switch_on }}
{%- elif repeat.item.entity is match "input_boolean." and states[repeat.item.entity].state == 'off' -%} {{ button_switch_off }}
{%- elif repeat.item.entity is match "cover." and states[repeat.item.entity].state == 'on' -%} {{ button_cover_on }}
{%- elif repeat.item.entity is match "cover." and states[repeat.item.entity].state == 'off' -%} {{ button_cover_off }}
{%- endif -%}
# TEXT and BRIGHTNESS Background
btn_bg: >-
{%- if states[repeat.item.entity].state == 'on' or states[repeat.item.entity].state == 'open' -%} {{ button_color_1 }}
{%- elif states[repeat.item.entity].state == 'off' or states[repeat.item.entity].state == 'closed' -%} {{ button_color_2 }}
{%- endif -%}
# TEXT Font
btn_txt_font: >-
{%- if states[repeat.item.entity].state == 'on' or states[repeat.item.entity].state == 'open' -%} {{ button_color_2 }}
{%- elif states[repeat.item.entity].state == 'off' or states[repeat.item.entity].state == 'closed' -%} {{ button_color_1 }}
{%- endif -%}
# BRIGHTNESS Font
btn_bri_font: "{{ button_color_2 }}"
# BTN Label
btn_label: "{{ button_label }}"
btn_bri_txt: >-
{%- if repeat.item.entity is match "light." and states[repeat.item.entity].state == 'on' and state_attr(repeat.item.entity, "brightness") != None -%} {{ (state_attr(repeat.item.entity, "brightness") | int(255) * 100 /254) | round(0) }}%
{%- elif repeat.item.entity is match "cover." and states[repeat.item.entity].state == 'open' and state_attr(repeat.item.entity, "current_position") != None -%} {{ (state_attr(repeat.item.entity, "current_position") | int(100)) | round(0) }}%
{%- else -%}
{%- endif -%}
##### SET Buttons ####
#
##### Button PIC #####
- service: "{{ command_printf }}"
data:
cmd: "{{ component_to_update }}pic.pic={{ btn_pic }}"
##### TEXT Background #####
- service: "{{ command_background_color }}"
data:
component: "{{ component_to_update }}text"
message: "{{ btn_bg }}"
##### TEXT Font Color #####
- service: "{{ command_font_color }}"
data:
component: "{{ component_to_update }}text"
message: "{{ btn_txt_font }}"
##### BRIGHTNESS Background Color #####
- service: "{{ command_background_color }}"
data:
component: "{{ component_to_update }}bri"
message: "{{ btn_bg }}"
##### BRIGHTNESS Font Color #####
- service: "{{ command_font_color }}"
data:
component: "{{ component_to_update }}bri"
message: "{{ btn_bri_font }}"
##### "TEXT" Label #####
- service: "{{ command_text_printf }}"
data:
component: "{{ component_to_update }}text"
message: "{{ btn_label }}"
##### "BRIGHTNESS" Text #####
- service: "{{ command_text_printf }}"
data:
component: "{{ component_to_update }}bri"
message: "{{ btn_bri_txt }}"
- delay:
milliseconds: 10
##### NSPanel Loading#####
- choose: