diff --git a/README.md b/README.md index 7cbf23f..5c4ded2 100644 --- a/README.md +++ b/README.md @@ -199,13 +199,14 @@ The Alarmo entity follows the state definitions as defined by HA: The Alarmo entity defines the following attributes: -| Attribute | Default value | Example value when set | Description | -| ------------------ | ------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `arm_mode` | `null` | `armed_away` | The current active arm mode.
Defined in all states except `disarmed`. | -| `changed_by` | `null` | `Niels` | User who last armed or disarmed the alarm.
Detected from the entered code.
Cleared when alarm is armed or disarmed without a code. | -| `open_sensors` | `null` | `{binary_sensor.backdoor: on}` | Dictionary of sensors with their entity-ID + state, that caused the alarm to change state.
Set when arming attempt failed (due to one or more sensors).
Set when alarm is triggered (only first sensor that caused the triggering is stored). | -| `bypassed_sensors` | `null` | `[binary_sensor.backdoor]` | List of sensors that are temporarily excluded from the alarm, due to arming in force. | -| `delay` | `null` | 30 | Duration of the exit or entry delay. Only set in the `arming` and `pending` states, `null` otherwise. | +| Attribute | Default value | Example value when set | Description | +| ------------------ | ----------------------- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `arm_mode` | `null` | `armed_away` | The current active arm mode.
Defined in all states except `disarmed`. | +| `next_state` | (same as current state) | `armed_away` | When alarm is in state `arming`: `next_state` is equal to the `arm_mode`.
When alarm is in state `pending`: `next_state` is `triggered`.
When alarm is in state `triggered`: `next_state` is `triggered` (if no trigger time is configured), `disarmed` (if 'disarm after triggering' setting is enabled) or equal to the `arm_mode` (otherwise).
In other cases, the `next_state` will be equal to the current state. | +| `changed_by` | `null` | `Niels` | User who last armed or disarmed the alarm.
Detected from the entered code.
Cleared when alarm is armed or disarmed without a code. | +| `open_sensors` | `null` | `{binary_sensor.backdoor: on}` | Dictionary of sensors with their entity-ID + state, that caused the alarm to change state.
Set when arming attempt failed (due to one or more sensors).
Set when alarm is triggered (only first sensor that caused the triggering is stored). | +| `bypassed_sensors` | `null` | `[binary_sensor.backdoor]` | List of sensors that are temporarily excluded from the alarm, due to arming in force. | +| `delay` | `null` | 30 | Duration of the exit or entry delay. Only set in the `arming` and `pending` states, `null` otherwise. | #### Commands The Alarmo entities support the following commands: @@ -289,12 +290,12 @@ When assigning sensors to Alarmo, the type of the sensor is automatically determ Note that assigning a sensor type is not mandatory, and all configuration settings can also be set manually. It is also possible to deviate from the predefined configuration after setting a type. The following table defines the sensor types and the predefined configuration: -| Type | Device classes | Arm modes | Enabled configuration options | -| ------------- | ----------------------------------------------------- | ------------------------------------------------------------------ | ----------------------------------------- | -| Door | `door`
`garage_door`
`lock`
`opening ` | `Armed Away`
`Armed Home`
`Armed Night`
`Armed Vacation` | `Arm after closing`
`Use entry delay` | -| Window | `window` | `Armed Away`
`Armed Home`
`Armed Night`
`Armed Vacation` | - | -| Motion | `motion`
`moving`
`occupancy`
`presence` | `Armed Away`
`Armed Vacation` | `Use exit delay`
`Use entry delay` | -| Tamper | `tamper`
`sound`
`vibration` | `Armed Away`
`Armed Home`
`Armed Night`
`Armed Vacation` | - | +| Type | Device classes | Arm modes | Enabled configuration options | +| ------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------ | ----------------------------------------- | +| Door | `door`
`garage_door`
`lock`
`opening ` | `Armed Away`
`Armed Home`
`Armed Night`
`Armed Vacation` | `Arm after closing`
`Use entry delay` | +| Window | `window` | `Armed Away`
`Armed Home`
`Armed Night`
`Armed Vacation` | - | +| Motion | `motion`
`moving`
`occupancy`
`presence` | `Armed Away`
`Armed Vacation` | `Use exit delay`
`Use entry delay` | +| Tamper | `tamper`
`sound`
`vibration` | `Armed Away`
`Armed Home`
`Armed Night`
`Armed Vacation` | - | | Environmental | `carbon_monoxide`
`gas`
`heat`
`moisture`
`smoke`
`safety` | N/A | `Always on` | @@ -499,12 +500,12 @@ Example: The following actions are defined in Alarmo and can be used in actionable notifications: -| action | Description | Suitable events | -| ------------------ | -------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | -| `ALARMO_RETRY_ARM` | Repeats the command that failed before.
Will only succeed in case the issue blocking the arming before has been restored. | Failed to arm | -| `ALARMO_FORCE_ARM` | Repeats the command that failed before.
The sensor/sensors that failed, shall be ignored (bypassed) while the alarm is armed. | Failed to arm | -| `ALARMO_DISARM` | Disarm the alarm. | Armed, Leave, Entry, Triggered | -| `ALARMO_ARM_AWAY`
`ALARMO_ARM_HOME`
`ALARMO_ARM_NIGHT`
`ALARMO_ARM_VACATION`
`ALARMO_ARM_CUSTOM_BYPASS` | Arm the alarm in the corresponding mode. | None (intended for automations outside of alarmo). | +| action | Description | Suitable events | +| ----------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | +| `ALARMO_RETRY_ARM` | Repeats the command that failed before.
Will only succeed in case the issue blocking the arming before has been restored. | Failed to arm | +| `ALARMO_FORCE_ARM` | Repeats the command that failed before.
The sensor/sensors that failed, shall be ignored (bypassed) while the alarm is armed. | Failed to arm | +| `ALARMO_DISARM` | Disarm the alarm. | Armed, Leave, Entry, Triggered | +| `ALARMO_ARM_AWAY`
`ALARMO_ARM_HOME`
`ALARMO_ARM_NIGHT`
`ALARMO_ARM_VACATION`
`ALARMO_ARM_CUSTOM_BYPASS` | Arm the alarm in the corresponding mode. | None (intended for automations outside of alarmo). | **Set up notification with actions** In the Alarmo notifications editor, create a notification and select an event. diff --git a/custom_components/alarmo/alarm_control_panel.py b/custom_components/alarmo/alarm_control_panel.py index db0f6a6..2236d50 100755 --- a/custom_components/alarmo/alarm_control_panel.py +++ b/custom_components/alarmo/alarm_control_panel.py @@ -254,6 +254,7 @@ def extra_state_attributes(self): return { "arm_mode": self.arm_mode, + "next_state": self.next_state, "open_sensors": self.open_sensors, "bypassed_sensors": self.bypassed_sensors, "delay": self.delay, @@ -535,6 +536,27 @@ def supported_features(self) -> int: return supported_features + @property + def next_state(self): + """Return the state after transition (countdown) state.""" + next_state = self.state + if self._state == STATE_ALARM_ARMING: + next_state = self.arm_mode + elif self._state == STATE_ALARM_PENDING: + next_state = STATE_ALARM_TRIGGERED + elif self._state == STATE_ALARM_TRIGGERED: + if ( + not self._config + or not self._arm_mode + or not self._config[const.ATTR_MODES][self._arm_mode]["trigger_time"] + ): + next_state = STATE_ALARM_TRIGGERED + elif self._config[const.ATTR_DISARM_AFTER_TRIGGER] or not self.arm_mode: + next_state = STATE_ALARM_DISARMED + else: + next_state = self.arm_mode + return next_state + async def async_added_to_hass(self): """Connect to dispatcher listening for entity data notifications.""" await super().async_added_to_hass() @@ -852,6 +874,22 @@ def supported_features(self) -> int: ] return functools.reduce(operator.and_, supported_features) + @property + def next_state(self): + """Return the state after transition (countdown) state.""" + next_states = list(set([ + item.next_state + for item in self.hass.data[const.DOMAIN]["areas"].values() + ])) + + next_state = self.state + if len(next_states)==1: + next_state = next_states[0] + elif STATE_ALARM_TRIGGERED in next_states: + next_state = STATE_ALARM_TRIGGERED + + return next_state + async def async_added_to_hass(self): """Connect to dispatcher listening for entity data notifications.""" await super().async_added_to_hass()