diff --git a/Arduino_Sketch/HASwitchPlate.ino.d1_mini.bin b/Arduino_Sketch/HASwitchPlate.ino.d1_mini.bin index 415edbc..168f0f6 100644 Binary files a/Arduino_Sketch/HASwitchPlate.ino.d1_mini.bin and b/Arduino_Sketch/HASwitchPlate.ino.d1_mini.bin differ diff --git a/Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino b/Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino index a0d4f27..baeb507 100755 --- a/Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino +++ b/Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino @@ -59,7 +59,7 @@ char motionPinConfig[3] = "0"; #include #include -const float haspVersion = 0.36; // Current HASP software release version +const float haspVersion = 0.37; // Current HASP software release version byte nextionReturnBuffer[128]; // Byte array to pass around data coming from the panel uint8_t nextionReturnIndex = 0; // Index for nextionReturnBuffer uint8_t nextionActivePage = 0; // Track active LCD page @@ -99,7 +99,9 @@ byte espMac[6]; // Byte array to store our M const uint16_t mqttMaxPacketSize = 4096; // Size of buffer for incoming MQTT message String mqttClientId; // Auto-generated MQTT ClientID String mqttGetSubtopic; // MQTT subtopic for incoming commands requesting .val +String mqttGetSubtopicJSON; // MQTT object buffer for JSON status when requesting .val String mqttStateTopic; // MQTT topic for outgoing panel interactions +String mqttStateJSONTopic; // MQTT topic for outgoing panel interactions in JSON format String mqttCommandTopic; // MQTT topic for incoming panel commands String mqttGroupCommandTopic; // MQTT topic for incoming group panel commands String mqttStatusTopic; // MQTT topic for publishing device connectivity state @@ -111,15 +113,17 @@ String mqttLightBrightStateTopic; // MQTT topic for outgoing p String mqttMotionStateTopic; // MQTT topic for outgoing motion sensor state String nextionModel; // Record reported model number of LCD panel const byte nextionSuffix[] = {0xFF, 0xFF, 0xFF}; // Standard suffix for Nextion commands -long tftFileSize = 0; // Filesize for TFT firmware upload +uint32_t tftFileSize = 0; // Filesize for TFT firmware upload uint8_t nextionResetPin = D6; // Pin for Nextion power rail switch (GPIO12/D6) WiFiClient wifiClient; +WiFiClient wifiMQTTClient; MQTTClient mqttClient(mqttMaxPacketSize); ESP8266WebServer webServer(80); ESP8266HTTPUpdateServer httpOTAUpdate; WiFiServer telnetServer(23); WiFiClient telnetClient; +MDNSResponder::hMDNSService hMDNSService; // Additional CSS style to match Hass theme const char HASP_STYLE[] = ""; @@ -162,19 +166,17 @@ void setup() espWifiSetup(); // Start up networking if (mdnsEnabled) - { - MDNS.begin(haspNode); // Add mDNS hostname - // MDNS.addService("http", "tcp", 80); this breaks Wemo devices when Home Assistant discovery is enabled. No idea why. + { // Setup mDNS service discovery if enabled + hMDNSService = MDNS.addService(haspNode, "http", "tcp", 80); if (debugTelnetEnabled) { - MDNS.addService("telnet", "tcp", 23); + MDNS.addService(haspNode, "telnet", "tcp", 23); } - MDNS.addServiceTxt("arduino", "tcp", "app_name", "HASwitchPlate"); - MDNS.addServiceTxt("arduino", "tcp", "app_version", String(haspVersion)); - MDNS.addServiceTxt("arduino", "tcp", "mac", WiFi.macAddress()); + MDNS.addServiceTxt(hMDNSService, "app_name", "HASwitchPlate"); + MDNS.addServiceTxt(hMDNSService, "app_version", String(haspVersion).c_str()); MDNS.update(); } - + if ((configPassword[0] != '\0') && (configUser[0] != '\0')) { httpOTAUpdate.setup(&webServer, "/update", configUser, configPassword); @@ -188,9 +190,11 @@ void setup() webServer.on("/resetConfig", webHandleResetConfig); webServer.on("/firmware", webHandleFirmware); webServer.on("/espfirmware", webHandleEspFirmware); - webServer.on("/lcdupload", HTTP_POST, []() { webServer.send(200, "text/plain", ""); }, webHandleLcdUpload); + webServer.on("/lcdupload", HTTP_POST, []() { webServer.send(200); }, webHandleLcdUpload); webServer.on("/tftFileSize", webHandleTftFileSize); webServer.on("/lcddownload", webHandleLcdDownload); + webServer.on("/lcdOtaSuccess", webHandleLcdUpdateSuccess); + webServer.on("/lcdOtaFailure", webHandleLcdUpdateFailure); webServer.on("/reboot", webHandleReboot); webServer.onNotFound(webHandleNotFound); webServer.begin(); @@ -199,7 +203,7 @@ void setup() espSetupOta(); // Create server and assign callbacks for MQTT - mqttClient.begin(mqttServer, atoi(mqttPort), wifiClient); + mqttClient.begin(mqttServer, atoi(mqttPort), wifiMQTTClient); mqttClient.onMessage(mqttCallback); mqttConnect(); @@ -208,12 +212,10 @@ void setup() if (debugTelnetEnabled) { // Setup telnet server for remote debug output - telnetServer.setNoDelay(true); telnetServer.begin(); debugPrintln(String(F("TELNET: debug server enabled at telnet:")) + WiFi.localIP().toString()); } - debugPrintln(F("SYSTEM: System init complete.")); } @@ -292,6 +294,8 @@ void loop() { handleTelnetClient(); // telnetClient loop } + + delay(10); // Spooky voodoo which claims to improve WiFi stability. } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -325,6 +329,7 @@ void mqttConnect() } // MQTT topic string definitions mqttStateTopic = "hasp/" + String(haspNode) + "/state"; + mqttStateJSONTopic = "hasp/" + String(haspNode) + "/state/json"; mqttCommandTopic = "hasp/" + String(haspNode) + "/command"; mqttGroupCommandTopic = "hasp/" + String(groupName) + "/command"; mqttStatusTopic = "hasp/" + String(haspNode) + "/status"; @@ -414,18 +419,18 @@ void mqttConnect() debugPrintln(String(F("MQTT connection attempt ")) + String(mqttReconnectCount) + String(F(" failed with rc ")) + String(mqttClient.returnCode()) + String(F(". Restarting device."))); espReset(); } - debugPrintln(String(F("MQTT connection attempt ")) + String(mqttReconnectCount) + String(F(" failed with rc ")) + String(mqttClient.returnCode()) + String(F(". Trying again in 10 seconds."))); - nextionSetAttr("p[0].b[1].txt", "\"WiFi Connected:\\r" + WiFi.localIP().toString() + "\\rMQTT Connect to" + String(mqttServer) + "\\rFAILED rc=" + String(mqttClient.returnCode()) + "\\rRetry in 10 sec\""); + debugPrintln(String(F("MQTT connection attempt ")) + String(mqttReconnectCount) + String(F(" failed with rc ")) + String(mqttClient.returnCode()) + String(F(". Trying again in 30 seconds."))); + nextionSetAttr("p[0].b[1].txt", "\"WiFi Connected:\\r" + WiFi.localIP().toString() + "\\rMQTT Connect to" + String(mqttServer) + "\\rFAILED rc=" + String(mqttClient.returnCode()) + "\\rRetry in 30 sec\""); unsigned long mqttReconnectTimer = millis(); // record current time for our timeout - while ((millis() - mqttReconnectTimer) < 10000) - { // Handle HTTP and OTA while we're waiting 10sec for MQTT to reconnect - yield(); + while ((millis() - mqttReconnectTimer) < 30000) + { // Handle HTTP and OTA while we're waiting 30sec for MQTT to reconnect if (nextionHandleInput()) { // Process user input from HMI nextionProcessInput(); } webServer.handleClient(); ArduinoOTA.handle(); + delay(10); } } } @@ -455,7 +460,7 @@ void mqttCallback(String &strTopic, String &strPayload) debugPrintln(String(F("MQTT IN: '")) + strTopic + "' : '" + strPayload + "'"); if (((strTopic == mqttCommandTopic) || (strTopic == mqttGroupCommandTopic)) && (strPayload == "")) - { // '[...]/device/command' -m '' = No command requested, respond with mqttStatusUpdate() + { // '[...]/device/command' -m '' = No command requested, respond with mqttStatusUpdate() mqttStatusUpdate(); // return status JSON via MQTT } else if (strTopic == mqttCommandTopic || strTopic == mqttGroupCommandTopic) @@ -471,11 +476,11 @@ void mqttCallback(String &strTopic, String &strPayload) } } else if (strTopic == (mqttCommandTopic + "/json") || strTopic == (mqttGroupCommandTopic + "/json")) - { // '[...]/device/command/json' -m '["dim=5", "page 1"]' = nextionSendCmd("dim=50"), nextionSendCmd("page 1") + { // '[...]/device/command/json' -m '["dim=5", "page 1"]' = nextionSendCmd("dim=50"), nextionSendCmd("page 1") nextionParseJson(strPayload); // Send to nextionParseJson() } else if (strTopic == (mqttCommandTopic + "/statusupdate") || strTopic == (mqttGroupCommandTopic + "/statusupdate")) - { // '[...]/device/command/statusupdate' == mqttStatusUpdate() + { // '[...]/device/command/statusupdate' == mqttStatusUpdate() mqttStatusUpdate(); // return status JSON via MQTT } else if (strTopic == (mqttCommandTopic + "/lcdupdate") || strTopic == (mqttGroupCommandTopic + "/lcdupdate")) @@ -594,7 +599,9 @@ void mqttStatusUpdate() mqttStatusPayload += String(F("\"espUptime\":")) + String(long(millis() / 1000)) + String(F(",")); mqttStatusPayload += String(F("\"signalStrength\":")) + String(WiFi.RSSI()) + String(F(",")); mqttStatusPayload += String(F("\"haspIP\":\"")) + WiFi.localIP().toString() + String(F("\",")); - mqttStatusPayload += String(F("\"heapFree\":")) + String(ESP.getFreeHeap()); + mqttStatusPayload += String(F("\"heapFree\":")) + String(ESP.getFreeHeap()) + String(F(",")); + mqttStatusPayload += String(F("\"heapFragmentation\":")) + String(ESP.getHeapFragmentation()) + String(F(",")); + mqttStatusPayload += String(F("\"espCore\":\"")) + String(ESP.getCoreVersion()) + String(F("\"")); mqttStatusPayload += "}"; mqttClient.publish(mqttSensorTopic, mqttStatusPayload); @@ -667,6 +674,8 @@ void nextionProcessInput() String mqttButtonTopic = mqttStateTopic + "/p[" + nextionPage + "].b[" + nextionButtonID + "]"; debugPrintln(String(F("MQTT OUT: '")) + mqttButtonTopic + "' : 'ON'"); mqttClient.publish(mqttButtonTopic, "ON"); + String mqttButtonJSONEvent = String(F("{\"event\":\"p[")) + String(nextionPage) + String(F("].b[")) + String(nextionButtonID) + String(F("]\", \"value\":\"ON\"}")); + mqttClient.publish(mqttStateJSONTopic, mqttButtonJSONEvent); } if (nextionButtonAction == 0x00) { @@ -674,10 +683,15 @@ void nextionProcessInput() String mqttButtonTopic = mqttStateTopic + "/p[" + nextionPage + "].b[" + nextionButtonID + "]"; debugPrintln(String(F("MQTT OUT: '")) + mqttButtonTopic + "' : 'OFF'"); mqttClient.publish(mqttButtonTopic, "OFF"); + // Burger King Hobbies is up to something with these two lines below, not sure what exactly. + // String mqttButtonJSONEvent = String(F("{\"event\":\"p[")) + String(nextionPage) + String(F("].b[")) + String(nextionButtonID) + String(F("]\", \"value\":\"OFF\"}")); + // mqttClient.publish(mqttStateJSONTopic, mqttButtonJSONEvent); + // // Now see if this object has a .val that might have been updated. // works for sliders, two-state buttons, etc, throws a 0x1A error for normal buttons // which we'll catch and ignore mqttGetSubtopic = "/p[" + nextionPage + "].b[" + nextionButtonID + "].val"; + mqttGetSubtopicJSON = "p[" + nextionPage + "].b[" + nextionButtonID + "].val"; nextionGetAttr("p[" + nextionPage + "].b[" + nextionButtonID + "].val"); } } @@ -774,6 +788,8 @@ void nextionProcessInput() { String mqttReturnTopic = mqttStateTopic + mqttGetSubtopic; mqttClient.publish(mqttReturnTopic, getString); + String mqttButtonJSONEvent = String(F("{\"event\":\"")) + mqttGetSubtopicJSON + String(F("\", \"value\":")) + getString + String(F("}")); + mqttClient.publish(mqttStateJSONTopic, mqttButtonJSONEvent); mqttGetSubtopic = ""; } } @@ -858,27 +874,30 @@ void nextionStartOtaDownload(String otaUrl) // based in large part on code posted by indev2 here: // http://support.iteadstudio.com/support/discussions/topics/11000007686/page/2 - int lcdOtaFileSize = 0; + uint32_t lcdOtaFileSize = 0; String lcdOtaNextionCmd; - int lcdOtaChunkCounter = 0; + uint32_t lcdOtaChunkCounter = 0; uint16_t lcdOtaPartNum = 0; - int lcdOtaTransferred = 0; - int lcdOtaPercentComplete = 0; + uint32_t lcdOtaTransferred = 0; + uint8_t lcdOtaPercentComplete = 0; + const uint32_t lcdOtaTimeout = 30000; // timeout for receiving new data in milliseconds + static uint32_t lcdOtaTimer = 0; // timer for upload timeout - debugPrintln(String(F("LCD OTA: Attempting firmware download from:")) + otaUrl); + debugPrintln(String(F("LCD OTA: Attempting firmware download from: ")) + otaUrl); + WiFiClient lcdOtaWifi; HTTPClient lcdOtaHttp; - lcdOtaHttp.begin(otaUrl); + lcdOtaHttp.begin(lcdOtaWifi, otaUrl); int lcdOtaHttpReturn = lcdOtaHttp.GET(); if (lcdOtaHttpReturn > 0) { // HTTP header has been sent and Server response header has been handled debugPrintln(String(F("LCD OTA: HTTP GET return code:")) + String(lcdOtaHttpReturn)); if (lcdOtaHttpReturn == HTTP_CODE_OK) - { // file found at server - // get length of document (is -1 when Server sends no Content-Length header) - int lcdOtaRemaining = lcdOtaHttp.getSize(); + { // file found at server + int32_t lcdOtaRemaining = lcdOtaHttp.getSize(); // get length of document (is -1 when Server sends no Content-Length header) lcdOtaFileSize = lcdOtaRemaining; - int lcdOtaParts = (lcdOtaRemaining / 4096) + 1; - uint8_t lcdOtaBuffer[128] = {}; // max size of ESP8266 UART buffer + static uint16_t lcdOtaParts = (lcdOtaRemaining / 4096) + 1; + static const uint16_t lcdOtaBufferSize = 1024; // upload data buffer before sending to UART + static uint8_t lcdOtaBuffer[lcdOtaBufferSize] = {}; debugPrintln(String(F("LCD OTA: File found at Server. Size ")) + String(lcdOtaRemaining) + String(F(" bytes in ")) + String(lcdOtaParts) + String(F(" 4k chunks."))); @@ -891,13 +910,10 @@ void nextionStartOtaDownload(String otaUrl) mqttClient.disconnect(); } - // get tcp stream - WiFiClient *stream = lcdOtaHttp.getStreamPtr(); - // Send empty command - Serial1.write(nextionSuffix, sizeof(nextionSuffix)); + WiFiClient *stream = lcdOtaHttp.getStreamPtr(); // get tcp stream + Serial1.write(nextionSuffix, sizeof(nextionSuffix)); // Send empty command Serial1.flush(); nextionHandleInput(); - String lcdOtaNextionCmd = "whmi-wri " + String(lcdOtaFileSize) + ",115200,0"; debugPrintln(String(F("LCD OTA: Sending LCD upload command: ")) + lcdOtaNextionCmd); Serial1.print(lcdOtaNextionCmd); @@ -914,17 +930,29 @@ void nextionStartOtaDownload(String otaUrl) espReset(); } debugPrintln(F("LCD OTA: Starting update")); + lcdOtaTimer = millis(); while (lcdOtaHttp.connected() && (lcdOtaRemaining > 0 || lcdOtaRemaining == -1)) - { // Write incoming data to panel as it arrives - // get available data size - size_t lcdOtaHttpSize = stream->available(); + { // Write incoming data to panel as it arrives + uint16_t lcdOtaHttpSize = stream->available(); // get available data size + if (lcdOtaHttpSize) { - // read up to 128 bytes - int lcdOtaChunkSize = stream->readBytes(lcdOtaBuffer, ((lcdOtaHttpSize > sizeof(lcdOtaBuffer)) ? sizeof(lcdOtaBuffer) : lcdOtaHttpSize)); - // write it to panel - Serial1.flush(); - Serial1.write(lcdOtaBuffer, lcdOtaChunkSize); + uint16_t lcdOtaChunkSize = 0; + if ((lcdOtaHttpSize <= lcdOtaBufferSize) && (lcdOtaHttpSize <= (4096 - lcdOtaChunkCounter))) + { + lcdOtaChunkSize = lcdOtaHttpSize; + } + else if ((lcdOtaBufferSize <= lcdOtaHttpSize) && (lcdOtaBufferSize <= (4096 - lcdOtaChunkCounter))) + { + lcdOtaChunkSize = lcdOtaBufferSize; + } + else + { + lcdOtaChunkSize = 4096 - lcdOtaChunkCounter; + } + stream->readBytes(lcdOtaBuffer, lcdOtaChunkSize); + Serial1.flush(); // make sure any previous writes the UART have completed + Serial1.write(lcdOtaBuffer, lcdOtaChunkSize); // now send buffer to the UART lcdOtaChunkCounter += lcdOtaChunkSize; if (lcdOtaChunkCounter >= 4096) { @@ -934,8 +962,9 @@ void nextionStartOtaDownload(String otaUrl) lcdOtaPercentComplete = (lcdOtaTransferred * 100) / lcdOtaFileSize; lcdOtaChunkCounter = 0; if (nextionOtaResponse()) - { - // debugPrintln(String(F("LCD OTA: Part ")) + String(lcdOtaPartNum) + String(F(" OK, ")) + String(lcdOtaPercentComplete) + String(F("% complete"))); + { // We've completed a chunk + debugPrintln(String(F("LCD OTA: Part ")) + String(lcdOtaPartNum) + String(F(" OK, ")) + String(lcdOtaPercentComplete) + String(F("% complete"))); + lcdOtaTimer = millis(); } else { @@ -954,19 +983,29 @@ void nextionStartOtaDownload(String otaUrl) lcdOtaRemaining -= lcdOtaChunkSize; } } + delay(10); + if ((lcdOtaTimer > 0) && ((millis() - lcdOtaTimer) > lcdOtaTimeout)) + { // Our timer expired so reset + debugPrintln(F("LCD OTA: ERROR: LCD upload timeout. Restarting.")); + espReset(); + } } lcdOtaPartNum++; lcdOtaTransferred += lcdOtaChunkCounter; if ((lcdOtaTransferred == lcdOtaFileSize) && nextionOtaResponse()) { - debugPrintln(String(F("LCD OTA: success, wrote ")) + String(lcdOtaTransferred) + " of " + String(lcdOtaFileSize) + " bytes."); - delay(5000); // extra delay while the LCD does its thing + debugPrintln(String(F("LCD OTA: Success, wrote ")) + String(lcdOtaTransferred) + " of " + String(tftFileSize) + " bytes."); + uint32_t lcdOtaDelay = millis(); + while ((millis() - lcdOtaDelay) < 5000) + { // extra 5sec delay while the LCD handles any local firmware updates from new versions of code sent to it + webServer.handleClient(); + delay(1); + } espReset(); } else { - debugPrintln(F("LCD OTA: failure")); - delay(2000); // extra delay while the LCD does its thing + debugPrintln(F("LCD OTA: Failure")); espReset(); } } @@ -1287,7 +1326,7 @@ void espStartOta(String espOtaUrl) nextionSetAttr("p[0].b[1].txt", "\"HTTP update\\rstarting...\""); WiFiUDP::stopAll(); // Keep mDNS responder from breaking things - t_httpUpdate_return returnCode = ESPhttpUpdate.update(espOtaUrl); + t_httpUpdate_return returnCode = ESPhttpUpdate.update(wifiClient, espOtaUrl); switch (returnCode) { case HTTP_UPDATE_FAILED: @@ -1645,6 +1684,8 @@ void webHandleRoot() httpMessage += String(F("
Sketch Size: ")) + String(ESP.getSketchSize()) + String(F(" bytes")); httpMessage += String(F("
Free Sketch Space: ")) + String(ESP.getFreeSketchSpace()) + String(F(" bytes")); httpMessage += String(F("
Heap Free: ")) + String(ESP.getFreeHeap()); + httpMessage += String(F("
Heap Fragmentation: ")) + String(ESP.getHeapFragmentation()); + httpMessage += String(F("
ESP core version: ")) + String(ESP.getCoreVersion()); httpMessage += String(F("
IP Address: ")) + String(WiFi.localIP().toString()); httpMessage += String(F("
Signal Strength: ")) + String(WiFi.RSSI()); httpMessage += String(F("
Uptime: ")) + String(long(millis() / 1000)); @@ -1941,11 +1982,14 @@ void webHandleLcdUpload() } } - static int lcdOtaTransferred = 0; - static int lcdOtaRemaining; - static int lcdOtaParts; + static uint32_t lcdOtaTransferred = 0; + static uint32_t lcdOtaRemaining; + static uint16_t lcdOtaParts; + const uint32_t lcdOtaTimeout = 30000; // timeout for receiving new data in milliseconds + static uint32_t lcdOtaTimer = 0; // timer for upload timeout HTTPUpload &upload = webServer.upload(); + if (tftFileSize == 0) { debugPrintln(String(F("LCD OTA: FAILED, no filesize sent."))); @@ -1961,28 +2005,14 @@ void webHandleLcdUpload() httpMessage += FPSTR(HTTP_END); webServer.send(200, "text/html", httpMessage); } + else if ((lcdOtaTimer > 0) && ((millis() - lcdOtaTimer) > lcdOtaTimeout)) + { // Our timer expired so reset + debugPrintln(F("LCD OTA: ERROR: LCD upload timeout. Restarting.")); + espReset(); + } else if (upload.status == UPLOAD_FILE_START) { - String httpMessage = FPSTR(HTTP_HEAD); - httpMessage.replace("{v}", (String(haspNode) + " LCD update")); - httpMessage += FPSTR(HTTP_SCRIPT); - httpMessage += FPSTR(HTTP_STYLE); - httpMessage += String(HASP_STYLE); - httpMessage += String(F("")); - httpMessage += FPSTR(HTTP_HEAD_END); - httpMessage += String(F("

")) + String(haspNode) + " LCD update

"; - httpMessage += String(F("Completing LCD firmware update from: ")) + String(upload.filename); - httpMessage += FPSTR(HTTP_END); - webServer.send(200, "text/html", httpMessage); - - WiFiUDP::stopAll(); // Keep mDNS responder and MQTT traffic from breaking things - if (mqttClient.connected()) - { - debugPrintln(F("LCD OTA: LCD firmware upload starting, closing MQTT connection.")); - mqttClient.publish(mqttStatusTopic, "OFF"); - mqttClient.publish(mqttSensorTopic, "{\"status\": \"unavailable\"}"); - mqttClient.disconnect(); - } + WiFiUDP::stopAll(); // Keep mDNS responder from breaking things debugPrintln(String(F("LCD OTA: Attempting firmware upload"))); debugPrintln(String(F("LCD OTA: upload.filename: ")) + String(upload.filename)); @@ -1991,8 +2021,8 @@ void webHandleLcdUpload() lcdOtaRemaining = tftFileSize; lcdOtaParts = (lcdOtaRemaining / 4096) + 1; debugPrintln(String(F("LCD OTA: File upload beginning. Size ")) + String(lcdOtaRemaining) + String(F(" bytes in ")) + String(lcdOtaParts) + String(F(" 4k chunks."))); - // Send empty command to LCD - Serial1.write(nextionSuffix, sizeof(nextionSuffix)); + + Serial1.write(nextionSuffix, sizeof(nextionSuffix)); // Send empty command to LCD Serial1.flush(); nextionHandleInput(); @@ -2004,27 +2034,43 @@ void webHandleLcdUpload() if (nextionOtaResponse()) { - debugPrintln(F("LCD OTA: LCD upload command accepted.")); + debugPrintln(F("LCD OTA: LCD upload command accepted")); } else { debugPrintln(F("LCD OTA: LCD upload command FAILED.")); espReset(); } + lcdOtaTimer = millis(); } else if (upload.status == UPLOAD_FILE_WRITE) - { + { // Handle upload data static int lcdOtaChunkCounter = 0; static uint16_t lcdOtaPartNum = 0; static int lcdOtaPercentComplete = 0; - uint8_t lcdOtaBuffer[128] = {}; // max size of ESP8266 UART buffer + static const uint16_t lcdOtaBufferSize = 1024; // upload data buffer before sending to UART + static uint8_t lcdOtaBuffer[lcdOtaBufferSize] = {}; uint16_t lcdOtaUploadIndex = 0; - size_t lcdOtaPacketRemaining = upload.currentSize; + int32_t lcdOtaPacketRemaining = upload.currentSize; + while (lcdOtaPacketRemaining > 0) { // Write incoming data to panel as it arrives - // read up to 128 bytes or whatever is left of the current packet - size_t lcdOtaChunkSize = ((lcdOtaPacketRemaining > sizeof(lcdOtaBuffer)) ? sizeof(lcdOtaBuffer) : lcdOtaPacketRemaining); - for (uint8_t i = 0; i < lcdOtaChunkSize; i++) + // determine chunk size as lowest value of lcdOtaPacketRemaining, lcdOtaBufferSize, or 4096 - lcdOtaChunkCounter + uint16_t lcdOtaChunkSize = 0; + if ((lcdOtaPacketRemaining <= lcdOtaBufferSize) && (lcdOtaPacketRemaining <= (4096 - lcdOtaChunkCounter))) + { + lcdOtaChunkSize = lcdOtaPacketRemaining; + } + else if ((lcdOtaBufferSize <= lcdOtaPacketRemaining) && (lcdOtaBufferSize <= (4096 - lcdOtaChunkCounter))) + { + lcdOtaChunkSize = lcdOtaBufferSize; + } + else + { + lcdOtaChunkSize = 4096 - lcdOtaChunkCounter; + } + + for (uint16_t i = 0; i < lcdOtaChunkSize; i++) { // Load up the UART buffer lcdOtaBuffer[i] = upload.buf[lcdOtaUploadIndex]; lcdOtaUploadIndex++; @@ -2050,7 +2096,7 @@ void webHandleLcdUpload() } else { - delay(20); + delay(10); } if (lcdOtaRemaining > 0) { @@ -2067,48 +2113,142 @@ void webHandleLcdUpload() if (nextionOtaResponse()) { debugPrintln(String(F("LCD OTA: Success, wrote ")) + String(lcdOtaTransferred) + " of " + String(tftFileSize) + " bytes."); - // delay(5000); // extra delay while the LCD does its thing + webServer.sendHeader("Location", "/lcdOtaSuccess"); + webServer.send(303); + uint32_t lcdOtaDelay = millis(); + while ((millis() - lcdOtaDelay) < 5000) + { // extra 5sec delay while the LCD handles any local firmware updates from new versions of code sent to it + webServer.handleClient(); + delay(1); + } espReset(); } else { debugPrintln(F("LCD OTA: Failure")); + webServer.sendHeader("Location", "/lcdOtaFailure"); + webServer.send(303); + uint32_t lcdOtaDelay = millis(); + while ((millis() - lcdOtaDelay) < 1000) + { // extra 1sec delay for client to grab failure page + webServer.handleClient(); + delay(1); + } espReset(); } } + lcdOtaTimer = millis(); } else if (upload.status == UPLOAD_FILE_END) - { + { // Upload completed if (lcdOtaTransferred >= tftFileSize) { if (nextionOtaResponse()) - { + { // YAY WE DID IT debugPrintln(String(F("LCD OTA: Success, wrote ")) + String(lcdOtaTransferred) + " of " + String(tftFileSize) + " bytes."); - // delay(5000); // extra delay while the LCD does its thing + webServer.sendHeader("Location", "/lcdOtaSuccess"); + webServer.send(303); + uint32_t lcdOtaDelay = millis(); + while ((millis() - lcdOtaDelay) < 5000) + { // extra 5sec delay while the LCD handles any local firmware updates from new versions of code sent to it + webServer.handleClient(); + delay(1); + } espReset(); } else { debugPrintln(F("LCD OTA: Failure")); - // delay(5000); // delay for user to read output + webServer.sendHeader("Location", "/lcdOtaFailure"); + webServer.send(303); + uint32_t lcdOtaDelay = millis(); + while ((millis() - lcdOtaDelay) < 1000) + { // extra 1sec delay for client to grab failure page + webServer.handleClient(); + delay(1); + } espReset(); } } } else if (upload.status == UPLOAD_FILE_ABORTED) - { + { // Something went kablooey debugPrintln(F("LCD OTA: ERROR: upload.status returned: UPLOAD_FILE_ABORTED")); - // delay(5000); // delay for user to read output + debugPrintln(F("LCD OTA: Failure")); + webServer.sendHeader("Location", "/lcdOtaFailure"); + webServer.send(303); + uint32_t lcdOtaDelay = millis(); + while ((millis() - lcdOtaDelay) < 1000) + { // extra 1sec delay for client to grab failure page + webServer.handleClient(); + delay(1); + } espReset(); } else - { + { // Something went weird, we should never get here... debugPrintln(String(F("LCD OTA: upload.status returned: ")) + String(upload.status)); - // delay(5000); // delay for user to read output + debugPrintln(F("LCD OTA: Failure")); + webServer.sendHeader("Location", "/lcdOtaFailure"); + webServer.send(303); + uint32_t lcdOtaDelay = millis(); + while ((millis() - lcdOtaDelay) < 1000) + { // extra 1sec delay for client to grab failure page + webServer.handleClient(); + delay(1); + } espReset(); } } +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleLcdUpdateSuccess() +{ // http://plate01/lcdOtaSuccess + if (configPassword[0] != '\0') + { //Request HTTP auth if configPassword is set + if (!webServer.authenticate(configUser, configPassword)) + { + return webServer.requestAuthentication(); + } + } + debugPrintln(String(F("HTTP: Sending /lcdOtaSuccess page to client connected from: ")) + webServer.client().remoteIP().toString()); + String httpMessage = FPSTR(HTTP_HEAD); + httpMessage.replace("{v}", (String(haspNode) + " LCD update success")); + httpMessage += FPSTR(HTTP_SCRIPT); + httpMessage += FPSTR(HTTP_STYLE); + httpMessage += String(HASP_STYLE); + httpMessage += String(F("")); + httpMessage += FPSTR(HTTP_HEAD_END); + httpMessage += String(F("

")) + String(haspNode) + String(F(" LCD update success

")); + httpMessage += String(F("Restarting HASwitchPlate to apply changes...")); + httpMessage += FPSTR(HTTP_END); + webServer.send(200, "text/html", httpMessage); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +void webHandleLcdUpdateFailure() +{ // http://plate01/lcdOtaFailure + if (configPassword[0] != '\0') + { //Request HTTP auth if configPassword is set + if (!webServer.authenticate(configUser, configPassword)) + { + return webServer.requestAuthentication(); + } + } + debugPrintln(String(F("HTTP: Sending /lcdOtaFailure page to client connected from: ")) + webServer.client().remoteIP().toString()); + String httpMessage = FPSTR(HTTP_HEAD); + httpMessage.replace("{v}", (String(haspNode) + " LCD update failed")); + httpMessage += FPSTR(HTTP_SCRIPT); + httpMessage += FPSTR(HTTP_STYLE); + httpMessage += String(HASP_STYLE); + httpMessage += String(F("")); + httpMessage += FPSTR(HTTP_HEAD_END); + httpMessage += String(F("

")) + String(haspNode) + String(F(" LCD update failed :(

")); + httpMessage += String(F("Restarting HASwitchPlate to reset device...")); + httpMessage += FPSTR(HTTP_END); + webServer.send(200, "text/html", httpMessage); +} + //////////////////////////////////////////////////////////////////////////////////////////////////// void webHandleLcdDownload() { // http://plate01/lcddownload @@ -2133,7 +2273,7 @@ void webHandleLcdDownload() httpMessage += FPSTR(HTTP_END); webServer.send(200, "text/html", httpMessage); - debugPrintln("LCDFW: Attempting LCD firmware update from: " + String(webServer.arg("lcdFirmware"))); + // debugPrintln("LCDFW: Attempting LCD firmware update from: " + String(webServer.arg("lcdFirmware"))); nextionStartOtaDownload(webServer.arg("lcdFirmware")); } @@ -2191,7 +2331,7 @@ bool updateCheck() HTTPClient updateClient; debugPrintln(String(F("UPDATE: Checking update URL: ")) + String(UPDATE_URL)); String updatePayload; - updateClient.begin(UPDATE_URL); + updateClient.begin(wifiClient, UPDATE_URL); // start connection and send HTTP header int httpCode = updateClient.GET(); @@ -2360,14 +2500,13 @@ void handleTelnetClient() void debugPrintln(String debugText) { // Debug output line of text to our debug targets String debugTimeText = "[+" + String(float(millis()) / 1000, 3) + "s] " + debugText; + Serial.println(debugTimeText); if (debugSerialEnabled) { SoftwareSerial debugSerial = SoftwareSerial(17, 1); // 17==nc for RX, 1==TX pin debugSerial.begin(115200); debugSerial.println(debugTimeText); debugSerial.flush(); - Serial.println(debugTimeText); - Serial.flush(); } if (debugTelnetEnabled) { @@ -2386,15 +2525,13 @@ void debugPrint(String debugText) // happens. Far better to put everything into a line and send it all out in one packet using // debugPrintln. if (debugSerialEnabled) + Serial.print(debugText); { SoftwareSerial debugSerial = SoftwareSerial(17, 1); // 17==nc for RX, 1==TX pin debugSerial.begin(115200); debugSerial.print(debugText); debugSerial.flush(); - Serial.print(debugText); - Serial.flush(); } - if (debugTelnetEnabled) { if (telnetClient.connected()) diff --git a/Home_Assistant/hasppackages.tar.gz b/Home_Assistant/hasppackages.tar.gz index 20af866..f8fcf74 100644 Binary files a/Home_Assistant/hasppackages.tar.gz and b/Home_Assistant/hasppackages.tar.gz differ diff --git a/Home_Assistant/packages/plate01/hasp_plate01_00_components.yaml b/Home_Assistant/packages/plate01/hasp_plate01_00_components.yaml index aed71d0..7420bc1 100755 --- a/Home_Assistant/packages/plate01/hasp_plate01_00_components.yaml +++ b/Home_Assistant/packages/plate01/hasp_plate01_00_components.yaml @@ -47,16 +47,11 @@ binary_sensor: sensor: - platform: mqtt name: plate01 Sensor - state_topic: "hasp/plate01/sensor" - value_template: '{{ value_json.status }}' - json_attributes: - - espVersion - - updateESPAvailable - - lcdVersion - - updateLcdAvailable - - espUptime - - signalStrength - - haspIP + state_topic: "hasp/plate01/status" + availability_topic: "hasp/plate01/status" + payload_available: "ON" + payload_not_available: "OFF" + json_attributes_topic: "hasp/plate01/sensor" input_text: hasp_plate01_pagebutton1label: diff --git a/contrib/openHAB/HASP-Foyer.items b/contrib/openHAB/HASP-Foyer.items index 2653827..68ce630 100644 --- a/contrib/openHAB/HASP-Foyer.items +++ b/contrib/openHAB/HASP-Foyer.items @@ -1,128 +1,3 @@ -Group HASP_Plate02_Button1_Group -Group HASP_Plate02_Button2_Group -Group HASP_Plate02_Button3_Group -Group HASP_Plate02_Page1_Button_Group -Group HASP_Plate02_Page2_Button_Group -Group HASP_Plate02_Page3_Button_Group -Group HASP_Plate02_Page4_Button_Group -Group HASP_Plate02_Page4_Dimmer_Group -Group HASP_Plate02_Page5_Button_Group -Group HASP_Plate02_Page5_Dimmer_Group -Group HASP_Plate02_Page6_Button_Group -Group HASP_Plate02_Page7_Button_Group -Group HASP_Plate02_Page8_Button_Group -Group HASP_Plate02_Page8_Dimmer_Group -Group HASP_Plate02_Page9_Button_Group - -Switch HASP_Plate02_Button_P0B1 "HASP Plate 02 Page 0 Button 1 State [%s]" {mqtt="<[broker:hasp/plate02/state/p[0].b[1]:state:default]"} - -Switch HASP_Plate02_Button_P1B1 "HASP Plate 02 Page 1 Button 1 State [%s]" (HASP_Plate02_Button1_Group) {mqtt="<[broker:hasp/plate02/state/p[1].b[1]:state:default]"} -Switch HASP_Plate02_Button_P2B1 "HASP Plate 02 Page 2 Button 1 State [%s]" (HASP_Plate02_Button1_Group) {mqtt="<[broker:hasp/plate02/state/p[2].b[1]:state:default]"} -Switch HASP_Plate02_Button_P3B1 "HASP Plate 02 Page 3 Button 1 State [%s]" (HASP_Plate02_Button1_Group) {mqtt="<[broker:hasp/plate02/state/p[3].b[1]:state:default]"} -Switch HASP_Plate02_Button_P4B1 "HASP Plate 02 Page 4 Button 1 State [%s]" (HASP_Plate02_Button1_Group) {mqtt="<[broker:hasp/plate02/state/p[4].b[1]:state:default]"} -Switch HASP_Plate02_Button_P5B1 "HASP Plate 02 Page 5 Button 1 State [%s]" (HASP_Plate02_Button1_Group) {mqtt="<[broker:hasp/plate02/state/p[5].b[1]:state:default]"} -Switch HASP_Plate02_Button_P6B1 "HASP Plate 02 Page 6 Button 1 State [%s]" (HASP_Plate02_Button1_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[1]:state:default]"} -Switch HASP_Plate02_Button_P7B1 "HASP Plate 02 Page 7 Button 1 State [%s]" (HASP_Plate02_Button1_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[1]:state:default]"} -Switch HASP_Plate02_Button_P8B1 "HASP Plate 02 Page 8 Button 1 State [%s]" (HASP_Plate02_Button1_Group) {mqtt="<[broker:hasp/plate02/state/p[8].b[1]:state:default]"} -Switch HASP_Plate02_Button_P9B1 "HASP Plate 02 Page 9 Button 1 State [%s]" (HASP_Plate02_Button1_Group) {mqtt="<[broker:hasp/plate02/state/p[9].b[1]:state:default]"} - -Switch HASP_Plate02_Button_P1B2 "HASP Plate 02 Page 1 Button 2 State [%s]" (HASP_Plate02_Button2_Group) {mqtt="<[broker:hasp/plate02/state/p[1].b[2]:state:default]"} -Switch HASP_Plate02_Button_P2B2 "HASP Plate 02 Page 2 Button 2 State [%s]" (HASP_Plate02_Button2_Group) {mqtt="<[broker:hasp/plate02/state/p[2].b[2]:state:default]"} -Switch HASP_Plate02_Button_P3B2 "HASP Plate 02 Page 3 Button 2 State [%s]" (HASP_Plate02_Button2_Group) {mqtt="<[broker:hasp/plate02/state/p[3].b[2]:state:default]"} -Switch HASP_Plate02_Button_P4B2 "HASP Plate 02 Page 4 Button 2 State [%s]" (HASP_Plate02_Button2_Group) {mqtt="<[broker:hasp/plate02/state/p[4].b[2]:state:default]"} -Switch HASP_Plate02_Button_P5B2 "HASP Plate 02 Page 5 Button 2 State [%s]" (HASP_Plate02_Button2_Group) {mqtt="<[broker:hasp/plate02/state/p[5].b[2]:state:default]"} -Switch HASP_Plate02_Button_P6B2 "HASP Plate 02 Page 6 Button 2 State [%s]" (HASP_Plate02_Button2_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[2]:state:default]"} -Switch HASP_Plate02_Button_P7B2 "HASP Plate 02 Page 7 Button 2 State [%s]" (HASP_Plate02_Button2_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[2]:state:default]"} -Switch HASP_Plate02_Button_P8B2 "HASP Plate 02 Page 8 Button 2 State [%s]" (HASP_Plate02_Button2_Group) {mqtt="<[broker:hasp/plate02/state/p[8].b[2]:state:default]"} -Switch HASP_Plate02_Button_P9B2 "HASP Plate 02 Page 9 Button 2 State [%s]" (HASP_Plate02_Button2_Group) {mqtt="<[broker:hasp/plate02/state/p[9].b[2]:state:default]"} - -Switch HASP_Plate02_Button_P1B3 "HASP Plate 02 Page 1 Button 3 State [%s]" (HASP_Plate02_Button3_Group) {mqtt="<[broker:hasp/plate02/state/p[1].b[3]:state:default]"} -Switch HASP_Plate02_Button_P2B3 "HASP Plate 02 Page 2 Button 3 State [%s]" (HASP_Plate02_Button3_Group) {mqtt="<[broker:hasp/plate02/state/p[2].b[3]:state:default]"} -Switch HASP_Plate02_Button_P3B3 "HASP Plate 02 Page 3 Button 3 State [%s]" (HASP_Plate02_Button3_Group) {mqtt="<[broker:hasp/plate02/state/p[3].b[3]:state:default]"} -Switch HASP_Plate02_Button_P4B3 "HASP Plate 02 Page 4 Button 3 State [%s]" (HASP_Plate02_Button3_Group) {mqtt="<[broker:hasp/plate02/state/p[4].b[3]:state:default]"} -Switch HASP_Plate02_Button_P5B3 "HASP Plate 02 Page 5 Button 3 State [%s]" (HASP_Plate02_Button3_Group) {mqtt="<[broker:hasp/plate02/state/p[5].b[3]:state:default]"} -Switch HASP_Plate02_Button_P6B3 "HASP Plate 02 Page 6 Button 3 State [%s]" (HASP_Plate02_Button3_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[3]:state:default]"} -Switch HASP_Plate02_Button_P7B3 "HASP Plate 02 Page 7 Button 3 State [%s]" (HASP_Plate02_Button3_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[3]:state:default]"} -Switch HASP_Plate02_Button_P8B3 "HASP Plate 02 Page 8 Button 3 State [%s]" (HASP_Plate02_Button3_Group) {mqtt="<[broker:hasp/plate02/state/p[8].b[3]:state:default]"} -Switch HASP_Plate02_Button_P9B3 "HASP Plate 02 Page 9 Button 3 State [%s]" (HASP_Plate02_Button3_Group) {mqtt="<[broker:hasp/plate02/state/p[9].b[3]:state:default]"} - -/* Page 1 Functional Items */ -Switch HASP_Plate02_Button_P1B4 "HASP Plate 02 Page 1 Button 4 State [%s]" (HASP_Plate02_Page1_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[1].b[4]:state:default]"} -Switch HASP_Plate02_Button_P1B5 "HASP Plate 02 Page 1 Button 5 State [%s]" (HASP_Plate02_Page1_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[1].b[5]:state:default]"} -Switch HASP_Plate02_Button_P1B6 "HASP Plate 02 Page 1 Button 6 State [%s]" (HASP_Plate02_Page1_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[1].b[6]:state:default]"} -Switch HASP_Plate02_Button_P1B7 "HASP Plate 02 Page 1 Button 7 State [%s]" (HASP_Plate02_Page1_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[1].b[7]:state:default]"} - -/* Page 2 Functional Items */ -Switch HASP_Plate02_Button_P2B4 "HASP Plate 02 Page 2 Button 4 State [%s]" (HASP_Plate02_Page2_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[2].b[4]:state:default]"} -Switch HASP_Plate02_Button_P2B5 "HASP Plate 02 Page 2 Button 5 State [%s]" (HASP_Plate02_Page2_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[2].b[5]:state:default]"} -Switch HASP_Plate02_Button_P2B6 "HASP Plate 02 Page 2 Button 6 State [%s]" (HASP_Plate02_Page2_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[2].b[6]:state:default]"} -Switch HASP_Plate02_Button_P2B7 "HASP Plate 02 Page 2 Button 7 State [%s]" (HASP_Plate02_Page2_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[2].b[7]:state:default]"} - -/* Page 3 Functional Items */ -Switch HASP_Plate02_Button_P3B4 "HASP Plate 02 Page 3 Button 4 State [%s]" (HASP_Plate02_Page3_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[3].b[4]:state:default]"} -Switch HASP_Plate02_Button_P3B5 "HASP Plate 02 Page 3 Button 5 State [%s]" (HASP_Plate02_Page3_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[3].b[5]:state:default]"} -Switch HASP_Plate02_Button_P3B6 "HASP Plate 02 Page 3 Button 6 State [%s]" (HASP_Plate02_Page3_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[3].b[6]:state:default]"} -Switch HASP_Plate02_Button_P3B7 "HASP Plate 02 Page 3 Button 7 State [%s]" (HASP_Plate02_Page3_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[3].b[7]:state:default]"} - -/* Page 4 Functional Items */ -Switch HASP_Plate02_Button_P4B4 "HASP Plate 02 Page 4 Button 4 State [%s]" (HASP_Plate02_Page4_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[4].b[4]:state:default]"} -Switch HASP_Plate02_Button_P4B5 "HASP Plate 02 Page 4 Button 5 State [%s]" (HASP_Plate02_Page4_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[4].b[5]:state:default]"} -Switch HASP_Plate02_Button_P4B6 "HASP Plate 02 Page 4 Button 6 State [%s]" (HASP_Plate02_Page4_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[4].b[6]:state:default]"} -Number HASP_Plate02_Dimmer_P4B7 "HASP Plate 02 Page 4 Dimmer 7 State [%d]" (HASP_Plate02_Page4_Dimmer_Group) {mqtt="<[broker:hasp/plate02/state/p[4].b[7].val:state:default]"} -Number HASP_Plate02_Dimmer_P4B7_Val "HASP Plate 02 Page 4 Dimmer 7 Value" {mqtt=">[broker:hasp/plate02/command/p[4].b[7].val:command:*:default]"} -Number HASP_Plate02_Dimmer_P4B8 "HASP Plate 02 Page 4 Dimmer 8 State [%d]" (HASP_Plate02_Page4_Dimmer_Group) {mqtt="<[broker:hasp/plate02/state/p[4].b[8].val:state:default]"} -Number HASP_Plate02_Dimmer_P4B8_Val "HASP Plate 02 Page 4 Dimmer 8 Value" {mqtt=">[broker:hasp/plate02/command/p[4].b[8].val:command:*:default]"} -Number HASP_Plate02_Dimmer_P4B9 "HASP Plate 02 Page 4 Dimmer 9 State [%d]" (HASP_Plate02_Page4_Dimmer_Group) {mqtt="<[broker:hasp/plate02/state/p[4].b[9].val:state:default]"} -Number HASP_Plate02_Dimmer_P4B9_Val "HASP Plate 02 Page 4 Dimmer 9 Value" {mqtt=">[broker:hasp/plate02/command/p[4].b[9].val:command:*:default]"} - -/* Page 5 Functional Items */ -Switch HASP_Plate02_Button_P5B4 "HASP Plate 02 Page 5 Button 4 State [%s]" (HASP_Plate02_Page5_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[5].b[4]:state:default]"} -Switch HASP_Plate02_Button_P5B5 "HASP Plate 02 Page 5 Button 5 State [%s]" (HASP_Plate02_Page5_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[5].b[5]:state:default]"} -Switch HASP_Plate02_Button_P5B6 "HASP Plate 02 Page 5 Button 6 State [%s]" (HASP_Plate02_Page5_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[5].b[6]:state:default]"} -Number HASP_Plate02_Dimmer_P5B7 "HASP Plate 02 Page 5 Dimmer 7 State [%d]" (HASP_Plate02_Page5_Dimmer_Group) {mqtt="<[broker:hasp/plate02/state/p[5].b[7].val:state:default]"} -Number HASP_Plate02_Dimmer_P5B7_Val "HASP Plate 02 Page 5 Dimmer 7 Value" {mqtt=">[broker:hasp/plate02/command/p[5].b[7].val:command:*:default]"} -Number HASP_Plate02_Dimmer_P5B8 "HASP Plate 02 Page 5 Dimmer 8 State [%d]" (HASP_Plate02_Page5_Dimmer_Group) {mqtt="<[broker:hasp/plate02/state/p[5].b[8].val:state:default]"} -Number HASP_Plate02_Dimmer_P5B8_Val "HASP Plate 02 Page 5 Dimmer 8 Value" {mqtt=">[broker:hasp/plate02/command/p[5].b[8].val:command:*:default]"} -Number HASP_Plate02_Dimmer_P5B9 "HASP Plate 02 Page 5 Dimmer 9 State [%d]" (HASP_Plate02_Page5_Dimmer_Group) {mqtt="<[broker:hasp/plate02/state/p[5].b[9].val:state:default]"} -Number HASP_Plate02_Dimmer_P5B9_Val "HASP Plate 02 Page 5 Dimmer 9 Value" {mqtt=">[broker:hasp/plate02/command/p[5].b[9].val:command:*:default]"} - -/* Page 6 Functional Items */ -Switch HASP_Plate02_Button_P6B4 "HASP Plate 02 Page 6 Button 4 State [%s]" (HASP_Plate02_Page6_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[4]:state:default]"} -Switch HASP_Plate02_Button_P6B5 "HASP Plate 02 Page 6 Button 5 State [%s]" (HASP_Plate02_Page6_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[5]:state:default]"} -Switch HASP_Plate02_Button_P6B6 "HASP Plate 02 Page 6 Button 6 State [%s]" (HASP_Plate02_Page6_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[6]:state:default]"} -Switch HASP_Plate02_Button_P6B7 "HASP Plate 02 Page 6 Button 7 State [%s]" (HASP_Plate02_Page6_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[7]:state:default]"} -Switch HASP_Plate02_Button_P6B8 "HASP Plate 02 Page 6 Button 8 State [%s]" (HASP_Plate02_Page6_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[8]:state:default]"} -Switch HASP_Plate02_Button_P6B9 "HASP Plate 02 Page 6 Button 9 State [%s]" (HASP_Plate02_Page6_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[9]:state:default]"} -Switch HASP_Plate02_Button_P6B10 "HASP Plate 02 Page 6 Button 10 State [%s]" (HASP_Plate02_Page6_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[10]:state:default]"} -Switch HASP_Plate02_Button_P6B11 "HASP Plate 02 Page 6 Button 11 State [%s]" (HASP_Plate02_Page6_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[6].b[11]:state:default]"} - -/* Page 7 Functional Items */ -Switch HASP_Plate02_Button_P7B4 "HASP Plate 02 Page 7 Button 4 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[4]:state:default]"} -Switch HASP_Plate02_Button_P7B5 "HASP Plate 02 Page 7 Button 5 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[5]:state:default]"} -Switch HASP_Plate02_Button_P7B6 "HASP Plate 02 Page 7 Button 6 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[6]:state:default]"} -Switch HASP_Plate02_Button_P7B7 "HASP Plate 02 Page 7 Button 7 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[7]:state:default]"} -Switch HASP_Plate02_Button_P7B8 "HASP Plate 02 Page 7 Button 8 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[8]:state:default]"} -Switch HASP_Plate02_Button_P7B9 "HASP Plate 02 Page 7 Button 9 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[9]:state:default]"} -Switch HASP_Plate02_Button_P7B10 "HASP Plate 02 Page 7 Button 10 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[10]:state:default]"} -Switch HASP_Plate02_Button_P7B11 "HASP Plate 02 Page 7 Button 11 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[11]:state:default]"} -Switch HASP_Plate02_Button_P7B12 "HASP Plate 02 Page 7 Button 12 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[12]:state:default]"} -Switch HASP_Plate02_Button_P7B13 "HASP Plate 02 Page 7 Button 13 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[13]:state:default]"} -Switch HASP_Plate02_Button_P7B14 "HASP Plate 02 Page 7 Button 14 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[14]:state:default]"} -Switch HASP_Plate02_Button_P7B15 "HASP Plate 02 Page 7 Button 15 State [%s]" (HASP_Plate02_Page7_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[7].b[15]:state:default]"} - -/* Page 8 Functional Items */ -Switch HASP_Plate02_Button_P8B4 "HASP Plate 02 Page 8 Button 4 State [%s]" (HASP_Plate02_Page8_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[8].b[4]:state:default]"} -Switch HASP_Plate02_Button_P8B5 "HASP Plate 02 Page 8 Button 5 State [%s]" (HASP_Plate02_Page8_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[8].b[5]:state:default]"} -Switch HASP_Plate02_Button_P8B6 "HASP Plate 02 Page 8 Button 6 State [%s]" (HASP_Plate02_Page8_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[8].b[6]:state:default]"} -Switch HASP_Plate02_Button_P8B7 "HASP Plate 02 Page 8 Button 7 State [%s]" (HASP_Plate02_Page8_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[8].b[7]:state:default]"} -Switch HASP_Plate02_Button_P8B8 "HASP Plate 02 Page 8 Button 8 State [%s]" (HASP_Plate02_Page8_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[8].b[8]:state:default]"} -Number HASP_Plate02_Dimmer_P8B9 "HASP Plate 02 Page 8 Dimmer 9 State [%d]" (HASP_Plate02_Page8_Dimmer_Group) {mqtt="<[broker:hasp/plate02/state/p[8].b[9].val:state:default]"} -Number HASP_Plate02_Dimmer_P8B9_Val "HASP Plate 02 Page 8 Dimmer 9 Value" {mqtt=">[broker:hasp/plate02/command/p[8].b[9].val:command:*:default]"} - -/* Page 9 Functional Items */ -Switch HASP_Plate02_Button_P9B4 "HASP Plate 02 Page 9 Button 4 State [%s]" (HASP_Plate02_Page9_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[9].b[4]:state:default]"} -Switch HASP_Plate02_Button_P9B5 "HASP Plate 02 Page 9 Button 5 State [%s]" (HASP_Plate02_Page9_Button_Group) {mqtt="<[broker:hasp/plate02/state/p[9].b[5]:state:default]"} - /* Page Storage Items */ Number HASP_Plate02_Page "HASP Plate 02 Page Select [%d]" (HASP) {mqtt=">[broker:hasp/plate02/command/page:command:*:default]"} @@ -152,4 +27,8 @@ Number HASP_Plate02_Plate_Motion "HASP Plate 02 Motion Status [%d]" (HASP) {mqtt String HASP_Plate02_Plate_Command "Hasp Plate 02 Command" (HASP) {mqtt=">[broker:hasp/plate02/command:command:*:default]"} -String HASP_Plate02_Plate_Command_JSON "Hasp Plate 02 JSON Command" (HASP) {mqtt=">[broker:hasp/plate02/command/json:command:*:default]"} \ No newline at end of file +String HASP_Plate02_Plate_Command_JSON "Hasp Plate 02 JSON Command" (HASP) {mqtt=">[broker:hasp/plate02/command/json:command:*:default]"} + +String HASP_Plate02_Plate_State_JSON "HASP Plate 02 JSON State" (HASP) {mqtt="<[broker:hasp/plate02/state/json:state:default]"} +String HASP_Plate02_Plate_State_JSON_Event "HASP Plate 02 JSON State Event" (HASP) {mqtt="<[broker:hasp/plate02/state/json:state:JSONPATH($.event)]"} +String HASP_Plate02_Plate_State_JSON_Value "HASP Plate 02 JSON State Value" (HASP) {mqtt="<[broker:hasp/plate02/state/json:state:JSONPATH($.value)]"} \ No newline at end of file diff --git a/contrib/openHAB/HASP-Foyer.rules b/contrib/openHAB/HASP-Foyer.rules index 1edca1c..0b45327 100644 --- a/contrib/openHAB/HASP-Foyer.rules +++ b/contrib/openHAB/HASP-Foyer.rules @@ -1,5 +1,3 @@ -//import java.util.Calendar - /* -------------------------------------- BEGIN USER CONFIG -------------------------------------- */ /* Configuration for the three page selection buttons at the bottom of the page */ @@ -132,405 +130,354 @@ Several examples are included (commented out) to get you started, whether you ju button is pressed, or toggle the output item depending on its current state. */ -rule "Handle HASP Foyer Page 0" -when - Item HASP_Plate02_Button_P0B1 received update ON -then - if(HASP_Plate02_Light_Power.state == OFF) - { - HASP_Plate02_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons from Page 0 here - */ - if (triggeringItem == HASP_Plate02_Button_P0B1) - { - //Insert action to perform if button 0 was pressed - - HASP_Plate02_Page.sendCommand(2 as Number) //This is only for when the HASP starts in page 0 and you need to go to a different page, this will send it to Page 2 - } - } -end - -rule "Handle HASP Foyer Page 1" -when - Member of HASP_Plate02_Page1_Button_Group received update ON -then - if(HASP_Plate02_Light_Power.state == OFF) - { - HASP_Plate02_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons from Page 1 here - */ - if (triggeringItem == HASP_Plate02_Button_P1B4) - { - //Insert action to perform if button 4 was pressed - - Scene_Morning.sendCommand(ON) //Example - Latching ON - send ON command from HASP button to turn item on - } - else if (triggeringItem == HASP_Plate02_Button_P1B5) - { - //Insert action to perform if button 5 was pressed - - // if(Scene_Evening == ON) //Example - Toggle - change item state using HASP button (turn OFF if ON and ON if OFF) - // { - // Scene_Evening.sendCommand(OFF) - // } - // else - // { - // Scene_Evening.sendCommand(ON) - // } - Scene_Evening.sendCommand(ON) - } - else if (triggeringItem == HASP_Plate02_Button_P1B6) - { - //Insert action to perform if button 6 was pressed - Scene_Night.sendCommand(ON) - } - else if (triggeringItem == HASP_Plate02_Button_P1B7) - { - //Insert action to perform if button 7 was pressed - Scene_Bedtime.sendCommand(ON) - } - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Foyer Page 2" -when - Member of HASP_Plate02_Page2_Button_Group received update ON -then - if(HASP_Plate02_Light_Power.state == OFF) - { - HASP_Plate02_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons from Page 2 here - */ - if (triggeringItem == HASP_Plate02_Button_P2B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P2B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P2B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P2B7) - { - //Insert action to perform if button 7 was pressed - } - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Foyer Page 3" -when - Member of HASP_Plate02_Page3_Button_Group received update ON -then - if(HASP_Plate02_Light_Power.state == OFF) - { - HASP_Plate02_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons from Page 3 here - */ - if (triggeringItem == HASP_Plate02_Button_P3B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P3B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P3B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P3B7) - { - //Insert action to perform if button 7 was pressed - } - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Foyer Page 4" -when - Member of HASP_Plate02_Page4_Button_Group received update ON or - Member of HASP_Plate02_Page4_Dimmer_Group received update -then - if(HASP_Plate02_Light_Power.state == OFF) - { - HASP_Plate02_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons/dimmers from Page 4 here - */ - if (triggeringItem == HASP_Plate02_Button_P4B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P4B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P4B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate02_Dimmer_P4B7) - { - //Insert action to perform if dimmer 1 was moved - } - else if (triggeringItem == HASP_Plate02_Dimmer_P4B8) - { - //Insert action to perform if dimmer 2 was moved - } - else if (triggeringItem == HASP_Plate02_Dimmer_P4B9) - { - //Insert action to perform if dimmer 3 was moved - } - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Foyer Page 5" -when - Member of HASP_Plate02_Page5_Button_Group received update ON or - Member of HASP_Plate02_Page5_Dimmer_Group received update -then - if(HASP_Plate02_Light_Power.state == OFF) - { - HASP_Plate02_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons/dimmers from Page 5 here - */ - if (triggeringItem == HASP_Plate02_Button_P5B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P5B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P5B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate02_Dimmer_P5B7) - { - //Insert action to perform if dimmer 1 was moved - - HASP_Plate02_Light_Dimmer.sendCommand(HASP_Plate02_Dimmer_P5B7.state.toString) //Example - send dimmer value to HASP Backlight item - } - else if (triggeringItem == HASP_Plate02_Dimmer_P5B8) - { - //Insert action to perform if dimmer 2 was moved - } - else if (triggeringItem == HASP_Plate02_Dimmer_P5B9) - { - //Insert action to perform if dimmer 3 was moved - } - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Foyer Page 6" +rule "Handle HASP Foyer" when - Member of HASP_Plate02_Page6_Button_Group received update ON + Item HASP_Plate02_Plate_State_JSON_Value received update then - if(HASP_Plate02_Light_Power.state == OFF) - { - HASP_Plate02_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons/dimmers from Page 6 here - */ - if (triggeringItem == HASP_Plate02_Button_P6B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P6B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P6B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P6B7) - { - //Insert action to perform if button 7 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P6B8) - { - //Insert action to perform if button 8 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P6B9) - { - //Insert action to perform if button 9 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P6B10) - { - //Insert action to perform if button 10 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P6B11) - { - //Insert action to perform if button 11 was moved - } - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Foyer Page 7" -when - Member of HASP_Plate02_Page7_Button_Group received update ON -then - if(HASP_Plate02_Light_Power.state == OFF) - { - HASP_Plate02_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons/dimmers from Page 7 here - */ - if (triggeringItem == HASP_Plate02_Button_P7B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P7B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P7B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P7B7) - { - //Insert action to perform if button 7 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P7B8) - { - //Insert action to perform if button 8 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P7B9) - { - //Insert action to perform if button 9 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P7B10) - { - //Insert action to perform if button 10 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P7B11) - { - //Insert action to perform if button 11 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P7B12) - { - //Insert action to perform if button 12 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P7B13) - { - //Insert action to perform if button 13 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P7B14) - { - //Insert action to perform if button 14 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P7B15) - { - //Insert action to perform if button 15 was moved - } - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end + //parse out data from JSON string (page, button, value) + var String eventpage = HASP_Plate02_Plate_State_JSON_Event.state.toString.split("\\[").get(1).split("\\]").get(0) + var String eventbutton = HASP_Plate02_Plate_State_JSON_Event.state.toString.split("\\[").get(2).split("\\]").get(0) -rule "Handle HASP Foyer Page 8" -when - Member of HASP_Plate02_Page8_Button_Group received update ON or - Member of HASP_Plate02_Page8_Dimmer_Group received update -then - if(HASP_Plate02_Light_Power.state == OFF) + if (HASP_Plate02_Plate_State_JSON_Value.state == 'OFF') { - HASP_Plate02_Light_Power.sendCommand(ON) + //Do nothing (button release event) + logInfo ("HASP", "Ignoring OFF event") } else - { - /* - Act on buttons/dimmers from Page 8 here - */ - if (triggeringItem == HASP_Plate02_Button_P8B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P8B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P8B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate02_Button_P8B7) - { - //Insert action to perform if button 7 was moved - } - else if (triggeringItem == HASP_Plate02_Button_P8B8) - { - //Insert action to perform if button 8 was moved - } - else if (triggeringItem == HASP_Plate02_Dimmer_P8B9) - { - //Insert action to perform if dimmer 9 was moved - } - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Foyer Page 9" -when - Member of HASP_Plate02_Page9_Button_Group received update ON -then - if(HASP_Plate02_Light_Power.state == OFF) { - HASP_Plate02_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons/dimmers from Page 9 here - */ - if (triggeringItem == HASP_Plate02_Button_P9B4) - { - //Insert action to perform if button 4 was pressed + //Handle Page/button/dimmer value event + if(HASP_Plate02_Light_Power.state == OFF) + { + HASP_Plate02_Light_Power.sendCommand(ON) + } + else + { + if ((eventbutton == '1' || eventbutton == '2' || eventbutton == '3') && eventpage != '0') //Handle the pressing of one of the 3 bottom page buttons + { + switch(eventbutton) + { + case '1': + { + HASP_Plate02_Page.sendCommand(plate02_pagebutton1page as Number) + } + case '2': + { + HASP_Plate02_Page.sendCommand(plate02_pagebutton2page as Number) + } + case '3': + { + HASP_Plate02_Page.sendCommand(plate02_pagebutton3page as Number) + } + } + HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + else + { + switch(eventpage) + { + case '0': + { + /* + Act on buttons from Page 0 here + */ + if (eventbutton == '1') + { + //Insert action to perform if button 0 was pressed + + HASP_Plate02_Page.sendCommand(2 as Number) //This is only for when the HASP starts in page 0 and you need to go to a different page, this will send it to Page 2 + } + } + case '1': + { + /* + Act on buttons from Page 1 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + + Scene_Morning.sendCommand(ON) //Example - Latching ON - send ON command from HASP button to turn item on + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + + // if(Scene_Evening == ON) //Example - Toggle - change item state using HASP button (turn OFF if ON and ON if OFF) + // { + // Scene_Evening.sendCommand(OFF) + // } + // else + // { + // Scene_Evening.sendCommand(ON) + // } + Scene_Evening.sendCommand(ON) + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + Scene_Night.sendCommand(ON) + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was pressed + Scene_Bedtime.sendCommand(ON) + } + HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '2': + { + /* + Act on buttons from Page 2 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was pressed + } + HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '3': + { + /* + Act on buttons from Page 3 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was pressed + } + HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '4': + { + /* + Act on buttons/dimmers from Page 4 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if dimmer 1 was moved + } + else if (eventbutton == '8') + { + //Insert action to perform if dimmer 2 was moved + } + else if (eventbutton == '9') + { + //Insert action to perform if dimmer 3 was moved + } + HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '5': + { + /* + Act on buttons/dimmers from Page 5 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if dimmer 1 was moved + if (HASP_Plate02_Plate_State_JSON_Value.state != 'ON'){ + HASP_Plate02_Light_Dimmer.sendCommand(HASP_Plate02_Plate_State_JSON_Value.state.toString) //Example - send dimmer value to HASP Backlight item + } + } + else if (eventbutton == '8') + { + //Insert action to perform if dimmer 2 was moved + } + else if (eventbutton == '9') + { + //Insert action to perform if dimmer 3 was moved + } + HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '6': + { + /* + Act on buttons/dimmers from Page 6 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was moved + } + else if (eventbutton == '8') + { + //Insert action to perform if button 8 was moved + } + else if (eventbutton == '9') + { + //Insert action to perform if button 9 was moved + } + else if (eventbutton == '10') + { + //Insert action to perform if button 10 was moved + } + else if (eventbutton == '11') + { + //Insert action to perform if button 11 was moved + } + HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '7': + { + /* + Act on buttons/dimmers from Page 7 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was moved + } + else if (eventbutton == '8') + { + //Insert action to perform if button 8 was moved + } + else if (eventbutton == '9') + { + //Insert action to perform if button 9 was moved + } + else if (eventbutton == '10') + { + //Insert action to perform if button 10 was moved + } + else if (eventbutton == '11') + { + //Insert action to perform if button 11 was moved + } + else if (eventbutton == '12') + { + //Insert action to perform if button 12 was moved + } + else if (eventbutton == '13') + { + //Insert action to perform if button 13 was moved + } + else if (eventbutton == '14') + { + //Insert action to perform if button 14 was moved + } + else if (eventbutton == '15') + { + //Insert action to perform if button 15 was moved + } + HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '8': + { + /* + Act on buttons/dimmers from Page 8 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was moved + } + else if (eventbutton == '8') + { + //Insert action to perform if button 8 was moved + } + else if (eventbutton == '9') + { + //Insert action to perform if dimmer 9 was moved + } + HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '9': + { + /* + Act on buttons/dimmers from Page 9 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + } + } } - else if (triggeringItem == HASP_Plate02_Button_P9B5) - { - //Insert action to perform if button 5 was pressed - } - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press } end @@ -573,7 +520,8 @@ rule "Handle HASP Foyer Page 5 dimmers" when Item HASP_Plate02_Light_Brightness received update then - HASP_Plate02_Dimmer_P5B8_Val.sendCommand(HASP_Plate02_Light_Brightness.state as Number) + var jsonString = '["p[5].b[8].val=' + HASP_Plate02_Light_Brightness.state + '"]' + HASP_Plate02_Plate_Command_JSON.sendCommand(jsonString) end rule "Handle HASP Foyer Page 9 chart" @@ -594,7 +542,7 @@ end /* Restore saved page and rebuild config on reconnect */ rule "HASP Foyer Restore page on connect" when - Item HASP_Plate02_Plate_Sensor_Status changed to "available" or + Item HASP_Plate02_Plate_Status changed to "ON" or Item HASP_Plate02_Plate_Refresh received command ON then @@ -755,33 +703,6 @@ then end -/* Select hasp_plate02_page in response to page button 1 */ -rule "HASP Foyer respond to page button 1" -when - Member of HASP_Plate02_Button1_Group received update ON -then - HASP_Plate02_Page.sendCommand(plate02_pagebutton1page as Number) - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press -end - -/* Select hasp_plate02_page in response to page button 2 */ -rule "HASP Foyer respond to page button 2" -when - Member of HASP_Plate02_Button2_Group received update ON -then - HASP_Plate02_Page.sendCommand(plate02_pagebutton2page as Number) - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press -end - -/* Select hasp_plate02_page in response to page button 3 */ -rule "HASP Foyer respond to page button 3" -when - Member of HASP_Plate02_Button3_Group received update ON -then - HASP_Plate02_Page.sendCommand(plate02_pagebutton3page as Number) - HASP_Plate02_Light_Power.sendCommand(ON) //refresh backlight timer following button press -end - /* Set page button colors based on current page */ rule "HASP Foyer set page button colors on page change" when diff --git a/contrib/openHAB/HASP-Master.items b/contrib/openHAB/HASP-Master.items index 06e968c..71b3936 100644 --- a/contrib/openHAB/HASP-Master.items +++ b/contrib/openHAB/HASP-Master.items @@ -1,128 +1,3 @@ -Group HASP_Plate01_Button1_Group -Group HASP_Plate01_Button2_Group -Group HASP_Plate01_Button3_Group -Group HASP_Plate01_Page1_Button_Group -Group HASP_Plate01_Page2_Button_Group -Group HASP_Plate01_Page3_Button_Group -Group HASP_Plate01_Page4_Button_Group -Group HASP_Plate01_Page4_Dimmer_Group -Group HASP_Plate01_Page5_Button_Group -Group HASP_Plate01_Page5_Dimmer_Group -Group HASP_Plate01_Page6_Button_Group -Group HASP_Plate01_Page7_Button_Group -Group HASP_Plate01_Page8_Button_Group -Group HASP_Plate01_Page8_Dimmer_Group -Group HASP_Plate01_Page9_Button_Group - -Switch HASP_Plate01_Button_P0B1 "HASP Plate 01 Page 0 Button 1 State [%s]" {mqtt="<[broker:hasp/plate01/state/p[0].b[1]:state:default]"} - -Switch HASP_Plate01_Button_P1B1 "HASP Plate 01 Page 1 Button 1 State [%s]" (HASP_Plate01_Button1_Group) {mqtt="<[broker:hasp/plate01/state/p[1].b[1]:state:default]"} -Switch HASP_Plate01_Button_P2B1 "HASP Plate 01 Page 2 Button 1 State [%s]" (HASP_Plate01_Button1_Group) {mqtt="<[broker:hasp/plate01/state/p[2].b[1]:state:default]"} -Switch HASP_Plate01_Button_P3B1 "HASP Plate 01 Page 3 Button 1 State [%s]" (HASP_Plate01_Button1_Group) {mqtt="<[broker:hasp/plate01/state/p[3].b[1]:state:default]"} -Switch HASP_Plate01_Button_P4B1 "HASP Plate 01 Page 4 Button 1 State [%s]" (HASP_Plate01_Button1_Group) {mqtt="<[broker:hasp/plate01/state/p[4].b[1]:state:default]"} -Switch HASP_Plate01_Button_P5B1 "HASP Plate 01 Page 5 Button 1 State [%s]" (HASP_Plate01_Button1_Group) {mqtt="<[broker:hasp/plate01/state/p[5].b[1]:state:default]"} -Switch HASP_Plate01_Button_P6B1 "HASP Plate 01 Page 6 Button 1 State [%s]" (HASP_Plate01_Button1_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[1]:state:default]"} -Switch HASP_Plate01_Button_P7B1 "HASP Plate 01 Page 7 Button 1 State [%s]" (HASP_Plate01_Button1_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[1]:state:default]"} -Switch HASP_Plate01_Button_P8B1 "HASP Plate 01 Page 8 Button 1 State [%s]" (HASP_Plate01_Button1_Group) {mqtt="<[broker:hasp/plate01/state/p[8].b[1]:state:default]"} -Switch HASP_Plate01_Button_P9B1 "HASP Plate 01 Page 9 Button 1 State [%s]" (HASP_Plate01_Button1_Group) {mqtt="<[broker:hasp/plate01/state/p[9].b[1]:state:default]"} - -Switch HASP_Plate01_Button_P1B2 "HASP Plate 01 Page 1 Button 2 State [%s]" (HASP_Plate01_Button2_Group) {mqtt="<[broker:hasp/plate01/state/p[1].b[2]:state:default]"} -Switch HASP_Plate01_Button_P2B2 "HASP Plate 01 Page 2 Button 2 State [%s]" (HASP_Plate01_Button2_Group) {mqtt="<[broker:hasp/plate01/state/p[2].b[2]:state:default]"} -Switch HASP_Plate01_Button_P3B2 "HASP Plate 01 Page 3 Button 2 State [%s]" (HASP_Plate01_Button2_Group) {mqtt="<[broker:hasp/plate01/state/p[3].b[2]:state:default]"} -Switch HASP_Plate01_Button_P4B2 "HASP Plate 01 Page 4 Button 2 State [%s]" (HASP_Plate01_Button2_Group) {mqtt="<[broker:hasp/plate01/state/p[4].b[2]:state:default]"} -Switch HASP_Plate01_Button_P5B2 "HASP Plate 01 Page 5 Button 2 State [%s]" (HASP_Plate01_Button2_Group) {mqtt="<[broker:hasp/plate01/state/p[5].b[2]:state:default]"} -Switch HASP_Plate01_Button_P6B2 "HASP Plate 01 Page 6 Button 2 State [%s]" (HASP_Plate01_Button2_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[2]:state:default]"} -Switch HASP_Plate01_Button_P7B2 "HASP Plate 01 Page 7 Button 2 State [%s]" (HASP_Plate01_Button2_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[2]:state:default]"} -Switch HASP_Plate01_Button_P8B2 "HASP Plate 01 Page 8 Button 2 State [%s]" (HASP_Plate01_Button2_Group) {mqtt="<[broker:hasp/plate01/state/p[8].b[2]:state:default]"} -Switch HASP_Plate01_Button_P9B2 "HASP Plate 01 Page 9 Button 2 State [%s]" (HASP_Plate01_Button2_Group) {mqtt="<[broker:hasp/plate01/state/p[9].b[2]:state:default]"} - -Switch HASP_Plate01_Button_P1B3 "HASP Plate 01 Page 1 Button 3 State [%s]" (HASP_Plate01_Button3_Group) {mqtt="<[broker:hasp/plate01/state/p[1].b[3]:state:default]"} -Switch HASP_Plate01_Button_P2B3 "HASP Plate 01 Page 2 Button 3 State [%s]" (HASP_Plate01_Button3_Group) {mqtt="<[broker:hasp/plate01/state/p[2].b[3]:state:default]"} -Switch HASP_Plate01_Button_P3B3 "HASP Plate 01 Page 3 Button 3 State [%s]" (HASP_Plate01_Button3_Group) {mqtt="<[broker:hasp/plate01/state/p[3].b[3]:state:default]"} -Switch HASP_Plate01_Button_P4B3 "HASP Plate 01 Page 4 Button 3 State [%s]" (HASP_Plate01_Button3_Group) {mqtt="<[broker:hasp/plate01/state/p[4].b[3]:state:default]"} -Switch HASP_Plate01_Button_P5B3 "HASP Plate 01 Page 5 Button 3 State [%s]" (HASP_Plate01_Button3_Group) {mqtt="<[broker:hasp/plate01/state/p[5].b[3]:state:default]"} -Switch HASP_Plate01_Button_P6B3 "HASP Plate 01 Page 6 Button 3 State [%s]" (HASP_Plate01_Button3_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[3]:state:default]"} -Switch HASP_Plate01_Button_P7B3 "HASP Plate 01 Page 7 Button 3 State [%s]" (HASP_Plate01_Button3_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[3]:state:default]"} -Switch HASP_Plate01_Button_P8B3 "HASP Plate 01 Page 8 Button 3 State [%s]" (HASP_Plate01_Button3_Group) {mqtt="<[broker:hasp/plate01/state/p[8].b[3]:state:default]"} -Switch HASP_Plate01_Button_P9B3 "HASP Plate 01 Page 9 Button 3 State [%s]" (HASP_Plate01_Button3_Group) {mqtt="<[broker:hasp/plate01/state/p[9].b[3]:state:default]"} - -/* Page 1 Functional Items */ -Switch HASP_Plate01_Button_P1B4 "HASP Plate 01 Page 1 Button 4 State [%s]" (HASP_Plate01_Page1_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[1].b[4]:state:default]"} -Switch HASP_Plate01_Button_P1B5 "HASP Plate 01 Page 1 Button 5 State [%s]" (HASP_Plate01_Page1_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[1].b[5]:state:default]"} -Switch HASP_Plate01_Button_P1B6 "HASP Plate 01 Page 1 Button 6 State [%s]" (HASP_Plate01_Page1_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[1].b[6]:state:default]"} -Switch HASP_Plate01_Button_P1B7 "HASP Plate 01 Page 1 Button 7 State [%s]" (HASP_Plate01_Page1_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[1].b[7]:state:default]"} - -/* Page 2 Functional Items */ -Switch HASP_Plate01_Button_P2B4 "HASP Plate 01 Page 2 Button 4 State [%s]" (HASP_Plate01_Page2_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[2].b[4]:state:default]"} -Switch HASP_Plate01_Button_P2B5 "HASP Plate 01 Page 2 Button 5 State [%s]" (HASP_Plate01_Page2_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[2].b[5]:state:default]"} -Switch HASP_Plate01_Button_P2B6 "HASP Plate 01 Page 2 Button 6 State [%s]" (HASP_Plate01_Page2_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[2].b[6]:state:default]"} -Switch HASP_Plate01_Button_P2B7 "HASP Plate 01 Page 2 Button 7 State [%s]" (HASP_Plate01_Page2_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[2].b[7]:state:default]"} - -/* Page 3 Functional Items */ -Switch HASP_Plate01_Button_P3B4 "HASP Plate 01 Page 3 Button 4 State [%s]" (HASP_Plate01_Page3_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[3].b[4]:state:default]"} -Switch HASP_Plate01_Button_P3B5 "HASP Plate 01 Page 3 Button 5 State [%s]" (HASP_Plate01_Page3_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[3].b[5]:state:default]"} -Switch HASP_Plate01_Button_P3B6 "HASP Plate 01 Page 3 Button 6 State [%s]" (HASP_Plate01_Page3_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[3].b[6]:state:default]"} -Switch HASP_Plate01_Button_P3B7 "HASP Plate 01 Page 3 Button 7 State [%s]" (HASP_Plate01_Page3_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[3].b[7]:state:default]"} - -/* Page 4 Functional Items */ -Switch HASP_Plate01_Button_P4B4 "HASP Plate 01 Page 4 Button 4 State [%s]" (HASP_Plate01_Page4_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[4].b[4]:state:default]"} -Switch HASP_Plate01_Button_P4B5 "HASP Plate 01 Page 4 Button 5 State [%s]" (HASP_Plate01_Page4_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[4].b[5]:state:default]"} -Switch HASP_Plate01_Button_P4B6 "HASP Plate 01 Page 4 Button 6 State [%s]" (HASP_Plate01_Page4_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[4].b[6]:state:default]"} -Number HASP_Plate01_Dimmer_P4B7 "HASP Plate 01 Page 4 Dimmer 7 State [%d]" (HASP_Plate01_Page4_Dimmer_Group) {mqtt="<[broker:hasp/plate01/state/p[4].b[7].val:state:default]"} -Number HASP_Plate01_Dimmer_P4B7_Val "HASP Plate 01 Page 4 Dimmer 7 Value" {mqtt=">[broker:hasp/plate01/command/p[4].b[7].val:command:*:default]"} -Number HASP_Plate01_Dimmer_P4B8 "HASP Plate 01 Page 4 Dimmer 8 State [%d]" (HASP_Plate01_Page4_Dimmer_Group) {mqtt="<[broker:hasp/plate01/state/p[4].b[8].val:state:default]"}//",>[broker:hasp/plate01/command/p[4].b[8].val:command:*:default]"} -Number HASP_Plate01_Dimmer_P4B8_Val "HASP Plate 01 Page 4 Dimmer 8 Value" {mqtt=">[broker:hasp/plate01/command/p[4].b[8].val:command:*:default]"} -Number HASP_Plate01_Dimmer_P4B9 "HASP Plate 01 Page 4 Dimmer 9 State [%d]" (HASP_Plate01_Page4_Dimmer_Group) {mqtt="<[broker:hasp/plate01/state/p[4].b[9].val:state:default]"}//",>[broker:hasp/plate01/command/p[4].b[9].val:command:*:default]"} -Number HASP_Plate01_Dimmer_P4B9_Val "HASP Plate 01 Page 4 Dimmer 9 Value" {mqtt=">[broker:hasp/plate01/command/p[4].b[9].val:command:*:default]"} - -/* Page 5 Functional Items */ -Switch HASP_Plate01_Button_P5B4 "HASP Plate 01 Page 5 Button 4 State [%s]" (HASP_Plate01_Page5_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[5].b[4]:state:default]"} -Switch HASP_Plate01_Button_P5B5 "HASP Plate 01 Page 5 Button 5 State [%s]" (HASP_Plate01_Page5_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[5].b[5]:state:default]"} -Switch HASP_Plate01_Button_P5B6 "HASP Plate 01 Page 5 Button 6 State [%s]" (HASP_Plate01_Page5_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[5].b[6]:state:default]"} -Number HASP_Plate01_Dimmer_P5B7 "HASP Plate 01 Page 5 Dimmer 7 State [%d]" (HASP_Plate01_Page5_Dimmer_Group) {mqtt="<[broker:hasp/plate01/state/p[5].b[7].val:state:default]"}//",>[broker:hasp/plate01/command/p[5].b[7].val:command:*:default]"} -Number HASP_Plate01_Dimmer_P5B7_Val "HASP Plate 01 Page 5 Dimmer 7 Value" {mqtt=">[broker:hasp/plate01/command/p[5].b[7].val:command:*:default]"} -Number HASP_Plate01_Dimmer_P5B8 "HASP Plate 01 Page 5 Dimmer 8 State [%d]" (HASP_Plate01_Page5_Dimmer_Group) {mqtt="<[broker:hasp/plate01/state/p[5].b[8].val:state:default]"}//",>[broker:hasp/plate01/command/p[5].b[8].val:command:*:default]"} -Number HASP_Plate01_Dimmer_P5B8_Val "HASP Plate 01 Page 5 Dimmer 8 Value" {mqtt=">[broker:hasp/plate01/command/p[5].b[8].val:command:*:default]"} -Number HASP_Plate01_Dimmer_P5B9 "HASP Plate 01 Page 5 Dimmer 9 State [%d]" (HASP_Plate01_Page5_Dimmer_Group) {mqtt="<[broker:hasp/plate01/state/p[5].b[9].val:state:default]"}//",>[broker:hasp/plate01/command/p[5].b[9].val:command:*:default]"} -Number HASP_Plate01_Dimmer_P5B9_Val "HASP Plate 01 Page 5 Dimmer 9 Value" {mqtt=">[broker:hasp/plate01/command/p[5].b[9].val:command:*:default]"} - -/* Page 6 Functional Items */ -Switch HASP_Plate01_Button_P6B4 "HASP Plate 01 Page 6 Button 4 State [%s]" (HASP_Plate01_Page6_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[4]:state:default]"} -Switch HASP_Plate01_Button_P6B5 "HASP Plate 01 Page 6 Button 5 State [%s]" (HASP_Plate01_Page6_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[5]:state:default]"} -Switch HASP_Plate01_Button_P6B6 "HASP Plate 01 Page 6 Button 6 State [%s]" (HASP_Plate01_Page6_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[6]:state:default]"} -Switch HASP_Plate01_Button_P6B7 "HASP Plate 01 Page 6 Button 7 State [%s]" (HASP_Plate01_Page6_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[7]:state:default]"} -Switch HASP_Plate01_Button_P6B8 "HASP Plate 01 Page 6 Button 8 State [%s]" (HASP_Plate01_Page6_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[8]:state:default]"} -Switch HASP_Plate01_Button_P6B9 "HASP Plate 01 Page 6 Button 9 State [%s]" (HASP_Plate01_Page6_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[9]:state:default]"} -Switch HASP_Plate01_Button_P6B10 "HASP Plate 01 Page 6 Button 10 State [%s]" (HASP_Plate01_Page6_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[10]:state:default]"} -Switch HASP_Plate01_Button_P6B11 "HASP Plate 01 Page 6 Button 11 State [%s]" (HASP_Plate01_Page6_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[6].b[11]:state:default]"} - -/* Page 7 Functional Items */ -Switch HASP_Plate01_Button_P7B4 "HASP Plate 01 Page 7 Button 4 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[4]:state:default]"} -Switch HASP_Plate01_Button_P7B5 "HASP Plate 01 Page 7 Button 5 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[5]:state:default]"} -Switch HASP_Plate01_Button_P7B6 "HASP Plate 01 Page 7 Button 6 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[6]:state:default]"} -Switch HASP_Plate01_Button_P7B7 "HASP Plate 01 Page 7 Button 7 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[7]:state:default]"} -Switch HASP_Plate01_Button_P7B8 "HASP Plate 01 Page 7 Button 8 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[8]:state:default]"} -Switch HASP_Plate01_Button_P7B9 "HASP Plate 01 Page 7 Button 9 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[9]:state:default]"} -Switch HASP_Plate01_Button_P7B10 "HASP Plate 01 Page 7 Button 10 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[10]:state:default]"} -Switch HASP_Plate01_Button_P7B11 "HASP Plate 01 Page 7 Button 11 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[11]:state:default]"} -Switch HASP_Plate01_Button_P7B12 "HASP Plate 01 Page 7 Button 12 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[12]:state:default]"} -Switch HASP_Plate01_Button_P7B13 "HASP Plate 01 Page 7 Button 13 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[13]:state:default]"} -Switch HASP_Plate01_Button_P7B14 "HASP Plate 01 Page 7 Button 14 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[14]:state:default]"} -Switch HASP_Plate01_Button_P7B15 "HASP Plate 01 Page 7 Button 15 State [%s]" (HASP_Plate01_Page7_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[7].b[15]:state:default]"} - -/* Page 8 Functional Items */ -Switch HASP_Plate01_Button_P8B4 "HASP Plate 01 Page 8 Button 4 State [%s]" (HASP_Plate01_Page8_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[8].b[4]:state:default]"} -Switch HASP_Plate01_Button_P8B5 "HASP Plate 01 Page 8 Button 5 State [%s]" (HASP_Plate01_Page8_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[8].b[5]:state:default]"} -Switch HASP_Plate01_Button_P8B6 "HASP Plate 01 Page 8 Button 6 State [%s]" (HASP_Plate01_Page8_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[8].b[6]:state:default]"} -Switch HASP_Plate01_Button_P8B7 "HASP Plate 01 Page 8 Button 7 State [%s]" (HASP_Plate01_Page8_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[8].b[7]:state:default]"} -Switch HASP_Plate01_Button_P8B8 "HASP Plate 01 Page 8 Button 8 State [%s]" (HASP_Plate01_Page8_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[8].b[8]:state:default]"} -Number HASP_Plate01_Dimmer_P8B9 "HASP Plate 01 Page 8 Dimmer 9 State [%d]" (HASP_Plate01_Page8_Dimmer_Group) {mqtt="<[broker:hasp/plate01/state/p[8].b[9].val:state:default]"} -Number HASP_Plate01_Dimmer_P8B9_Val "HASP Plate 01 Page 8 Dimmer 9 Value" {mqtt=">[broker:hasp/plate01/command/p[8].b[9].val:command:*:default]"} - -/* Page 9 Functional Items */ -Switch HASP_Plate01_Button_P9B4 "HASP Plate 01 Page 9 Button 4 State [%s]" (HASP_Plate01_Page9_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[9].b[4]:state:default]"} -Switch HASP_Plate01_Button_P9B5 "HASP Plate 01 Page 9 Button 5 State [%s]" (HASP_Plate01_Page9_Button_Group) {mqtt="<[broker:hasp/plate01/state/p[9].b[5]:state:default]"} - /* Page Storage Items */ Number HASP_Plate01_Page "HASP Plate 01 Page Select [%d]" (HASP) {mqtt=">[broker:hasp/plate01/command/page:command:*:default]"} @@ -152,4 +27,8 @@ Number HASP_Plate01_Plate_Motion "HASP Plate 01 Motion Status [%d]" (HASP) {mqtt String HASP_Plate01_Plate_Command "Hasp Plate 01 Command" (HASP) {mqtt=">[broker:hasp/plate01/command:command:*:default]"} -String HASP_Plate01_Plate_Command_JSON "Hasp Plate 01 JSON Command" (HASP) {mqtt=">[broker:hasp/plate01/command/json:command:*:default]"} \ No newline at end of file +String HASP_Plate01_Plate_Command_JSON "Hasp Plate 01 JSON Command" (HASP) {mqtt=">[broker:hasp/plate01/command/json:command:*:default]"} + +String HASP_Plate01_Plate_State_JSON "HASP Plate 01 JSON State" (HASP) {mqtt="<[broker:hasp/plate01/state/json:state:default]"} +String HASP_Plate01_Plate_State_JSON_Event "HASP Plate 01 JSON State Event" (HASP) {mqtt="<[broker:hasp/plate01/state/json:state:JSONPATH($.event)]"} +String HASP_Plate01_Plate_State_JSON_Value "HASP Plate 01 JSON State Value" (HASP) {mqtt="<[broker:hasp/plate01/state/json:state:JSONPATH($.value)]"} \ No newline at end of file diff --git a/contrib/openHAB/HASP-Master.rules b/contrib/openHAB/HASP-Master.rules index 227f46a..1c2d76c 100644 --- a/contrib/openHAB/HASP-Master.rules +++ b/contrib/openHAB/HASP-Master.rules @@ -1,5 +1,3 @@ -//import java.util.Calendar - /* -------------------------------------- BEGIN USER CONFIG -------------------------------------- */ /* Configuration for the three page selection buttons at the bottom of the page */ @@ -132,405 +130,354 @@ Several examples are included (commented out) to get you started, whether you ju button is pressed, or toggle the output item depending on its current state. */ -rule "Handle HASP Master Page 0" -when - Item HASP_Plate01_Button_P0B1 received update ON -then - if(HASP_Plate01_Light_Power.state == OFF) - { - HASP_Plate01_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons from Page 0 here - */ - if (triggeringItem == HASP_Plate01_Button_P0B1) - { - //Insert action to perform if button 0 was pressed - - HASP_Plate01_Page.sendCommand(2) //This is only for when the HASP starts in page 0 and you need to go to a different page, this will send it to Page 2 - } - } -end - -rule "Handle HASP Master Page 1" -when - Member of HASP_Plate01_Page1_Button_Group received update ON -then - if(HASP_Plate01_Light_Power.state == OFF) - { - HASP_Plate01_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons from Page 1 here - */ - if (triggeringItem == HASP_Plate01_Button_P1B4) - { - //Insert action to perform if button 4 was pressed - - Scene_Morning.sendCommand(ON) //Example - Latching ON - send ON command from HASP button to turn item on - } - else if (triggeringItem == HASP_Plate01_Button_P1B5) - { - //Insert action to perform if button 5 was pressed - - // if(Scene_Evening == ON) //Example - Toggle - change item state using HASP button (turn OFF if ON and ON if OFF) - // { - // Scene_Evening.sendCommand(OFF) - // } - // else - // { - // Scene_Evening.sendCommand(ON) - // } - Scene_Evening.sendCommand(ON) - } - else if (triggeringItem == HASP_Plate01_Button_P1B6) - { - //Insert action to perform if button 6 was pressed - Scene_Night.sendCommand(ON) - } - else if (triggeringItem == HASP_Plate01_Button_P1B7) - { - //Insert action to perform if button 7 was pressed - Scene_Bedtime.sendCommand(ON) - } - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Master Page 2" -when - Member of HASP_Plate01_Page2_Button_Group received update ON -then - if(HASP_Plate01_Light_Power.state == OFF) - { - HASP_Plate01_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons from Page 2 here - */ - if (triggeringItem == HASP_Plate01_Button_P2B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P2B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P2B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P2B7) - { - //Insert action to perform if button 7 was pressed - } - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Master Page 3" -when - Member of HASP_Plate01_Page3_Button_Group received update ON -then - if(HASP_Plate01_Light_Power.state == OFF) - { - HASP_Plate01_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons from Page 3 here - */ - if (triggeringItem == HASP_Plate01_Button_P3B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P3B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P3B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P3B7) - { - //Insert action to perform if button 7 was pressed - } - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Master Page 4" -when - Member of HASP_Plate01_Page4_Button_Group received update ON or - Member of HASP_Plate01_Page4_Dimmer_Group received update -then - if(HASP_Plate01_Light_Power.state == OFF) - { - HASP_Plate01_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons/dimmers from Page 4 here - */ - if (triggeringItem == HASP_Plate01_Button_P4B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P4B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P4B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate01_Dimmer_P4B7) - { - //Insert action to perform if dimmer 1 was moved - } - else if (triggeringItem == HASP_Plate01_Dimmer_P4B8) - { - //Insert action to perform if dimmer 2 was moved - } - else if (triggeringItem == HASP_Plate01_Dimmer_P4B9) - { - //Insert action to perform if dimmer 3 was moved - } - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Master Page 5" -when - Member of HASP_Plate01_Page5_Button_Group received update ON or - Member of HASP_Plate01_Page5_Dimmer_Group received update -then - if(HASP_Plate01_Light_Power.state == OFF) - { - HASP_Plate01_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons/dimmers from Page 5 here - */ - if (triggeringItem == HASP_Plate01_Button_P5B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P5B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P5B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate01_Dimmer_P5B7) - { - //Insert action to perform if dimmer 1 was moved - - HASP_Plate01_Light_Dimmer.sendCommand(HASP_Plate01_Dimmer_P5B7.state.toString) //Example - send dimmer value to HASP Backlight item - } - else if (triggeringItem == HASP_Plate01_Dimmer_P5B8) - { - //Insert action to perform if dimmer 2 was moved - } - else if (triggeringItem == HASP_Plate01_Dimmer_P5B9) - { - //Insert action to perform if dimmer 3 was moved - } - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Master Page 6" +rule "Handle HASP Master" when - Member of HASP_Plate01_Page6_Button_Group received update ON + Item HASP_Plate01_Plate_State_JSON_Value received update then - if(HASP_Plate01_Light_Power.state == OFF) - { - HASP_Plate01_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons/dimmers from Page 6 here - */ - if (triggeringItem == HASP_Plate01_Button_P6B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P6B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P6B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P6B7) - { - //Insert action to perform if button 7 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P6B8) - { - //Insert action to perform if button 8 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P6B9) - { - //Insert action to perform if button 9 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P6B10) - { - //Insert action to perform if button 10 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P6B11) - { - //Insert action to perform if button 11 was moved - } - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end + //parse out data from JSON string (page, button, value) + var String eventpage = HASP_Plate01_Plate_State_JSON_Event.state.toString.split("\\[").get(1).split("\\]").get(0) + var String eventbutton = HASP_Plate01_Plate_State_JSON_Event.state.toString.split("\\[").get(2).split("\\]").get(0) -rule "Handle HASP Master Page 7" -when - Member of HASP_Plate01_Page7_Button_Group received update ON -then - if(HASP_Plate01_Light_Power.state == OFF) + if (HASP_Plate01_Plate_State_JSON_Value.state == 'OFF') { - HASP_Plate01_Light_Power.sendCommand(ON) + //Do nothing (button release event) + logInfo ("HASP", "Ignoring OFF event") } else - { - /* - Act on buttons/dimmers from Page 7 here - */ - if (triggeringItem == HASP_Plate01_Button_P7B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P7B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P7B6) - { - //Insert action to perform if button 6 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P7B7) - { - //Insert action to perform if button 7 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P7B8) - { - //Insert action to perform if button 8 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P7B9) - { - //Insert action to perform if button 9 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P7B10) - { - //Insert action to perform if button 10 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P7B11) - { - //Insert action to perform if button 11 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P7B12) - { - //Insert action to perform if button 12 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P7B13) - { - //Insert action to perform if button 13 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P7B14) - { - //Insert action to perform if button 14 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P7B15) - { - //Insert action to perform if button 15 was moved - } - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Master Page 8" -when - Member of HASP_Plate01_Page8_Button_Group received update ON or - Member of HASP_Plate01_Page8_Dimmer_Group received update -then - if(HASP_Plate01_Light_Power.state == OFF) { - HASP_Plate01_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons/dimmers from Page 8 here - */ - if (triggeringItem == HASP_Plate01_Button_P8B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P8B5) - { - //Insert action to perform if button 5 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P8B6) + //Handle Page/button/dimmer value event + if(HASP_Plate01_Light_Power.state == OFF) { - //Insert action to perform if button 6 was pressed + HASP_Plate01_Light_Power.sendCommand(ON) } - else if (triggeringItem == HASP_Plate01_Button_P8B7) - { - //Insert action to perform if button 7 was moved - } - else if (triggeringItem == HASP_Plate01_Button_P8B8) - { - //Insert action to perform if button 8 was moved - } - else if (triggeringItem == HASP_Plate01_Dimmer_P8B9) - { - //Insert action to perform if dimmer 9 was moved - } - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press - } -end - -rule "Handle HASP Master Page 9" -when - Member of HASP_Plate01_Page9_Button_Group received update ON -then - if(HASP_Plate01_Light_Power.state == OFF) - { - HASP_Plate01_Light_Power.sendCommand(ON) - } - else - { - /* - Act on buttons/dimmers from Page 9 here - */ - if (triggeringItem == HASP_Plate01_Button_P9B4) - { - //Insert action to perform if button 4 was pressed - } - else if (triggeringItem == HASP_Plate01_Button_P9B5) - { - //Insert action to perform if button 5 was pressed + else + { + if ((eventbutton == '1' || eventbutton == '2' || eventbutton == '3') && eventpage != '0') //Handle the pressing of one of the 3 bottom page buttons + { + switch(eventbutton) + { + case '1': + { + HASP_Plate01_Page.sendCommand(plate01_pagebutton1page as Number) + } + case '2': + { + HASP_Plate01_Page.sendCommand(plate01_pagebutton2page as Number) + } + case '3': + { + HASP_Plate01_Page.sendCommand(plate01_pagebutton3page as Number) + } + } + HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + else + { + switch(eventpage) + { + case '0': + { + /* + Act on buttons from Page 0 here + */ + if (eventbutton == '1') + { + //Insert action to perform if button 0 was pressed + + HASP_Plate01_Page.sendCommand(2 as Number) //This is only for when the HASP starts in page 0 and you need to go to a different page, this will send it to Page 2 + } + } + case '1': + { + /* + Act on buttons from Page 1 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + + Scene_Morning.sendCommand(ON) //Example - Latching ON - send ON command from HASP button to turn item on + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + + // if(Scene_Evening == ON) //Example - Toggle - change item state using HASP button (turn OFF if ON and ON if OFF) + // { + // Scene_Evening.sendCommand(OFF) + // } + // else + // { + // Scene_Evening.sendCommand(ON) + // } + Scene_Evening.sendCommand(ON) + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + Scene_Night.sendCommand(ON) + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was pressed + Scene_Bedtime.sendCommand(ON) + } + HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '2': + { + /* + Act on buttons from Page 2 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was pressed + } + HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '3': + { + /* + Act on buttons from Page 3 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was pressed + } + HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '4': + { + /* + Act on buttons/dimmers from Page 4 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if dimmer 1 was moved + } + else if (eventbutton == '8') + { + //Insert action to perform if dimmer 2 was moved + } + else if (eventbutton == '9') + { + //Insert action to perform if dimmer 3 was moved + } + HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '5': + { + /* + Act on buttons/dimmers from Page 5 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if dimmer 1 was moved + if (HASP_Plate01_Plate_State_JSON_Value.state != 'ON'){ + HASP_Plate01_Light_Dimmer.sendCommand(HASP_Plate01_Plate_State_JSON_Value.state.toString) //Example - send dimmer value to HASP Backlight item + } + } + else if (eventbutton == '8') + { + //Insert action to perform if dimmer 2 was moved + } + else if (eventbutton == '9') + { + //Insert action to perform if dimmer 3 was moved + } + HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '6': + { + /* + Act on buttons/dimmers from Page 6 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was moved + } + else if (eventbutton == '8') + { + //Insert action to perform if button 8 was moved + } + else if (eventbutton == '9') + { + //Insert action to perform if button 9 was moved + } + else if (eventbutton == '10') + { + //Insert action to perform if button 10 was moved + } + else if (eventbutton == '11') + { + //Insert action to perform if button 11 was moved + } + HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '7': + { + /* + Act on buttons/dimmers from Page 7 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was moved + } + else if (eventbutton == '8') + { + //Insert action to perform if button 8 was moved + } + else if (eventbutton == '9') + { + //Insert action to perform if button 9 was moved + } + else if (eventbutton == '10') + { + //Insert action to perform if button 10 was moved + } + else if (eventbutton == '11') + { + //Insert action to perform if button 11 was moved + } + else if (eventbutton == '12') + { + //Insert action to perform if button 12 was moved + } + else if (eventbutton == '13') + { + //Insert action to perform if button 13 was moved + } + else if (eventbutton == '14') + { + //Insert action to perform if button 14 was moved + } + else if (eventbutton == '15') + { + //Insert action to perform if button 15 was moved + } + HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '8': + { + /* + Act on buttons/dimmers from Page 8 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + else if (eventbutton == '6') + { + //Insert action to perform if button 6 was pressed + } + else if (eventbutton == '7') + { + //Insert action to perform if button 7 was moved + } + else if (eventbutton == '8') + { + //Insert action to perform if button 8 was moved + } + else if (eventbutton == '9') + { + //Insert action to perform if dimmer 9 was moved + } + HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + case '9': + { + /* + Act on buttons/dimmers from Page 9 here + */ + if (eventbutton == '4') + { + //Insert action to perform if button 4 was pressed + } + else if (eventbutton == '5') + { + //Insert action to perform if button 5 was pressed + } + HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press + } + } + } } - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press } end @@ -573,7 +520,8 @@ rule "Handle HASP Master Page 5 dimmers" when Item HASP_Plate01_Light_Brightness received update then - HASP_Plate01_Dimmer_P5B8_Val.sendCommand(HASP_Plate01_Light_Brightness.state as Number) + var jsonString = '["p[5].b[8].val=' + HASP_Plate01_Light_Brightness.state + '"]' + HASP_Plate01_Plate_Command_JSON.sendCommand(jsonString) end rule "Handle HASP Master Page 9 chart" @@ -594,7 +542,7 @@ end /* Restore saved page and rebuild config on reconnect */ rule "HASP Master Restore page on connect" when - Item HASP_Plate01_Plate_Sensor_Status changed to "available" or + Item HASP_Plate01_Plate_Status changed to "ON" or Item HASP_Plate01_Plate_Refresh received command ON then @@ -755,38 +703,11 @@ then end -/* Select hasp_plate01_page in response to page button 1 */ -rule "HASP Master respond to page button 1" -when - Member of HASP_Plate01_Button1_Group received update ON -then - HASP_Plate01_Page.sendCommand(plate01_pagebutton1page as Number) - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press -end - -/* Select hasp_plate01_page in response to page button 2 */ -rule "HASP Master respond to page button 2" -when - Member of HASP_Plate01_Button2_Group received update ON -then - HASP_Plate01_Page.sendCommand(plate01_pagebutton2page as Number) - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press -end - -/* Select hasp_plate01_page in response to page button 3 */ -rule "HASP Master respond to page button 3" -when - Member of HASP_Plate01_Button3_Group received update ON -then - HASP_Plate01_Page.sendCommand(plate01_pagebutton3page as Number) - HASP_Plate01_Light_Power.sendCommand(ON) //refresh backlight timer following button press -end - /* Set page button colors based on current page */ rule "HASP Master set page button colors on page change" when Item HASP_Plate01_Page_Current received update -then +then if (HASP_Plate01_Page_Current.state != 0) { var jsonString = '["p['+ (HASP_Plate01_Page_Current.state.toString) + '].b[1].bco=25388", ' + @@ -805,11 +726,11 @@ then { jsonString = jsonString + ', "p['+ (HASP_Plate01_Page_Current.state.toString) + '].b[3].bco=65535"]' } - else + else { jsonString = jsonString + ']' } HASP_Plate01_Plate_Command_JSON.sendCommand(jsonString) } -end +end \ No newline at end of file diff --git a/update/version.json b/update/version.json index 8a6748c..43da11e 100644 --- a/update/version.json +++ b/update/version.json @@ -1,6 +1,6 @@ { "d1_mini": { - "version": "0.36", + "version": "0.37", "firmware": "http://haswitchplate.com/update/HASwitchPlate.ino.d1_mini.bin" }, "NX3224T024_011R": {