Template support for alarm_control_panel#24997
Conversation
|
Hey there @PhracturedBlue, mind taking a look at this pull request as its been labeled with a integration ( This is a automatic comment generated by codeowners-mention to help ensure issues and pull requests are seen by the right people. |
|
What functionality here isn't supported already via the manual alarm control panel + automations? |
|
@MartinHjelmare - fair question. They're fairly different, though. The manual panel is best for creating a new panel from scratch, where one doesn't already exit. The logic and state machine is managed by Home Assistant. The template panel is best for augmenting the behavior of an existing panel, or series of security devices, whose state machine is managed externally. For example - template panel supports templating for rendering state. My own use case here is adjusting the behaviour of our actual alarm panel when exposed via Home Assistant and Siri. I want our panel to only be "quick armable" via Homekit if one of us is home, and "disarmable" under other complex rules. I also need to be able to augment the Alarmdecoder component, which doesn't support "Night" mode properly (as the underlying AlarmDecoder API doesn't, and my PR to fix that natively within the component was rejected as a result). |
|
@balloob do you think we should add this next to the manual alarm control panel? |
|
@MartinHjelmare - I honestly think that these are two really different use cases. For me, the “template” series is about adjusting the behaviour of existing components, or merging several together to present something more logical in HASS (or onward tools, like Alexa, Google, Siri). It’s also incredibly powerful for adjusting the logic of existing devices when controlled via the UI or other apps (e.g. “if the light brightness is manually controlled turn off the flux component”, or “if the alarm is sounding or no-one is home, refuse to disarm it via the UI”). The Manual Alarm Control Panel is a complex beast that’s about creating a full-fledged security system within Home Assistant. For the UI-adjustment use cases that’ll lead end users to have to create a lot of configuration code, and try and synchronize two different state machines.... that’s likely to lead to poor user experiences, and other fun bugs (e.g. what happens when HASS is restarted?...) |
|
I want a second opinion before I go ahead and review. |
|
I think that this would be a useful contribution. @alistairg has a good point with state being managed outside of this integration versus the manual alarm, which manages it itself. |
MartinHjelmare
left a comment
There was a problem hiding this comment.
I haven't looked at the tests yet.
| vol.Optional(CONF_ARM_HOME_ACTION): cv.SCRIPT_SCHEMA, | ||
| vol.Optional(CONF_ARM_NIGHT_ACTION): cv.SCRIPT_SCHEMA, | ||
| vol.Optional(CONF_ICON_TEMPLATE): cv.template, | ||
| vol.Optional(CONF_ENTITY_PICTURE_TEMPLATE): cv.template, |
There was a problem hiding this comment.
Do we need entity picture and icon template?
| alarm_control_panels = [] | ||
|
|
||
| for device, device_config in config[CONF_ALARM_CONTROL_PANELS].items(): | ||
| friendly_name = device_config.get(CONF_FRIENDLY_NAME, device) |
There was a problem hiding this comment.
Please use dict[key] for required config keys and keys with default config schema values.
| code_arm_required, entity_ids) | ||
| ) | ||
|
|
||
| if not alarm_control_panels: |
There was a problem hiding this comment.
We should require at least one alarm panel in the config schema.
| return False | ||
|
|
||
| async_add_entities(alarm_control_panels) | ||
| return True |
There was a problem hiding this comment.
Nothing is checking this return value. We can remove this statement.
| self._state = None | ||
| self._icon = None | ||
| self._entity_picture = None | ||
| self._brightness = None |
| optimistic_set = False | ||
|
|
||
| if self._template is None: | ||
| _LOGGER.info("Optimistically setting arm state to Away") |
| ATTR_CODE: code | ||
| }, context=self._context) | ||
| else: | ||
| _LOGGER.warning("No script action defined for Arm Away.") |
There was a problem hiding this comment.
We don't end logging messages with period.
|
A couple of months have passed now, without activity on this PR. Nevertheless, @alistairg, I hope you are able to re-open and pick up again since this contribution would be very much appreciated 👍 |
Description:
Template support for alarm control panel - templated state, icon, entity picture. Scripted actions for arm away, home, stay and disarm.
Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#9801
TBD
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
python3 -m script.hassfest.requirements_all.txtby runningpython3 -m script.gen_requirements_all..coveragerc.If the code does not interact with devices: