Ok, so this shouldn’t be as headache-inducing as its been, but I’m just try to accomplish a few things here.
ultimately have a frontend Date & Time displayed from a timestamp i set in an input_datetime var in hass
in an automation I’m trying this [below] method to format the date and time the way i want it ultimately displayed. But as you can see from the dev templating screen below, I’m getting this random date and time from my input_datetime thats obviously not right. How is this happening; where is it getting that December 31, 1969 and 7:00 PM from?
You can see the data is correct in the states above for that input_datetime.
date: >
{{ now().strftime('%B %d, %Y') | replace(" 0", "") }}
time: >
{{ (now().strftime('%-I:%M %p')) }}
{{ states.input_datetime.cgm_sensor_start }}
================================
date: >
{% set date = states('input_datetime.cgm_sensor_start') | float %}
{{ date | timestamp_custom("%B %d, %Y", true) }}
time: >
{% set time = states('input_datetime.cgm_sensor_start') | int %}
{{ time | timestamp_custom("%-I:%M %p", true) }}
Heres my next issue beyond this one. Even when the state is manually set to the format i want, its displayed in the front end in its original format. But more_info on that input_datetime shows the correct format?
I’m starting to think input_datetime cant handle these new formats I’m trying to input.
I’m assuming i need a sensor template to take the original datetime and convert it for display in the front end. But this is where I’m lost. There’s just too many things going on here that dont add up.
Could anyone post the method to do this efficiently and properly? I just need a date and time (i set) to be viewable in the frontend in the format of “July 4,2020 5:08 PM”. Maybe I’m going about this all wrong.
Thanks A lot. I knew that was wrong. Just one more little thing and I’m all good.
The output now is (‘July 4, 2020’, ‘5:08 AM’) with the ( and ‘ on both ends; how can i remove those?
Here my sensor.
- platform: template
sensors:
cgm_sensor_start:
friendly_name: "G6 Sensor Start: "
value_template: >
{% set date = state_attr('input_datetime.cgm_sensor_start', 'timestamp') | timestamp_custom('%B %-d, %Y') %}
{% set time = state_attr('input_datetime.cgm_sensor_start', 'timestamp') | timestamp_custom('%-I:%M %p') %}
{{date, time}}
The reason i want this static data as a sensor is because of where i can use it, and how it displays in the frontend.