class37
September 18, 2023, 1:46pm
1
I have created a sensor for the next set point in a room of my house. All works fine but I have spent ages reading and searching in how to change the date/time format. I am struggling to find the answer and hoping someone can help. I am very new to this and so far it has been a really long learning curve but well worth it.
This is the sensor
- platform: template
sensors:
climate_office_setpoint_mode_next:
friendly_name: Snug Setpoint Next
entity_id:
- climate.office
value_template: '{{ states.climate.office.attributes.status.setpoints.next_sp_from }}'
The date and time format returns as
2023-09-18T19:00:00+01:00
I would like it to be something like 18-09-2023 19:00:00 or 18th Sept 2023 19:00
Thanks
John
tom_l
September 18, 2023, 1:53pm
2
pedolsky
(Pedolsky)
September 18, 2023, 1:56pm
3
Use device_class: timestamp
class37
September 18, 2023, 2:13pm
4
class37
September 18, 2023, 2:15pm
5
Please could you advise how to add this to the template.
Thanks
John
tom_l
September 18, 2023, 2:20pm
6
{{ states('climate.office','status').setpoints.next_sp_from.strftime('%Y-%m-%d %H:%M') }}
Look at the options in the second link I posted to change the format of the string. You can test it in Developer Tools → Template Editor.
pedolsky
(Pedolsky)
September 18, 2023, 2:30pm
7
- platform: template
sensors:
climate_office_setpoint_mode_next:
friendly_name: Snug Setpoint Next
entity_id:
- climate.office
value_template: '{{ states.climate.office.attributes.status.setpoints.next_sp_from }}'
device_class: timestamp
class37
September 18, 2023, 3:29pm
9
Thank you for your help.
I tried as your suggestion but the date and time remain in the same format.
Thanks
John
class37
September 18, 2023, 3:32pm
10
Thank you,
I have read through the article and tried as you suggested but keep getting the error
str object’ has no attribute ‘setpoints’
Thanks
John
class37
September 18, 2023, 5:11pm
11
I have spent most of the afternoon trying to get this working but unfortunately not able to do so.
As an update I note all the sensors messages etc are all in the same format eg. 2023-09-18T19:00:00+01:00
So it looks like further investigation is needed but just where do I look.
Thanks for all the help
John
pedolsky
(Pedolsky)
September 18, 2023, 5:59pm
12
Just to be sure: Did you reload the template integration?
pedolsky
(Pedolsky)
September 18, 2023, 6:11pm
13
class37:
messages
Copy the following and paste it into Dev Tools:
{% set x = states.climate.office.attributes.status.setpoints.next_sp_from |as_datetime |as_local %}
{{ x.strftime('%d. %b %Y %H:%M') }}
class37
September 18, 2023, 7:10pm
14
Thank you. Yes I did reload. Will give this a try tomorrow.
Thank you for your help. Much appreciated.
class37
September 19, 2023, 8:38am
15
Using your suggestion returns 19 Sep 2023 19:00 which is just how I would like.
However I am struggling to add the line to the template in file editor and keep getting various errors.
Thanks
John
pedolsky
(Pedolsky)
September 19, 2023, 9:03am
16
Try:
value_template: |
{% set x = states.climate.office.attributes.status.setpoints.next_sp_from |as_datetime |as_local %}
{{ x.strftime('%d. %b %Y %H:%M') }}
class37
September 19, 2023, 10:26am
17
pedolsky
Thank you so much for all your time and trouble. Very much appreciated.
This is the final version…
- platform: template
sensors:
climate_office_setpoint_mode_next:
friendly_name: Snug Setpoint Next
value_template: |
{% set x = states.climate.office.attributes.status.setpoints.next_sp_from |as_datetime |as_local %}
{{ x.strftime('%d. %b %Y %H:%M') }}
class37
September 19, 2023, 10:30am
18
This is how it looks. Again many thanks.