From d8f726a0c96811e4552ce5596880e71114ad63d6 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Wed, 26 Aug 2020 08:56:13 +0200 Subject: [PATCH] Add Zigbee web ui widget for Lights --- tasmota/CHANGELOG.md | 1 + tasmota/xdrv_23_zigbee_2_devices.ino | 38 ++++++++++++++--------- tasmota/xdrv_23_zigbee_7_statemachine.ino | 2 +- tasmota/xdrv_23_zigbee_A_impl.ino | 34 +++++++++++++++++--- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 7118053e0..96ae2be02 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -3,6 +3,7 @@ ### 8.4.0.3 20200823 - Add command ``PowerDelta1`` to ``PowerDelta3`` to trigger on up to three phases (#9134) +- Add Zigbee web ui widget for Lights ### 8.4.0.2 20200813 diff --git a/tasmota/xdrv_23_zigbee_2_devices.ino b/tasmota/xdrv_23_zigbee_2_devices.ino index a7bd2adee..68ba55d42 100644 --- a/tasmota/xdrv_23_zigbee_2_devices.ino +++ b/tasmota/xdrv_23_zigbee_2_devices.ino @@ -146,6 +146,14 @@ public: inline bool getReachable(void) const { return bitRead(power, 7); } inline void setPower(bool power_on) { bitWrite(power, 0, power_on); bitWrite(power, 1, false); } inline bool getPower(void) const { return bitRead(power, 0); } + + // If light, returns the number of channels, or 0xFF if unknown + uint8_t getLightChannels(void) const { + if ((zb_profile & 0xF0) == 0x00) { + return zb_profile & 0x07; + } + return 0xFF; + } }; /*********************************************************************************************\ @@ -682,21 +690,21 @@ void Z_Devices::updateZbProfile(uint16_t shortaddr) { { uint32_t channels = zb_profile & 0x07; // depending on the bulb type, the default parameters from unknown to credible defaults - if (!device.validPower()) { device.setPower(false); } - if (1 <= channels) { - if (0xFF == device.dimmer) { device.dimmer = 0; } - } - if (3 <= channels) { - if (0xFF == device.sat) { device.sat = 0; } - if (0xFFFF == device.hue) { device.hue = 0; } - if (0xFFFF == device.x) { device.x = 0; } - if (0xFFFF == device.y) { device.y = 0; } - if (0xFF == device.colormode) { device.colormode = 0; } // HueSat mode - } - if ((2 == channels) || (5 == channels)) { - if (0xFFFF == device.ct) { device.ct = 200; } - if (0xFF == device.colormode) { device.colormode = 2; } // CT mode - } + // if (!device.validPower()) { device.setPower(false); } + // if (1 <= channels) { + // if (0xFF == device.dimmer) { device.dimmer = 0; } + // } + // if (3 <= channels) { + // if (0xFF == device.sat) { device.sat = 0; } + // if (0xFFFF == device.hue) { device.hue = 0; } + // if (0xFFFF == device.x) { device.x = 0; } + // if (0xFFFF == device.y) { device.y = 0; } + // if (0xFF == device.colormode) { device.colormode = 0; } // HueSat mode + // } + // if ((2 == channels) || (5 == channels)) { + // if (0xFFFF == device.ct) { device.ct = 200; } + // if (0xFF == device.colormode) { device.colormode = 2; } // CT mode + // } } break; } diff --git a/tasmota/xdrv_23_zigbee_7_statemachine.ino b/tasmota/xdrv_23_zigbee_7_statemachine.ino index ee9bfd19a..5a6ab4e29 100644 --- a/tasmota/xdrv_23_zigbee_7_statemachine.ino +++ b/tasmota/xdrv_23_zigbee_7_statemachine.ino @@ -681,7 +681,7 @@ ZBM(ZBS_SET_CONCENTRATOR, EZSP_setConcentrator, 0x00 /*high*/, 0x00 /*false*/, 0 ZBM(ZBR_SET_CONCENTRATOR, EZSP_setConcentrator, 0x00 /*high*/, 0x00 /*ok*/) // 100000 // setInitialSecurityState -#define EZ_SECURITY_MODE EMBER_TRUST_CENTER_GLOBAL_LINK_KEY | EMBER_PRECONFIGURED_NETWORK_KEY_MODE | EMBER_HAVE_NETWORK_KEY | EMBER_HAVE_PRECONFIGURED_KEY +#define EZ_SECURITY_MODE EMBER_TRUST_CENTER_GLOBAL_LINK_KEY | EMBER_PRECONFIGURED_NETWORK_KEY_MODE | EMBER_HAVE_NETWORK_KEY | EMBER_HAVE_PRECONFIGURED_KEY | EMBER_NO_FRAME_COUNTER_RESET ZBR(ZBS_SET_SECURITY, EZSP_setInitialSecurityState, 0x00 /*high*/, Z_B0(EZ_SECURITY_MODE), Z_B1(EZ_SECURITY_MODE), // preConfiguredKey diff --git a/tasmota/xdrv_23_zigbee_A_impl.ino b/tasmota/xdrv_23_zigbee_A_impl.ino index 73cd9e4a6..1552eb166 100644 --- a/tasmota/xdrv_23_zigbee_A_impl.ino +++ b/tasmota/xdrv_23_zigbee_A_impl.ino @@ -1348,6 +1348,7 @@ void ZigbeeShow(bool json) const uint8_t px_lqi = (strlen(D_LQI) + 4) * 10; // LQI 254 = 70px WSContentSend_P(PSTR("{t}")); // Terminate current two column table and open new table + WSContentSend_P(PSTR("")); // sort elements by name, then by id uint8_t sorted_idx[zigbee_num]; @@ -1393,20 +1394,45 @@ void ZigbeeShow(bool json) bool pressure_ok = device.validPressure(); if (temperature_ok || humidity_ok || pressure_ok) { - WSContentSend_P(PSTR("| ")); + WSContentSend_P(PSTR("┆")); if (temperature_ok) { char buf[12]; dtostrf(device.temperature / 10.0f, 3, 1, buf); - WSContentSend_PD(PSTR("  ☀️%s°C"), buf); + WSContentSend_PD(PSTR(" ☀️%s°C"), buf); } if (humidity_ok) { - WSContentSend_P(PSTR("  💧%d%%"), device.humidity); + WSContentSend_P(PSTR(" 💧%d%%"), device.humidity); } if (pressure_ok) { - WSContentSend_P(PSTR("  ⛅ %d hPa"), device.pressure); + WSContentSend_P(PSTR(" ⛅ %d hPa"), device.pressure); } WSContentSend_P(PSTR("{e}")); } + + // Light and switches + bool power_ok = device.validPower(); + if (power_ok) { + uint8_t channels = device.getLightChannels(); + if (0xFF == channels) { channels = 5; } // if number of channel is unknown, display all known attributes + WSContentSend_P(PSTR("┆ %s"), device.getPower() ? PSTR(D_ON) : PSTR(D_OFF)); + if (device.validDimmer() && (channels >= 1)) { + WSContentSend_P(PSTR(" 🔅%d%%"), changeUIntScale(device.dimmer,0,254,0,100)); + } + if (device.validCT() && ((channels == 2) || (channels == 5))) { + uint32_t ct_k = (((1000000 / device.ct) + 25) / 50) * 50; + WSContentSend_P(PSTR(" %dK"), device.ct, ct_k); + } + if (device.validHue() && device.validSat() && (channels >= 3)) { + uint8_t r,g,b; + uint8_t sat = changeUIntScale(device.sat, 0, 254, 0, 255); // scale to 0..255 + LightStateClass::HsToRgb(device.hue, sat, &r, &g, &b); + WSContentSend_P(PSTR(" #%02X%02X%02X"), r,g,b,r,g,b); + } else if (device.validX() && device.validY() && (channels >= 3)) { + uint8_t r,g,b; + LightStateClass::XyToRgb(device.x / 65535.0f, device.y / 65535.0f, &r, &g, &b); + WSContentSend_P(PSTR(" #%02X%02X%02X"), r,g,b,r,g,b); + } + } } WSContentSend_P(PSTR("{t}")); // Terminate current multi column table and open new table