Showing the last status of a sensor in a template

Anyone know how I could get a template sensor to show the previous status on the front end rather than the current one? Ie after the user unlocks my lock I want to show the last status in this case who unlocked last but as soon as the lock is locked the alarm type changes so I cant see unless I look at the history.

sensor 20:
platform: template
sensors:
template_back_door_unlock_status:
{% if is_state(‘sensor.back_door_alarm_level’, ‘2’) and is_state(‘sensor.back_door_alarm_type’, ‘19’) %} User1 {% endif %}
{% if is_state(‘sensor.back_door_alarm_level’, ‘3’) and is_state(‘sensor.back_door_alarm_type’, ‘19’) %} Guest 1 {% endif %}
{% if is_state(‘sensor.back_door_alarm_level’, ‘4’) and is_state(‘sensor.back_door_alarm_type’, ‘19’) %} Guest 2 {% endif %}
{% if is_state(‘sensor.back_door_alarm_level’, ‘5’) and is_state(‘sensor.back_door_alarm_type’, ‘19’) %} Guest 3 {% endif %}
{% if is_state(‘sensor.back_door_alarm_level’, ‘5’) and is_state(‘sensor.back_door_alarm_type’, ‘19’) %} Guest 3 {% endif %}
friendly_name: ‘Last Unlocked by’

Not really sure what you are asking, but your template looks off. You should use elif:

template_back_door_unlock_status:
  {% if is_state(‘sensor.back_door_alarm_type’, ‘19’) %}
    {% if is_state(‘sensor.back_door_alarm_level’, ‘2’) %}
      User1
    {% elif is_state(‘sensor.back_door_alarm_level’, ‘3’) %}
      Guest 1
    {% elif is_state(‘sensor.back_door_alarm_level’, ‘4’) %}
      Guest 2
    {% elif is_state(‘sensor.back_door_alarm_level’, ‘5’) %}
      Guest 3
    {% else %}
      Someone
    {% endif %}
  {% else %}
    Someone
  {% endif %}

If you need to figure out who the ‘last person to do something’ is, you need to create an automation that stores a current value into a control. Example, if the sensor.back_door_alarm_level is tied to a persons name, then use a input_number to store the sensor.back_door_alarm_level number. Then create a sensor to use that input_number and display a name. It can be quite complicated but the functionality is there.

humm i see what you mean… sound very convoluted will see if I can get this working with appdaemon