Gaijin66
(Gerrit de Boer)
March 7, 2025, 2:29pm
1
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?
123
(Taras)
March 7, 2025, 2:39pm
2
variables:
datevariable: >
{{ states('input_datetime.tomorrow')[:10] }}
Gaijin66
(Gerrit de Boer)
March 8, 2025, 11:02pm
3
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?
123
(Taras)
March 10, 2025, 2:11pm
4
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.
Gaijin66
(Gerrit de Boer)
March 17, 2025, 8:16pm
6
As a matter of fact: There is.
First of all I want to thank you for your input.
I took a different approach.
This is the datetime helper:
entity_id: input_datetime.tomorrow
has_date: true
has_time: false
entity_id: input_datetime.sleeptime
has_date: false
has_time: true
This script is working:
sequence:
- action: input_datetime.set_datetime
target:
entity_id: input_datetime.tomorrow
data:
timestamp: "{{ as_timestamp(now()) + 86400 }}"
alias: Determine tomorrow
description: ""
But the automation has an error. I do not know what it is yet.
alias: Set Bedtime
description: ""
triggers:
- trigger: state
entity_id:
- binary_sensor.workday_sensor
conditions: []
actions:
- action: script.determine_tomorrow
data: {}
- action: workday.check_date
data:
check_date: "{{ states('input_datetime.tomorrow') }}"
target:
entity_id: binary_sensor.workday_sensor
response_variable: check_date
- action: input_datetime.set_datetime
data:
time: "{% if check_date %}23:00:00{% else %}02:00:00{% endif %}"
target:
entity_id: input_datetime.sleeptime
mode: single