diff --git a/sonoff/xdrv_20_hue.ino b/sonoff/xdrv_20_hue.ino index 49eaf2dc8..a37caa559 100644 --- a/sonoff/xdrv_20_hue.ino +++ b/sonoff/xdrv_20_hue.ino @@ -276,6 +276,12 @@ void HueLightStatus1(uint8_t device, String *response) if (bri > 254) bri = 254; // Philips Hue bri is between 1 and 254 if (bri < 1) bri = 1; +#ifdef USE_SHUTTER + if (ShutterState(device)) { + bri = (float)(Settings.shutter_invert[device-1] ? 100 - Settings.shutter_position[device-1] : Settings.shutter_position[device-1]) / 100; + } +#endif + if (light_type) { light_state.getHSB(&hue, &sat, nullptr); @@ -452,7 +458,6 @@ void HueGlobalConfig(String *path) response += ",\""; } } - response += F("},\"groups\":{},\"schedules\":{},\"config\":"); HueConfigResponse(&response); response += "}"; @@ -502,7 +507,6 @@ void HueLights(String *path) Script_Check_Hue(&response); #endif response += "}"; - } else if (path->endsWith("/state")) { // Got ID/state path->remove(0,8); // Remove /lights/ @@ -531,19 +535,32 @@ void HueLights(String *path) response.replace("{id", String(EncodeLightId(device))); response.replace("{cm", "on"); - on = hue_json["on"]; - switch(on) - { - case false : ExecuteCommandPower(device, POWER_OFF, SRC_HUE); - response.replace("{re", "false"); - break; - case true : ExecuteCommandPower(device, POWER_ON, SRC_HUE); - response.replace("{re", "true"); - break; - default : response.replace("{re", (power & (1 << (device-1))) ? "true" : "false"); - break; +#ifdef USE_SHUTTER + if (ShutterState(device)) { + if (!change) { + on = hue_json["on"]; + bri = on ? 1.0f : 0.0f; // when bri is not part of this request then calculate it + change = true; + } + response.replace("{re", on ? "true" : "false"); + } else { +#endif + on = hue_json["on"]; + switch(on) + { + case false : ExecuteCommandPower(device, POWER_OFF, SRC_HUE); + response.replace("{re", "false"); + break; + case true : ExecuteCommandPower(device, POWER_ON, SRC_HUE); + response.replace("{re", "true"); + break; + default : response.replace("{re", (power & (1 << (device-1))) ? "true" : "false"); + break; + } + resp = true; +#ifdef USE_SHUTTER } - resp = true; +#endif // USE_SHUTTER } if (light_type && (local_light_subtype >= LST_SINGLE)) { @@ -649,6 +666,12 @@ void HueLights(String *path) resp = true; } if (change) { +#ifdef USE_SHUTTER + if (ShutterState(device)) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("Settings.shutter_invert: %d"), Settings.shutter_invert[device-1]); + SetShutterPosition(device, bri * 100.0f ); + } else +#endif if (light_type && (local_light_subtype > LST_NONE)) { // not relay if (!Settings.flag3.pwm_multi_channels) { if (g_gotct) { @@ -687,7 +710,7 @@ void HueLights(String *path) if (device>devices_present) { Script_HueStatus(&response,device-devices_present-1); goto exit; - } +} #endif if ((device < 1) || (device > maxhue)) { @@ -696,7 +719,6 @@ void HueLights(String *path) response += F("{\"state\":"); HueLightStatus1(device, &response); HueLightStatus2(device, &response); - } else { response = "{}";