Strptime templating

I have a sensor that gives date as a string. I have tried the following template in Developer tools and it works

{{strptime((states('sensor.papp_og_papir')),"%d/%m/%Y") }}

However, when I tried to use this to create a template sensor. the config is invalid

  - platform: template
    sensors:
      Papp:
        value_template: >-
          {{strptime((states('sensor.papp_og_papir')),"%d/%m/%Y") }}

Any help is appreciated. Also would that be possible to put the value_template with the sensor config?

  1. What is the error in the homeassistant.log file inside your config folder?

  2. What are you trying to display in that field? That’s a datetime object that’s incomplete when using strptime. You’re essentially doing nothing with it so the conversion is pointless.

  3. What do you intend to do with it as a sensor?

  4. Also, it’s possible that HA no longer allows capitals for fields either. Its always been a no-no to use capitals for field names (Papp in your case), they may cause invalid configs now.

  5. I’m not sure why you have the states method wrapped in (). It’s not needed and just makes the code more confusing to read. I know a lot of people like using them liberally, but you should get used to trusting order of operation in code. The parenthesis on the outside of (states('sensor.papp_og_papir')) are doing nothing for your code.

  - platform: template
    sensors:
      papp:
        value_template: >-
          {{ strptime(states('sensor.papp_og_papir'),"%d/%m/%Y") }}