diff --git a/esphome/components/api/homeassistant_service.h b/esphome/components/api/homeassistant_service.h index cb19dd19a4f..1b8dfbe4121 100644 --- a/esphome/components/api/homeassistant_service.h +++ b/esphome/components/api/homeassistant_service.h @@ -232,10 +232,11 @@ template class HomeAssistantServiceCallAction : public Action cpp_types). + # Identity check (is) avoids brittle string comparison. + if isinstance(value, str) and output_type is not None: + from esphome.cpp_types import std_string + + if output_type is std_string: + return FlashStringLiteral(value) return value if isinstance(to_exp, dict): return to_exp[value]