Using an input helper to update a timestamp sensor

Assuming the input_datetime contains date and time:

template:
  - sensor:
      - name: whatever
        device_class: timestamp
        state: "{{ states('input_datetime.something') | as_datetime | as_local }}"

Assuming the input_datetime contains time only:

template:
  - sensor:
      - name: whatever
        device_class: timestamp
        state: "{{ today_at(states('input_datetime.something')) }}"

EDIT

Correction. Added as_local filter to ensure datetime has timezone information.

7 Likes