Only display last time alarm was armed

Hi,

Hopefully this has an easy solution as I want to apply the same method for other devices.

I have been trying to display the last time my home alarm was armed (and only that), but I’m not getting it to work as intended - as it’s also showing when it was last disarmed (overriding the armed state).

Here’s my sensors (perhaps I don’t need to do this in two steps…)

  risco_armed:
    value_template: >
      {% set entity_id = 'alarm_control_panel.risco_larm_partition_0' %}
      {% if is_state(entity_id, 'armed_away') %} Risco is armed
      {% endif %} 

  risco_status: 
    friendly_name: "Alarm last armed:"
    value_template: "{{ as_timestamp(states.sensor.risco_armed.last_changed)|timestamp_custom('%H:%M - %d/%m') }}"

And here’s how I want to display it in lovelace (other devices sorted in auto-entities):

  - type: custom:auto-entities
    card:
      type: entities
    filter:
      include:
        - entity_id: sensor.risco_status
        - entity_id: sensor.altan_door
        - entity_id: sensor.garden_motion
    sort:
      method: last_changed

Looking at my sensor.yaml and the code I have there, I do see and can understand why it’s not working (as the “last_changed” is more working as a toggle). And also in the auto-entities card, as it’s also “last_changed” there. But I don’t know how to fix it, so would appreciate some help :slight_smile:

I have also trying to create an automation for when the alarm was set to armed_away and display that, but I’m not really getting it to work (plus is doesn’t work with my auto-entities display).

Thanks.

  risco_status: 
    friendly_name: "Alarm last armed:"
    value_template: >
      {% if is_state('alarm_control_panel.risco_larm_partition_0', 'armed_away') %}
        {{ as_timestamp(states.alarm_control_panel.risco_larm_partition_0.last_changed)|timestamp_custom('%H:%M - %d/%m') }}
      {% else %}
        {{ states('sensor.risco_status') }}
      {% endif %} 

If the alarm panel is currently armed, the sensor displays the alarm panel’s last_changed value. If the alarm panel is not armed, the sensor displays its own existing value (representing the previous time the alarm panel was armed). Initially this value will be unknown but will become a known value the moment the alarm panel is armed (and thereafter).

Works like a charm. Thanks @123 !

1 Like