GMFalka
(Gm Falka)
December 14, 2016, 8:50pm
1
Hello!
I have a states.calendar.work.attributes.start_time = 2016-12-15 12:00:00
What is the best way to cut out the date, because i only need the time.
My current template setup:
work_start_time:
value_template: '{{ states.calendar.work.attributes.start_time }}'
Thanks in advance, guys!
Have you tried strptime(string, "%H%M")
?
GMFalka
(Gm Falka)
December 14, 2016, 9:09pm
3
Thanks!
I havent tried anything, cause im very new in this part of HA.
Do you know where should i start learning about strptime, etc.
GMFalka
(Gm Falka)
December 14, 2016, 11:57pm
5
Please forgive my inexperience!
I tried
work_start_time2:
value_template: '{{ strptime("2016-12-15 12:00:00", "%H%M") }}'
but the output is the same (2016-12-15 12:00:00)
ih8gates
(Scott Reston)
December 15, 2016, 12:26am
6
I couldn’t get strptime to work for me, either.
This is hacky, but you could use
{{states.calendar.work.attributes.start_time.split(’ ')[1]}}
That’s “split on spaces” to get a list, and then take 1 (zero based lists).
Templating is based on Jinja . Also, use the template dev tool (button at bottom of HASS sidebar) to debug templates.
2 Likes
GMFalka
(Gm Falka)
December 15, 2016, 1:14am
7
Thank you! That’s how I wanted to workaround this issue.
If strtime not working, is there any other way to change time formats?
2016-12-10 to Dec 10, 2016. (Google maps api takes that format…)
Edit: I know strtime isn’t exactly format changer.
ih8gates
(Scott Reston)
December 15, 2016, 1:37am
8
I wonder if it’s not working there because of the data type of what’s being passed. I was able to get strptime to work on a timestamp (last_triggered) for an automation. What if you try:
{{ states.calendar.work.attributes.start_time.strptime("%H:%M") }}
(again - play around with this in the template dev tool - you can debug in real time)
Updated - I had strftime in my example - meant strptime.
If strptime is not working, you should post a bug report here: https://github.com/home-assistant/home-assistant/issues/new
ih8gates
(Scott Reston)
December 15, 2016, 3:50pm
10
Should strptime work on a string?
GMFalka
(Gm Falka)
December 16, 2016, 12:50am
11
Thanks.
Intrestingly, the dev tool debugger shows the correct output (12:00:00) for your template, but hass --script check_config
shows an error:
while parsing a flow mapping
in "/home/hass/.homeassistant/configuration.yaml", line 136, column 24
expected ',' or '}', but got '['
in "/home/hass/.homeassistant/configuration.yaml", line 136, column 79
ih8gates
(Scott Reston)
December 16, 2016, 12:58pm
12
Can you post what you’ve got on line 136?
You might try this alternate syntax:
value_template: >
{{ states.calendar.work.attributes.start_time.strptime("%H:%M") }}