- sensor:
- name: "Linktap scheduled start time isoformat"
device_class: timestamp
state: >
{% set a = states('input_number.linktap_default_am_time_in_minutes')|float %}
{% set b = (a/60)|int %}
{% set c = (a - (b*60))|int|string %}
{% if c|length==1 %}
{% set c = "0" + c %}
{% endif %}
{% set am = b|string + ":" + c|string + ":00" %}
{% set a = states('input_number.linktap_default_pm_time_in_minutes')|float %}
{% set b = (a/60)|int %}
{% set c = (a - (b*60))|int|string %}
{% if c|length==1 %}
{% set c = "0" + c %}
{% endif %}
{% set pm = b|string + ":" + c|string + ":00" %}
{% if states('input_boolean.linktap_am_pm_0') == "on" %}
{% set tod = pm %}
{% else %}
{% set tod = am %}
{% endif %}
{% set day = states('input_datetime.linktap_date_0') %}
{% set thedate = day + " " + tod %}
{{(thedate|as_datetime|as_local).isoformat()}}
Either a datetime object or timestamp string (ISO 8601) is acceptable… in your example the .isoformat() is superfluous because you already have a datetime object.
I think the following should do the same thing:
{% set am_pm = 'pm' if is_state('input_boolean.linktap_am_pm_0', 'on') else 'am' %}
{% set ent = 'input_number.linktap_default_'~am_pm~'_time_in_minutes' %}
{% set mins = states(ent)|int(0) %}
{% set date = states('input_datetime.linktap_date_0')|as_datetime|as_local %}
{{ date + timedelta(minutes=mins) }}
Thanks @Didgeridrew.
That is so funny - 5 lines instead of 22
There’s some useful stuff there for me to learn - thank you.
(As you can tell I’m not very good at this yet.)
The sensor is part of quite a big project (and I am extremely proud of it).
Here’s one of the dashboards: