Is 'as_timestamp(now())' misbehaving since v115? [Solved]

In 0.115, templates in the Template integration are evaluated more efficiently. However, the new technique has deprecated the use of the entity_id option.

That means the entity_id option in your Template Sensor is now ignored (so sensor.time is not being included). Your template contains no entities (so no listeners can be assigned) therefore it is evaluated at startup and never again (until the next restart).

For more information: Heads up! Upcoming breaking change in the Template integration

I suggest you change the template to this:

  - platform: template
    sensors:
      simple_time:
        friendly_name: "Simple Time"
        value_template: >
          {{ as_local(states.sensor.time.last_updated).timestamp() | timestamp_custom('%-I.%M %p') }}

If you test this new template in the Template Editor, it confirms that it has detected the sensor.time entity and assigned a listener to it.

The reason why that works is because sensor.time has been included in the template (it also works with all versions of Home Assistant prior to 0.115). Here’s another way to include sensor.time:

  - platform: template
    sensors:
      simple_time:
        friendly_name: "Simple Time"
        value_template: >
          {% set x = states('sensor.time') %}
          {{ now().timestamp() | timestamp_custom('%-I.%M %p') }}


EDIT

Correction. Used the wrong character (<) for indicating line-continuation!

1 Like