Input_datetime: Convert timestamp to yyyy-mm-dd

Hello everyone,

I am trying to convert a input_datetime entity to a yyyy-mm-dd format.

The entity is:

  input_datetime.tomorrow
    has_date: true
    has_time: true

I want to determine with the workday checkdate action if tomorrow is a workday or weekend.

I have tried:

actions:
  - action: workday.check_date
    metadata: {}
    data:
      check_date: "{{ datevariable }}"
    response_variable: boolworkday
variables:
  datevariable:
    - "{{ strptime(states('input_datetime.tomorrow'), '%Y-%m-%d') }}"

But i do not get it in a ‘yyyy-mm-dd’ format. What am i doing wrong?
Will someone please help?

variables:
  datevariable: >
    {{ states('input_datetime.tomorrow')[:10] }}

That is a possibility. But it will fail when it is e.g. 00:08. Input_datetime.tomorrow is calculated when workday turns to weekend or holiday and vice versa:

Automation:

alias: Update tomorrow
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.workday_sensor
    to: "on"
conditions: []
actions:
  - action: script.determine_tomorrow
    metadata: {}
    data: {}
mode: single

Script determine_tomorrow

action: input_datetime.set_datetime
target:
  entity_id: input_datetime.tomorrow
data:
  timestamp: "{{ now().timestamp() + 86400 }}"

Please, does someone have the answer?

According to your first post, input_datetime.tomorrow is configured to contain both date and time. How can it simply report 00:08 without also including the date?


If you want another way to do it, you can use the Input Datetime’s timestamp value with the timestamp_custom filter.

variables:
  datevariable: >
    {{ state_attr('input_datetime.tomorrow', 'timestamp') | timestamp_custom('%Y-%m-%d') }}

However, if the Input Datetime only contains time but no date, the result of that template will be 1970-01-01 which is the Unix Epoch date.