Templating is killing me…
Is there any simple tutorial on how to transform a "{{ value_json.e85upp }}"
(value today “20170112”)
To be “2017-01-12” instead?
Try this template: "{{ strptime(value_json.e85upp, '%Y%m%d').date() }}"
No, that will give me “unknown”
The value is an MQTT value passed on from my phone with tasker. (along with alot of other values)
When I test {{ strptime('20170112', '%Y%m%d').date() }}
in the template editor, it works and returns 2017-01-12
. So the '20170112'
bit just needs to be replaced with whatever the value is.
When i run your example {{ strptime(value_json.e85pris, '%Y%m%d').date() }}
in the template editor i get:
Error rendering template: UndefinedError: 'value_json' is undefined
i got this as a sensor:
- platform: mqtt
state_topic: “owntracks/matte/location”
name: “E85 Uppdaterat”
value_template: “{{ strptime(value_json.e85upp, ‘%Y%m%d’).date() }}”
(preformatted text dosent work for me right now??)
I found the problem.
This link made me understand…
https://community.home-assistant.io/t/value-json-is-undefined/1030/2
I had missed to enclose the value in “” when i send it from tasker…
Glad you got it to work
Yes, i had never used the template editor to test out my templates.
So that was really helpful to get aware of.