{"record":{"id":"924adc8321c2c5bf","repo":"home-assistant/core","slug":"code-arm-required","errorCode":"code_arm_required","errorMessage":"code_arm_required","messagePattern":"code_arm_required","errorType":"validation","errorClass":"ServiceValidationError","httpStatus":null,"severity":"warning","filePath":"homeassistant/components/alarm_control_panel/__init__.py","lineNumber":198,"sourceCode":"        \"\"\"Code format or None if no code is required.\"\"\"\n        return self._attr_code_format\n\n    @cached_property\n    def changed_by(self) -> str | None:\n        \"\"\"Last change triggered by.\"\"\"\n        return self._attr_changed_by\n\n    @cached_property\n    def code_arm_required(self) -> bool:\n        \"\"\"Whether the code is required for arm actions.\"\"\"\n        return self._attr_code_arm_required\n\n    @final\n    @callback\n    def check_code_arm_required(self, code: str | None) -> str | None:\n        \"\"\"Check if arm code is required, raise if no code is given.\"\"\"\n        if not (_code := self.code_or_default_code(code)) and self.code_arm_required:\n            raise ServiceValidationError(\n                translation_domain=DOMAIN,\n                translation_key=\"code_arm_required\",\n                translation_placeholders={\n                    \"entity_id\": self.entity_id,\n                },\n            )\n        return _code\n\n    @final\n    async def async_handle_alarm_disarm(self, code: str | None = None) -> None:\n        \"\"\"Add default code and disarm.\"\"\"\n        await self.async_alarm_disarm(self.code_or_default_code(code))\n\n    def alarm_disarm(self, code: str | None = None) -> None:\n        \"\"\"Send disarm command.\"\"\"\n        raise NotImplementedError\n\n    async def async_alarm_disarm(self, code: str | None = None) -> None:","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/alarm_control_panel/__init__.py#L180-L216","documentation":"ServiceValidationError with translation_key 'code_arm_required' raised by AlarmControlPanelEntity.check_code_arm_required when the provided code is empty/falsy after applying code_or_default_code and the entity's code_arm_required attribute is True. It aborts arm actions (arm_away, arm_home, arm_vacation, arm_night, arm_custom_bypass) before any device call, telling the user a code must be supplied.","triggerScenarios":"Calling alarm_control_panel.arm_* without a code while the panel entity sets _attr_code_arm_required = True (default) and has a code or default_code configured. disarm is unaffected (it uses code_or_default_code without this gate).","commonSituations":"Automations or scripts calling arm actions without passing a code; UI automations missing the code field; custom panels overriding code_arm_required incorrectly; YAML/scripts created before a code was added to the panel.","solutions":["Pass a valid code in the service call data.","If arming without a code is desired, set code_arm_required: false on the entity (or remove the configured code).","Configure a default code on the entity if automations should use it implicitly.","In custom integrations, ensure code_or_default_code and code_arm_required stay consistent."],"exampleFix":"# before\naction:\n  - service: alarm_control_panel.alarm_arm_away\n    target:\n      entity_id: alarm_control_panel.home\n\n# after\naction:\n  - service: alarm_control_panel.alarm_arm_away\n    target:\n      entity_id: alarm_control_panel.home\n    data:\n      code: \"1234\"","handlingStrategy":"validation","validationCode":"# Before arming, ensure a code is available when required\nif entity.code_arm_required and not entity.code_or_default_code(None):\n    # supply code in the service call or set a default code\n    ...","typeGuard":"def can_arm_without_code(entity) -> bool:\n    return not entity.code_arm_required or bool(entity.code_or_default_code(None))","tryCatchPattern":"from homeassistant.exceptions import ServiceValidationError\n\ntry:\n    await hass.services.async_call(\n        \"alarm_control_panel\", \"alarm_arm_away\",\n        {\"entity_id\": \"alarm_control_panel.home\", \"code\": \"1234\"},\n    )\nexcept ServiceValidationError as err:\n    # translation_key 'code_arm_required': prompt for code\n    ...","preventionTips":["Always pass the code field in arm automations when a code is configured.","Set code_arm_required false only when arming without a code is intentional.","Configure a default code for headless automations."],"tags":["alarm-control-panel","validation","arm","service-validation"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}