Use brightness for dimmable lights

This commit is contained in:
fvanroie 2021-05-29 23:37:59 +02:00
parent 5b9d5f45e3
commit 3dadfa606d
2 changed files with 12 additions and 2 deletions

View File

@ -200,8 +200,9 @@ static void dispatch_output(const char* topic, const char* payload)
return;
}
JsonVariant state = json[F("state")];
JsonVariant value = json[F("val")];
JsonVariant state = json[F("state")];
JsonVariant value = json[F("val")];
JsonVariant brightness = json[F("brightness")];
// Check if the state needs to change
if(!state.isNull() && power_state != state.as<bool>()) {
@ -212,6 +213,9 @@ static void dispatch_output(const char* topic, const char* payload)
if(!value.isNull() && state_value != value.as<int32_t>()) {
state_value = value.as<int32_t>();
updated = true;
} else if(!brightness.isNull() && state_value != brightness.as<int32_t>()) {
state_value = brightness.as<int32_t>();
updated = true;
}
// Set new state

View File

@ -393,6 +393,12 @@ void gpio_output_state(hasp_gpio_config_t* gpio)
case POWER_RELAY:
snprintf_P(payload, sizeof(payload), PSTR("{\"state\":\"%s\"}"), statename);
break;
case LED:
case SERIAL_DIMMER:
case SERIAL_DIMMER_AU:
case SERIAL_DIMMER_EU:
snprintf_P(payload, sizeof(payload), PSTR("{\"state\":\"%s\",\"brightness\":%d}"), statename, gpio->val);
break;
default:
snprintf_P(payload, sizeof(payload), PSTR("{\"state\":\"%s\",\"val\":%d}"), statename, gpio->val);
}