mirror of
https://github.com/HASwitchPlate/HASPone.git
synced 2025-07-24 11:46:33 +00:00
HASPone v1.02
This commit is contained in:
parent
9b320d09b5
commit
9f97699005
Binary file not shown.
@ -62,7 +62,7 @@ char nextionBaud[7] = "115200";
|
||||
#include <SoftwareSerial.h>
|
||||
#include <ESP8266Ping.h>
|
||||
|
||||
const float haspVersion = 1.01; // Current HASP software release version
|
||||
const float haspVersion = 1.02; // Current HASP software release version
|
||||
const uint16_t mqttMaxPacketSize = 2048; // Size of buffer for incoming MQTT message
|
||||
byte nextionReturnBuffer[128]; // Byte array to pass around data coming from the panel
|
||||
uint8_t nextionReturnIndex = 0; // Index for nextionReturnBuffer
|
||||
@ -770,6 +770,34 @@ void mqttDiscovery()
|
||||
mqttClient.publish(mqttDiscoveryTopic, mqttDiscoveryPayload, true, 1);
|
||||
debugPrintln(String(F("MQTT OUT: '")) + mqttDiscoveryTopic + String(F("' : '")) + String(mqttDiscoveryPayload) + String(F("'")));
|
||||
|
||||
// AlwaysOn topic for RGB lights
|
||||
mqttClient.publish((String(F("hasp/")) + String(haspNode) + String(F("/alwayson"))), "ON", true, 1);
|
||||
debugPrintln(String(F("MQTT OUT: 'hasp/"))+ String(haspNode) + String(F("/alwayson' : 'ON'")));
|
||||
|
||||
// rgb light discovery for selectedforegroundcolor
|
||||
mqttDiscoveryTopic = String(F("homeassistant/light/")) + String(haspNode) + String(F("/selectedforegroundcolor/config"));
|
||||
mqttDiscoveryPayload = String(F("{\"name\":\"")) + String(haspNode) + String(F(" selected foreground color\",\"command_topic\":\"hasp/")) + String(haspNode) + String(F("/light/selectedforegroundcolor/switch\",\"state_topic\":\"hasp/")) + String(haspNode) + String(F("/alwayson\",\"rgb_command_topic\":\"hasp/")) + String(haspNode) + String(F("/light/selectedforegroundcolor/rgb\",\"rgb_command_template\":\"{{(red|bitwise_and(248)*256)+(green|bitwise_and(252)*8)+(blue|bitwise_and(248)/8)|int }}\",\"retain\":true,\"unique_id\":\"")) + mqttClientId + String(F("-selectedforegroundcolor\",\"device\":{\"identifiers\":[\"")) + mqttClientId + String(F("\"],\"name\":\"")) + String(haspNode) + String(F("\",\"manufacturer\":\"HASwitchPlate\",\"model\":\"HASPone v1.0.0\",\"sw_version\":")) + String(haspVersion) + String(F("}}"));
|
||||
mqttClient.publish(mqttDiscoveryTopic, mqttDiscoveryPayload, true, 1);
|
||||
debugPrintln(String(F("MQTT OUT: '")) + mqttDiscoveryTopic + String(F("' : '")) + String(mqttDiscoveryPayload) + String(F("'")));
|
||||
|
||||
// rgb light discovery for selectedbackgroundcolor
|
||||
mqttDiscoveryTopic = String(F("homeassistant/light/")) + String(haspNode) + String(F("/selectedbackgroundcolor/config"));
|
||||
mqttDiscoveryPayload = String(F("{\"name\":\"")) + String(haspNode) + String(F(" selected background color\",\"command_topic\":\"hasp/")) + String(haspNode) + String(F("/light/selectedbackgroundcolor/switch\",\"state_topic\":\"hasp/")) + String(haspNode) + String(F("/alwayson\",\"rgb_command_topic\":\"hasp/")) + String(haspNode) + String(F("/light/selectedbackgroundcolor/rgb\",\"rgb_command_template\":\"{{(red|bitwise_and(248)*256)+(green|bitwise_and(252)*8)+(blue|bitwise_and(248)/8)|int }}\",\"retain\":true,\"unique_id\":\"")) + mqttClientId + String(F("-selectedbackgroundcolor\",\"device\":{\"identifiers\":[\"")) + mqttClientId + String(F("\"],\"name\":\"")) + String(haspNode) + String(F("\",\"manufacturer\":\"HASwitchPlate\",\"model\":\"HASPone v1.0.0\",\"sw_version\":")) + String(haspVersion) + String(F("}}"));
|
||||
mqttClient.publish(mqttDiscoveryTopic, mqttDiscoveryPayload, true, 1);
|
||||
debugPrintln(String(F("MQTT OUT: '")) + mqttDiscoveryTopic + String(F("' : '")) + String(mqttDiscoveryPayload) + String(F("'")));
|
||||
|
||||
// rgb light discovery for unselectedforegroundcolor
|
||||
mqttDiscoveryTopic = String(F("homeassistant/light/")) + String(haspNode) + String(F("/unselectedforegroundcolor/config"));
|
||||
mqttDiscoveryPayload = String(F("{\"name\":\"")) + String(haspNode) + String(F(" unselected foreground color\",\"command_topic\":\"hasp/")) + String(haspNode) + String(F("/light/unselectedforegroundcolor/switch\",\"state_topic\":\"hasp/")) + String(haspNode) + String(F("/alwayson\",\"rgb_command_topic\":\"hasp/")) + String(haspNode) + String(F("/light/unselectedforegroundcolor/rgb\",\"rgb_command_template\":\"{{(red|bitwise_and(248)*256)+(green|bitwise_and(252)*8)+(blue|bitwise_and(248)/8)|int }}\",\"retain\":true,\"unique_id\":\"")) + mqttClientId + String(F("-unselectedforegroundcolor\",\"device\":{\"identifiers\":[\"")) + mqttClientId + String(F("\"],\"name\":\"")) + String(haspNode) + String(F("\",\"manufacturer\":\"HASwitchPlate\",\"model\":\"HASPone v1.0.0\",\"sw_version\":")) + String(haspVersion) + String(F("}}"));
|
||||
mqttClient.publish(mqttDiscoveryTopic, mqttDiscoveryPayload, true, 1);
|
||||
debugPrintln(String(F("MQTT OUT: '")) + mqttDiscoveryTopic + String(F("' : '")) + String(mqttDiscoveryPayload) + String(F("'")));
|
||||
|
||||
// rgb light discovery for unselectedbackgroundcolor
|
||||
mqttDiscoveryTopic = String(F("homeassistant/light/")) + String(haspNode) + String(F("/unselectedbackgroundcolor/config"));
|
||||
mqttDiscoveryPayload = String(F("{\"name\":\"")) + String(haspNode) + String(F(" unselected background color\",\"command_topic\":\"hasp/")) + String(haspNode) + String(F("/light/unselectedbackgroundcolor/switch\",\"state_topic\":\"hasp/")) + String(haspNode) + String(F("/alwayson\",\"rgb_command_topic\":\"hasp/")) + String(haspNode) + String(F("/light/unselectedbackgroundcolor/rgb\",\"rgb_command_template\":\"{{(red|bitwise_and(248)*256)+(green|bitwise_and(252)*8)+(blue|bitwise_and(248)/8)|int }}\",\"retain\":true,\"unique_id\":\"")) + mqttClientId + String(F("-unselectedbackgroundcolor\",\"device\":{\"identifiers\":[\"")) + mqttClientId + String(F("\"],\"name\":\"")) + String(haspNode) + String(F("\",\"manufacturer\":\"HASwitchPlate\",\"model\":\"HASPone v1.0.0\",\"sw_version\":")) + String(haspVersion) + String(F("}}"));
|
||||
mqttClient.publish(mqttDiscoveryTopic, mqttDiscoveryPayload, true, 1);
|
||||
debugPrintln(String(F("MQTT OUT: '")) + mqttDiscoveryTopic + String(F("' : '")) + String(mqttDiscoveryPayload) + String(F("'")));
|
||||
|
||||
if (motionEnabled)
|
||||
{ // binary_sensor for motion
|
||||
String macAddress = String(espMac[0], HEX) + String(F(":")) + String(espMac[1], HEX) + String(F(":")) + String(espMac[2], HEX) + String(F(":")) + String(espMac[3], HEX) + String(F(":")) + String(espMac[4], HEX) + String(F(":")) + String(espMac[5], HEX);
|
||||
@ -1125,7 +1153,7 @@ void nextionProcessInput()
|
||||
xCoord = xCoord * 256 + nextionReturnBuffer[2];
|
||||
uint16_t yCoord = nextionReturnBuffer[3];
|
||||
yCoord = yCoord * 256 + nextionReturnBuffer[4];
|
||||
String xyCoord = String(xCoord) + ',' + String(yCoord);
|
||||
String xyCoord = String(xCoord) + String(',') + String(yCoord);
|
||||
byte nextionTouchAction = nextionReturnBuffer[5];
|
||||
if (nextionTouchAction == 0x01)
|
||||
{
|
||||
@ -2294,6 +2322,7 @@ void configClearSaved()
|
||||
debugPrintln(F("RESET: Formatting SPIFFS"));
|
||||
SPIFFS.format();
|
||||
debugPrintln(F("RESET: Clearing WiFiManager settings..."));
|
||||
WiFi.disconnect();
|
||||
WiFiManager wifiManager;
|
||||
wifiManager.resetSettings();
|
||||
EEPROM.begin(512);
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,7 +2,9 @@ blueprint:
|
||||
name: "HASP Core functionality"
|
||||
description: |
|
||||
|
||||
# Description
|
||||
## Blueprint Version: `1.02`
|
||||
|
||||
## Description
|
||||
|
||||
Provides core HASP functionality. Deploy one copy of this blueprint for each HASP device.
|
||||
|
||||
@ -222,7 +224,6 @@ variables:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^sensor\.") -%}
|
||||
{{- entity|regex_replace(find="^sensor\.", replace="", ignorecase=true)|regex_replace(find="_sensor(?:_\d+|)$", replace="", ignorecase=true) -}}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
page1text: !input page1text
|
||||
@ -247,19 +248,16 @@ variables:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^number\..*_active_page(?:_\d+|)$") -%}
|
||||
{%- set activepage.entity=entity -%}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{% if states(activepage.entity)|lower == "none" %}-1{% else %}{{ states(activepage.entity) | int }}{% endif %}
|
||||
statetopic: '{{ "hasp/" ~ haspname ~ "/state" }}'
|
||||
commandtopic: '{{ "hasp/" ~ haspname ~ "/command/" ~ haspobject }}'
|
||||
jsontopic: '{{ "hasp/" ~ haspname ~ "/state/json" }}'
|
||||
jsoncommandtopic: '{{ "hasp/" ~ haspname ~ "/command/json" }}'
|
||||
haspsensor: >-
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^sensor\..+_sensor(?:_\d+|)$") -%}
|
||||
{{ entity }}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
haspIP: '{{state_attr(haspsensor, "haspIP")}}'
|
||||
@ -317,14 +315,12 @@ trigger_variables:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^sensor\.") -%}
|
||||
{{- entity|regex_replace(find="^sensor\.", replace="", ignorecase=true)|regex_replace(find="_sensor(?:_\d+|)$", replace="", ignorecase=true) -}}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
haspsensor: >-
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^sensor\..+_sensor(?:_\d+|)$") -%}
|
||||
{{ entity }}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
jsontopic: '{{ "hasp/" ~ haspname ~ "/state/json" }}'
|
||||
@ -359,87 +355,8 @@ action:
|
||||
# Create required helpers and apply HASP defaults when "RUN ACTIONS" is pressed by the user
|
||||
- conditions:
|
||||
- condition: template
|
||||
value_template: "{{ trigger is not defined }}"
|
||||
value_template: "{{ (trigger is not defined) or (trigger.platform is none) }}"
|
||||
sequence:
|
||||
# Push discovery messages for RGB lights used to configure themes
|
||||
- service: mqtt.publish
|
||||
data:
|
||||
topic: "homeassistant/light/{{haspname}}/selectedforegroundcolor/config"
|
||||
payload: >-
|
||||
{"name":"{{haspname}} selected foreground color",
|
||||
"command_topic":"hasp/{{haspname}}/light/selectedforegroundcolor/switch",
|
||||
"state_topic":"hasp/{{haspname}}/alwayson",
|
||||
"rgb_command_topic":"hasp/{{haspname}}/light/selectedforegroundcolor/rgb",
|
||||
"rgb_command_template": {% raw %}"{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}",{% endraw %}
|
||||
"retain":false,
|
||||
"unique_id":"{{haspClientId}}-selectedforegroundcolor",
|
||||
"device":{"identifiers":["{{haspClientId}}"],
|
||||
"name":"{{haspname}}",
|
||||
"manufacturer":"{{haspManufacturer}}",
|
||||
"model":"{{haspModel}}",
|
||||
"sw_version":{{sw_version}}
|
||||
}}
|
||||
retain: true
|
||||
- service: mqtt.publish
|
||||
data:
|
||||
topic: "homeassistant/light/{{haspname}}/selectedbackgroundcolor/config"
|
||||
payload: >-
|
||||
{"name":"{{haspname}} selected background color",
|
||||
"command_topic":"hasp/{{haspname}}/light/selectedbackgroundcolor/switch",
|
||||
"state_topic":"hasp/{{haspname}}/alwayson",
|
||||
"rgb_command_topic":"hasp/{{haspname}}/light/selectedbackgroundcolor/rgb",
|
||||
"rgb_command_template": {% raw %}"{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}",{% endraw %}
|
||||
"retain":false,
|
||||
"unique_id":"{{haspClientId}}-selectedbackgroundcolor",
|
||||
"device":{
|
||||
"identifiers":["{{haspClientId}}"],
|
||||
"name":"{{haspname}}",
|
||||
"manufacturer":"{{haspManufacturer}}",
|
||||
"model":"{{haspModel}}",
|
||||
"sw_version":{{sw_version}}
|
||||
}}
|
||||
retain: true
|
||||
- service: mqtt.publish
|
||||
data:
|
||||
topic: "homeassistant/light/{{haspname}}/unselectedforegroundcolor/config"
|
||||
payload: >-
|
||||
{"name":"{{haspname}} unselected foreground color",
|
||||
"command_topic":"hasp/{{haspname}}/light/unselectedforegroundcolor/switch",
|
||||
"state_topic":"hasp/{{haspname}}/alwayson",
|
||||
"rgb_command_topic":"hasp/{{haspname}}/light/unselectedforegroundcolor/rgb",
|
||||
"rgb_command_template": {% raw %}"{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}",{% endraw %}
|
||||
"retain":false,
|
||||
"unique_id":"{{haspClientId}}-unselectedforegroundcolor",
|
||||
"device":{"identifiers":["{{haspClientId}}"],
|
||||
"name":"{{haspname}}",
|
||||
"manufacturer":"{{haspManufacturer}}",
|
||||
"model":"{{haspModel}}",
|
||||
"sw_version":{{sw_version}}
|
||||
}}
|
||||
retain: true
|
||||
- service: mqtt.publish
|
||||
data:
|
||||
topic: "homeassistant/light/{{haspname}}/unselectedbackgroundcolor/config"
|
||||
payload: >-
|
||||
{"name":"{{haspname}} unselected background color",
|
||||
"command_topic":"hasp/{{haspname}}/light/unselectedbackgroundcolor/switch",
|
||||
"state_topic":"hasp/{{haspname}}/alwayson",
|
||||
"rgb_command_topic":"hasp/{{haspname}}/light/unselectedbackgroundcolor/rgb",
|
||||
"rgb_command_template": {% raw %}"{{ (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int }}",{% endraw %}
|
||||
"retain":false,
|
||||
"unique_id":"{{haspClientId}}-unselectedbackgroundcolor",
|
||||
"device":{"identifiers":["{{haspClientId}}"],
|
||||
"name":"{{haspname}}",
|
||||
"manufacturer":"{{haspManufacturer}}",
|
||||
"model":"{{haspModel}}",
|
||||
"sw_version":{{sw_version}}
|
||||
}}
|
||||
retain: true
|
||||
- service: mqtt.publish
|
||||
data:
|
||||
topic: "hasp/{{haspname}}/alwayson"
|
||||
payload: "ON"
|
||||
retain: true
|
||||
# Send page select button config
|
||||
- service: mqtt.publish
|
||||
data:
|
||||
@ -448,6 +365,7 @@ action:
|
||||
[{% for p in range(1,12) %}"p[{{p}}].b[1].font={{page1font}}","p[{{p}}].b[1].txt=\"{{page1text}}\"",{% endfor %}
|
||||
{% for p in range(1,12) %}"p[{{p}}].b[2].font={{page2font}}","p[{{p}}].b[2].txt=\"{% if page_scroll %}{{page_names.get("page" ~ p)}}{% else %}{{page2text}}{% endif %}\"",{% endfor %}
|
||||
{% for p in range(1,12) %}"p[{{p}}].b[3].font={{page3font}}","p[{{p}}].b[3].txt=\"{{page3text}}\""{% if not loop.last %},{% endif %}{% endfor %}]
|
||||
|
||||
- choose:
|
||||
#########################################################################
|
||||
# Create a notification with the lovelace entity card YAML
|
||||
@ -455,7 +373,6 @@ action:
|
||||
- condition: template
|
||||
value_template: "{{ show_lovelace }}"
|
||||
sequence:
|
||||
- delay: "00:00:01"
|
||||
- service: persistent_notification.create
|
||||
data:
|
||||
title: "{{haspname}} Lovelace Card"
|
||||
@ -551,14 +468,12 @@ action:
|
||||
data:
|
||||
topic: "hasp/{{haspname}}/state/page"
|
||||
payload: "0"
|
||||
- delay: "00:00:01"
|
||||
- service: light.turn_on
|
||||
data:
|
||||
entity_id: >-
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_selected_foreground_color(?:_\d+|)$") -%}
|
||||
{{ entity }}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
rgb_color: "{{default_selected_foreground_color}}"
|
||||
@ -568,7 +483,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_selected_foreground_color(?:_\d+|)$") -%}
|
||||
{{ entity }}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
brightness: "{{default_selected_foreground_brightness}}"
|
||||
@ -578,7 +492,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_selected_background_color(?:_\d+|)$") -%}
|
||||
{{ entity }}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
rgb_color: "{{default_selected_background_color}}"
|
||||
@ -588,7 +501,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_selected_background_color(?:_\d+|)$") -%}
|
||||
{{ entity }}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
brightness: "{{default_selected_background_brightness}}"
|
||||
@ -598,7 +510,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_unselected_foreground_color(?:_\d+|)$") -%}
|
||||
{{ entity }}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
rgb_color: "{{default_unselected_foreground_color}}"
|
||||
@ -608,7 +519,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_unselected_foreground_color(?:_\d+|)$") -%}
|
||||
{{ entity }}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
brightness: "{{default_unselected_foreground_brightness}}"
|
||||
@ -618,7 +528,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_unselected_background_color(?:_\d+|)$") -%}
|
||||
{{ entity }}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
rgb_color: "{{default_unselected_background_color}}"
|
||||
@ -628,7 +537,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_unselected_background_color(?:_\d+|)$") -%}
|
||||
{{ entity }}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
brightness: "{{default_unselected_background_brightness}}"
|
||||
@ -642,6 +550,86 @@ action:
|
||||
topic: "hasp/{{haspname}}/command/page"
|
||||
payload: "{% if page_scroll %}{{page2page}}{% else %}{{page1page}}{% endif %}"
|
||||
retain: true
|
||||
- service: mqtt.publish # apply selected foreground color to page select buttons
|
||||
data:
|
||||
topic: "{{jsoncommandtopic}}"
|
||||
payload: >-
|
||||
{%- 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 / 255 -%}
|
||||
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int -%}
|
||||
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int -%}
|
||||
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int -%}
|
||||
{%- set colorcode = (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int -%}
|
||||
[{%- if not page_scroll -%}{%- for p in range(1,12) %}{%- if p == page1page|int %}"p[{{p}}].b[1].pco={{colorcode}}"{%- else -%}"p[{{p}}].b[1].pco2={{colorcode}}"{%- endif -%},{%- endfor -%}
|
||||
{%- else -%}{%- for p in range(1,12) %}"p[{{p}}].b[1].pco2={{colorcode}}",{%- endfor -%}{%- endif -%}
|
||||
{%- for p in range(1,12) %}{%- if p == page2page|int %}"p[{{p}}].b[2].pco={{colorcode}}"{%- else -%}"p[{{p}}].b[2].pco2={{colorcode}}"{%- endif -%},{%- endfor -%}
|
||||
{%- if not page_scroll -%}{%- for p in range(1,12) %}{%- if p == page3page|int %}"p[{{p}}].b[3].pco={{colorcode}}"{%- else -%}"p[{{p}}].b[3].pco2={{colorcode}}"{%- endif -%}{% if not loop.last %},{% endif %}{%- endfor -%}
|
||||
{%- else -%}{%- for p in range(1,12) %}"p[{{p}}].b[3].pco2={{colorcode}}"{% if not loop.last %},{% endif %}{%- endfor -%}{%- endif -%}]
|
||||
- service: mqtt.publish # apply selected background color to page select buttons
|
||||
data:
|
||||
topic: "{{jsoncommandtopic}}"
|
||||
payload: >-
|
||||
{%- 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 / 255 -%}
|
||||
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int -%}
|
||||
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int -%}
|
||||
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int -%}
|
||||
{%- set colorcode = (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int -%}
|
||||
[{%- if not page_scroll -%}{%- for p in range(1,12) %}{%- if p == page1page|int %}"p[{{p}}].b[1].bco={{colorcode}}"{%- else -%}"p[{{p}}].b[1].bco2={{colorcode}}"{%- endif -%},{%- endfor -%}
|
||||
{% else %}{%- for p in range(1,12) %}"p[{{p}}].b[1].bco2={{colorcode}}",{%- endfor -%}{%- endif -%}
|
||||
{%- for p in range(1,12) %}{%- if p == page2page|int %}"p[{{p}}].b[2].bco={{colorcode}}"{%- else -%}"p[{{p}}].b[2].bco2={{colorcode}}"{%- endif -%},{%- endfor -%}
|
||||
{%- if not page_scroll -%}{%- for p in range(1,12) %}{%- if p == page3page|int %}"p[{{p}}].b[3].bco={{colorcode}}"{%- else -%}"p[{{p}}].b[3].bco2={{colorcode}}"{%- endif -%}{% if not loop.last %},{% endif %}{%- endfor -%}
|
||||
{% else %}{%- for p in range(1,12) %}"p[{{p}}].b[3].bco2={{colorcode}}"{% if not loop.last %},{% endif %}{%- endfor -%}{%- endif -%}]
|
||||
- service: mqtt.publish # apply unselected foreground color to page select buttons
|
||||
data:
|
||||
topic: "{{jsoncommandtopic}}"
|
||||
payload: >-
|
||||
{%- 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 / 255 -%}
|
||||
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int -%}
|
||||
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int -%}
|
||||
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int -%}
|
||||
{%- set colorcode = (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int -%}
|
||||
[{%- if not page_scroll -%}{%- for p in range(1,12) %}{%- if p == page1page|int %}"p[{{p}}].b[1].pco2={{colorcode}}"{%- else -%}"p[{{p}}].b[1].pco={{colorcode}}"{%- endif -%},{%- endfor -%}
|
||||
{% else %}{%- for p in range(1,12) %}"p[{{p}}].b[1].pco={{colorcode}}",{%- endfor -%}{%- endif -%}
|
||||
{%- for p in range(1,12) %}{%- if p == page2page|int %}"p[{{p}}].b[2].pco2={{colorcode}}"{%- else -%}"p[{{p}}].b[2].pco={{colorcode}}"{%- endif -%},{%- endfor -%}
|
||||
{%- if not page_scroll -%}{%- for p in range(1,12) %}{%- if p == page3page|int %}"p[{{p}}].b[3].pco2={{colorcode}}"{%- else -%}"p[{{p}}].b[3].pco={{colorcode}}"{%- endif -%}{% if not loop.last %},{% endif %}{%- endfor -%}
|
||||
{% else %}{%- for p in range(1,12) %}"p[{{p}}].b[3].pco={{colorcode}}"{% if not loop.last %},{% endif %}{%- endfor -%}{%- endif -%}]
|
||||
- service: mqtt.publish # apply unselected background color to page select buttons
|
||||
data:
|
||||
topic: "{{jsoncommandtopic}}"
|
||||
payload: >-
|
||||
{%- 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 / 255 -%}
|
||||
{%- set red=(state_attr(color.source, "rgb_color")[0] * brightness)|int -%}
|
||||
{%- set green=(state_attr(color.source, "rgb_color")[1] * brightness)|int -%}
|
||||
{%- set blue=(state_attr(color.source, "rgb_color")[2] * brightness)|int -%}
|
||||
{%- set colorcode = (red|bitwise_and(248)*256) + (green|bitwise_and(252)*8) + (blue|bitwise_and(248)/8)|int -%}
|
||||
[{%- if not page_scroll -%}{%- for p in range(1,12) %}{%- if p == page1page|int %}"p[{{p}}].b[1].bco2={{colorcode}}"{%- else -%}"p[{{p}}].b[1].bco={{colorcode}}"{%- endif -%},{%- endfor -%}
|
||||
{% else %}{%- for p in range(1,12) %}"p[{{p}}].b[1].bco={{colorcode}}",{%- endfor -%}{%- endif -%}
|
||||
{%- for p in range(1,12) %}{%- if p == page2page|int %}"p[{{p}}].b[2].bco2={{colorcode}}"{%- else -%}"p[{{p}}].b[2].bco={{colorcode}}"{%- endif -%},{%- endfor -%}
|
||||
{%- if not page_scroll -%}{%- for p in range(1,12) %}{%- if p == page3page|int %}"p[{{p}}].b[3].bco2={{colorcode}}"{%- else -%}"p[{{p}}].b[3].bco={{colorcode}}"{%- endif -%}{% if not loop.last %},{% endif %}{%- endfor -%}
|
||||
{% else %}{%- for p in range(1,12) %}"p[{{p}}].b[3].bco={{colorcode}}"{% if not loop.last %},{% endif %}{%- endfor -%}{%- endif -%}]
|
||||
|
||||
#########################################################################
|
||||
# Push configuration to device when it connects or Home Assistant starts
|
||||
@ -669,7 +657,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_selected_foreground_color(?:_\d+|)$") -%}
|
||||
{%- set color.source=entity -%}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- set brightness = state_attr(color.source, "brightness")|int / 255 -%}
|
||||
@ -690,7 +677,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_selected_background_color(?:_\d+|)$") -%}
|
||||
{%- set color.source=entity -%}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- set brightness = state_attr(color.source, "brightness")|int / 255 -%}
|
||||
@ -711,7 +697,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_unselected_foreground_color(?:_\d+|)$") -%}
|
||||
{%- set color.source=entity -%}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- set brightness = state_attr(color.source, "brightness")|int / 255 -%}
|
||||
@ -732,7 +717,6 @@ action:
|
||||
{%- for entity in device_entities(haspdevice) -%}
|
||||
{%- if entity|regex_search("^light\..*_unselected_background_color(?:_\d+|)$") -%}
|
||||
{%- set color.source=entity -%}
|
||||
{{ break }}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- set brightness = state_attr(color.source, "brightness")|int / 255 -%}
|
||||
|
Loading…
x
Reference in New Issue
Block a user