Merge pull request #94 from HASwitchPlate/dev-1.02

1.02 release
This commit is contained in:
Allen Derusha 2021-05-03 16:17:20 -04:00 committed by GitHub
commit 2098a87c3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 125 additions and 166 deletions

View File

@ -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);

View File

@ -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.
@ -355,85 +357,6 @@ action:
- condition: template
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:
@ -442,87 +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 %}]
- delay: "00:00:01" # give MQTT discovery a second to find our RGB theme lights
- 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 -%}]
- choose:
#########################################################################
# Create a notification with the lovelace entity card YAML
@ -530,7 +373,6 @@ action:
- condition: template
value_template: "{{ show_lovelace }}"
sequence:
- delay: "00:00:01"
- service: persistent_notification.create
data:
title: "{{haspname}} Lovelace Card"
@ -588,6 +430,15 @@ action:
name: Unselected Background Color
secondary_info: brightness
- type: divider
- type: attribute
entity: {{haspsensor}}
attribute: espVersion
name: {{haspname}} ESP firmware
- type: attribute
entity: {{haspsensor}}
attribute: lcdVersion
name: {{haspname}} LCD firmware
- type: divider
footer:
type: buttons
entities:
@ -626,7 +477,6 @@ action:
data:
topic: "hasp/{{haspname}}/state/page"
payload: "0"
- delay: "00:00:01"
- service: light.turn_on
data:
entity_id: >-
@ -709,6 +559,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

View File

@ -1,6 +1,6 @@
{
"d1_mini": {
"version": "1.01",
"version": "1.02",
"firmware": "https://raw.githubusercontent.com/HASwitchPlate/HASPone/main/Arduino_Sketch/HASwitchPlate.ino.d1_mini.bin"
},
"NX3224T024_011R": {