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?