Mixing UTC and local timestamps

I’ve got a template that only shows a door keypad entry for about a minute then resets to 0. Since the door keypad itself hangs on to the value until a new code is entered.

      template_door_code_entered:
        value_template: >-
          {% if (((as_timestamp(strptime(states.sensor.date_time.state, "%Y-%m-%d, %H:%M")) + 18000 - 
                  as_timestamp(states.sensor.schlage_fe599gr_wireless_door_lock_alarm_level.last_changed))) | abs < 60) %}
            {{ states.sensor.schlage_fe599gr_wireless_door_lock_alarm_level.state }}
          {% else %}
            0
          {% endif %}
        friendly_name: 'Door Code Entered'

This works fine EXCEPT the adjustment of 18000 seconds has to be made since the sensor.date_time is in my local timezone and the schlage timestamp is in UTC. This 18000 value “breaks” when daylight savings changes.

Anyone know how to make this template work by forcing everything to local timezone or everything to UTC? I have tried a few things unsuccessfully.

Note: I rely on sensor.date_time since it updates regularly on it’s own, hence why now() or utcnow() are not used in this case.

Read finity’s EPIC time manipulation thread, most people’s time handling questions are answered there.

I knew if I tried enough variations I’d come up with something. Found a solution using as_timestamp twice, applying a local filter to the schlage -

      template_door_code_entered:
        value_template: >-
          {% if ((as_timestamp(strptime(states.sensor.date_time.state, "%Y-%m-%d, %H:%M")) - 
                  as_timestamp(as_timestamp(states.sensor.schlage_fe599gr_wireless_door_lock_alarm_level.last_changed)|timestamp_local)) | abs < 60) %}
            {{ states.sensor.schlage_fe599gr_wireless_door_lock_alarm_level.state }}
          {% else %}
            0
          {% endif %}
        friendly_name: 'Door Code Entered'