diff --git a/src/components/ha-service-control.ts b/src/components/ha-service-control.ts index b9cfa06920..8b2b189af9 100644 --- a/src/components/ha-service-control.ts +++ b/src/components/ha-service-control.ts @@ -130,6 +130,33 @@ export class HaServiceControl extends LitElement { this._value = this.value; } + if (oldValue?.service !== this.value?.service) { + let updatedDefaultValue = false; + if (this._value && serviceData) { + // Set mandatory bools without a default value to false + this._value.data ??= {}; + serviceData.fields.forEach((field) => { + if ( + field.selector && + field.required && + field.default === undefined && + "boolean" in field.selector && + this._value!.data![field.key] === undefined + ) { + updatedDefaultValue = true; + this._value!.data![field.key] = false; + } + }); + } + if (updatedDefaultValue) { + fireEvent(this, "value-changed", { + value: { + ...this._value, + }, + }); + } + } + if (this._value?.data) { const yamlEditor = this._yamlEditor; if (yamlEditor && yamlEditor.value !== this._value.data) {