Add text and icon color control

This commit is contained in:
aderusha 2021-12-12 13:05:47 -05:00
parent bc93600ed4
commit dc6b021122
6 changed files with 317 additions and 108 deletions

View File

@ -22,6 +22,28 @@ blueprint:
</details>
## Nextion color codes
<details>
The Nextion environment utilizes RGB 565 encoding. [Use this handy convertor](https://nodtem66.github.io/nextion-hmi-color-convert/index.html) to select your colors and convert to the RGB 565 format.
Here are some example colors:
| Color | Code |
|--------|-------|
| White | 65535 |
| Black | 0 |
| Grey | 25388 |
| Red | 63488 |
| Green | 2016 |
| Blue | 31 |
| Yellow | 65504 |
| Orange | 64512 |
| Brown | 48192 |
</details>
domain: automation
input:
haspdevice:
@ -52,6 +74,51 @@ blueprint:
max: 7
mode: slider
unit_of_measurement: button
selected_fgcolor:
name: "Selected foreground color"
description: 'Selected foreground color in Nextion RGB565 format (see "Nextion color codes" above for reference). -1 = Current theme selected foreground color.'
default: -1
selector:
number:
min: -1
max: 65535
mode: slider
selected_bgcolor:
name: "Selected background color"
description: 'Selected background color in Nextion RGB565 format (see "Nextion color codes" above for reference). -1 = Current theme selected background color.'
default: -1
selector:
number:
min: -1
max: 65535
mode: slider
unselected_fgcolor:
name: "Unselected foreground color"
description: 'Unselected foreground color in Nextion RGB565 format (see "Nextion color codes" above for reference). -1 = Current theme unselected foreground color.'
default: -1
selector:
number:
min: -1
max: 65535
mode: slider
unselected_bgcolor:
name: "Unselected background color"
description: 'Unselected background color in Nextion RGB565 format (see "Nextion color codes" above for reference). -1 = Current theme unselected background color.'
default: -1
selector:
number:
min: -1
max: 65535
mode: slider
icon_fgcolor:
name: "Icon foreground color"
description: 'Icon foreground color in Nextion RGB565 format (see "Nextion color codes" above for reference). -1 = Current theme selected foreground color.'
default: -1
selector:
number:
min: -1
max: 65535
mode: slider
mode: parallel
max_exceeded: silent
@ -66,14 +133,15 @@ variables:
{%- endfor -%}
hasppage: !input hasppage
haspbutton: !input haspbutton
selected_fgcolor: !input selected_fgcolor
selected_bgcolor: !input selected_bgcolor
unselected_fgcolor: !input unselected_fgcolor
unselected_bgcolor: !input unselected_bgcolor
icon_fgcolor: !input icon_fgcolor
haspobject: '{{ "p[" ~ hasppage ~ "].b[" ~ haspbutton ~ "]" }}'
commandtopic: '{{ "hasp/" ~ haspname ~ "/command/" ~ haspobject }}'
jsontopic: '{{ "hasp/" ~ haspname ~ "/state/json" }}'
jsoncommandtopic: '{{ "hasp/" ~ haspname ~ "/command/json" }}'
selectedfgtopic: '{{ "hasp/" ~ haspname ~ "/light/selectedforegroundcolor/rgb" }}'
selectedbgtopic: '{{ "hasp/" ~ haspname ~ "/light/selectedbackgroundcolor/rgb" }}'
unselectedfgtopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedforegroundcolor/rgb" }}'
unselectedbgtopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedbackgroundcolor/rgb" }}'
activepage: >-
{%- set activepage = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
@ -82,54 +150,90 @@ variables:
{%- endif -%}
{%- endfor -%}
{{ states(activepage.entity) | int(default=-1) }}
selectedfgtopic: '{{ "hasp/" ~ haspname ~ "/light/selectedforegroundcolor/rgb" }}'
selectedbgtopic: '{{ "hasp/" ~ haspname ~ "/light/selectedbackgroundcolor/rgb" }}'
unselectedfgtopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedforegroundcolor/rgb" }}'
unselectedbgtopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedbackgroundcolor/rgb" }}'
selectedfg: >-
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_selected_foreground_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- if (selected_fgcolor|int) >= 0 -%}
{{ selected_fgcolor }}
{%- else -%}
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_selected_foreground_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- endif -%}
selectedbg: >-
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_selected_background_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- if (selected_bgcolor|int) >= 0 -%}
{{ selected_bgcolor }}
{%- else -%}
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_selected_background_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- endif -%}
unselectedfg: >-
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_unselected_foreground_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- if (unselected_fgcolor|int) >= 0 -%}
{{ unselected_fgcolor }}
{%- else -%}
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_unselected_foreground_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- endif -%}
unselectedbg: >-
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_unselected_background_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- if (unselected_bgcolor|int) >= 0 -%}
{{ unselected_bgcolor }}
{%- else -%}
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_unselected_background_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- endif -%}
iconcolor: >-
{%- if (icon_fgcolor|int) >= 0 -%}
{{ icon_fgcolor }}
{%- else -%}
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_selected_foreground_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- endif -%}
text: '{{(now().strftime("%b "))~now().day}}'
font: 8
ypos: "{{(haspbutton|int - 4) * 67 + 2}}" # calculate the top pixel position based on the selected button
@ -212,7 +316,7 @@ action:
"{{haspobject}}.bco2={{unselectedbg}}",
"{{haspobject}}.txt=\"{{text}} \""
{%- if activepage|int == hasppage|int -%}
,"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""
,"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""
{%- endif -%}]
#########################################################################
# Update the calendar text every day at midnight. If the selected page is currently active, also place the icon.
@ -226,7 +330,7 @@ action:
payload: >-
["{{haspobject}}.txt=\"{{text}} \""
{%- if activepage|int == hasppage|int -%}
,"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""
,"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""
{%- endif -%}]
#########################################################################
# Catch MQTT events
@ -251,7 +355,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'
- conditions: # Page changed to our page, so place the icon on the screen.
- condition: template
value_template: '{{ (trigger.topic == jsontopic ) and (trigger.payload_json.event == "page" ) and (trigger.payload_json.value == hasppage|int) }}'
@ -259,7 +363,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply selected foreground color when it changes.
# Any change to the button will remove the overlaid icon.
@ -277,7 +381,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{trigger.payload}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply selected background color on change
- conditions:
@ -294,7 +398,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply unselected foreground color on change
- conditions:
@ -311,7 +415,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply unselected background color on change
- conditions:
@ -328,4 +432,4 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'

View File

@ -22,6 +22,28 @@ blueprint:
</details>
## Nextion color codes
<details>
The Nextion environment utilizes RGB 565 encoding. [Use this handy convertor](https://nodtem66.github.io/nextion-hmi-color-convert/index.html) to select your colors and convert to the RGB 565 format.
Here are some example colors:
| Color | Code |
|--------|-------|
| White | 65535 |
| Black | 0 |
| Grey | 25388 |
| Red | 63488 |
| Green | 2016 |
| Blue | 31 |
| Yellow | 65504 |
| Orange | 64512 |
| Brown | 48192 |
</details>
domain: automation
input:
haspdevice:
@ -57,6 +79,51 @@ blueprint:
default: false
selector:
boolean:
selected_fgcolor:
name: "Selected foreground color"
description: 'Selected foreground color in Nextion RGB565 format (see "Nextion color codes" above for reference). -1 = Current theme selected foreground color.'
default: -1
selector:
number:
min: -1
max: 65535
mode: slider
selected_bgcolor:
name: "Selected background color"
description: 'Selected background color in Nextion RGB565 format (see "Nextion color codes" above for reference). -1 = Current theme selected background color.'
default: -1
selector:
number:
min: -1
max: 65535
mode: slider
unselected_fgcolor:
name: "Unselected foreground color"
description: 'Unselected foreground color in Nextion RGB565 format (see "Nextion color codes" above for reference). -1 = Current theme unselected foreground color.'
default: -1
selector:
number:
min: -1
max: 65535
mode: slider
unselected_bgcolor:
name: "Unselected background color"
description: 'Unselected background color in Nextion RGB565 format (see "Nextion color codes" above for reference). -1 = Current theme unselected background color.'
default: -1
selector:
number:
min: -1
max: 65535
mode: slider
icon_fgcolor:
name: "Icon foreground color"
description: 'Icon foreground color in Nextion RGB565 format (see "Nextion color codes" above for reference). -1 = Current theme selected foreground color.'
default: -1
selector:
number:
min: -1
max: 65535
mode: slider
mode: parallel
max_exceeded: silent
@ -72,6 +139,11 @@ variables:
hasppage: !input hasppage
haspbutton: !input haspbutton
hour24: !input hour24
selected_fgcolor: !input selected_fgcolor
selected_bgcolor: !input selected_bgcolor
unselected_fgcolor: !input unselected_fgcolor
unselected_bgcolor: !input unselected_bgcolor
icon_fgcolor: !input icon_fgcolor
haspobject: '{{ "p[" ~ hasppage ~ "].b[" ~ haspbutton ~ "]" }}'
commandtopic: '{{ "hasp/" ~ haspname ~ "/command/" ~ haspobject }}'
jsontopic: '{{ "hasp/" ~ haspname ~ "/state/json" }}'
@ -89,53 +161,85 @@ variables:
unselectedfgtopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedforegroundcolor/rgb" }}'
unselectedbgtopic: '{{ "hasp/" ~ haspname ~ "/light/unselectedbackgroundcolor/rgb" }}'
selectedfg: >-
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_selected_foreground_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- if (selected_fgcolor|int) >= 0 -%}
{{ selected_fgcolor }}
{%- else -%}
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_selected_foreground_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- endif -%}
selectedbg: >-
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_selected_background_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- if (selected_bgcolor|int) >= 0 -%}
{{ selected_bgcolor }}
{%- else -%}
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_selected_background_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- endif -%}
unselectedfg: >-
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_unselected_foreground_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- if (unselected_fgcolor|int) >= 0 -%}
{{ unselected_fgcolor }}
{%- else -%}
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_unselected_foreground_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- endif -%}
unselectedbg: >-
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_unselected_background_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- if (unselected_bgcolor|int) >= 0 -%}
{{ unselected_bgcolor }}
{%- else -%}
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_unselected_background_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- endif -%}
iconcolor: >-
{%- if (icon_fgcolor|int) >= 0 -%}
{{ icon_fgcolor }}
{%- else -%}
{%- set color = namespace() -%}
{%- for entity in device_entities(haspdevice) -%}
{%- if entity|regex_search("^light\..*_selected_foreground_color(?:_\d+|)$") -%}
{%- set color.source=entity -%}
{%- endif -%}
{%- endfor -%}
{%- set brightness = state_attr(color.source, "brightness")|int(default=255) / 255 -%}
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int(default=0) -%}
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int(default=0) -%}
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int(default=0) -%}
{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}
{%- endif -%}
text: '{%- if hour24 == true -%}{%- set hourformat="%-H" -%}{%- else %}{%- set hourformat="%I" -%}{%- endif -%}{{(now().strftime(hourformat)|int)~now().strftime(":%M")}}'
font: 10
ypos: "{{(haspbutton|int - 4) * 67 + 2}}" # calculate the top pixel position based on the selected button
@ -218,7 +322,7 @@ action:
"{{haspobject}}.bco2={{unselectedbg}}",
"{{haspobject}}.txt=\"{{text}} \""
{%- if activepage|int == hasppage|int -%}
,"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""
,"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""
{%- endif -%}]
#########################################################################
# Every minute, update the clock text. If the selected page is currently active, also place the icon.
@ -229,7 +333,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["{{haspobject}}.txt=\"{{text}} \""{%- if activepage|int == hasppage|int -%},"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""{%- endif -%}]'
payload: '["{{haspobject}}.txt=\"{{text}} \""{%- if activepage|int == hasppage|int -%},"delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""{%- endif -%}]'
#########################################################################
# Catch MQTT events
@ -254,7 +358,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'
- conditions: # Page changed to our page, so place the icon on the screen.
- condition: template
value_template: '{{ (trigger.topic == jsontopic ) and (trigger.payload_json.event == "page" ) and (trigger.payload_json.value == hasppage|int) }}'
@ -262,7 +366,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply selected foreground color when it changes.
# Any change to the button will remove the overlaid icon.
@ -280,7 +384,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{trigger.payload}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply selected background color on change
- conditions:
@ -297,7 +401,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply unselected foreground color on change
- conditions:
@ -314,7 +418,7 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'
#########################################################################
# Theme: Apply unselected background color on change
- conditions:
@ -331,4 +435,4 @@ action:
- service: mqtt.publish
data:
topic: "{{jsoncommandtopic}}"
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{selectedfg}},0,1,1,3,\"{{icon}}\""]'
payload: '["delay=1","xstr {{xpos}},{{ypos}},{{iconwidth}},{{iconheight}},{{iconfont}},{{iconcolor}},0,1,1,3,\"{{icon}}\""]'

View File

@ -43,6 +43,7 @@ blueprint:
| Brown | 48192 |
</details>
domain: automation
input:
haspdevice:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB