Trigger Event Time: Can it be shifted to my timezone?

When I look at the event bus for state_changed events, I see that the event.data.new_state.state value is UTC, and thus, when I use a template to set a sensor state to that value, it’s consistently off by exactly 7 hours. I’m in Arizona (-7).

In my trigger template I have this:

- trigger:
    - platform: event
      event_type: "state_changed"
      event_data:
        entity_id: input_button.fair_play_task_home_garbage
  sensor:
    - name: "Fair Play Task Home Garbage Last"
      state: "Hello"
      attributes:
        old_state: "{{trigger.event.data.old_state.state}}"
        new_state: "{{trigger.event.data.new_state.state}}"

…which correctly adds the attributes to the sensor, however, the times are off by 7 hours.

I tried "{{ as_local(trigger.event.data.old_state.state}}" but that rendered the entire sensor unavailable.

What am I doing wrong?

Is it possible that your HA does not have the proper location / timezone set?

Settings… System… General

I figured it out. as_local only works on as_datetime objects. Since the value is a string, I first need to convert it to datetime, then apply local.

{{as_local(as_datetime(trigger.event.data.old_state.state))}}

That works.

I do in fact have the correct time zone set for the system, but this time string is embedded in the trigger data and needs to be adjusted for some reason.