diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 8730828994..5a33a82842 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -637,14 +637,14 @@ uint16_t APIConnection::try_send_climate_state(EntityBase *entity, APIConnection } if (traits.get_supports_fan_modes() && climate->fan_mode.has_value()) resp.fan_mode = static_cast(climate->fan_mode.value()); - if (!traits.get_supported_custom_fan_modes().empty() && climate->custom_fan_mode.has_value()) { - resp.set_custom_fan_mode(StringRef(climate->custom_fan_mode.value())); + if (!traits.get_supported_custom_fan_modes().empty() && climate->custom_fan_mode != nullptr) { + resp.set_custom_fan_mode(StringRef(climate->custom_fan_mode)); } if (traits.get_supports_presets() && climate->preset.has_value()) { resp.preset = static_cast(climate->preset.value()); } - if (!traits.get_supported_custom_presets().empty() && climate->custom_preset.has_value()) { - resp.set_custom_preset(StringRef(climate->custom_preset.value())); + if (!traits.get_supported_custom_presets().empty() && climate->custom_preset != nullptr) { + resp.set_custom_preset(StringRef(climate->custom_preset)); } if (traits.get_supports_swing_modes()) resp.swing_mode = static_cast(climate->swing_mode);