lukevink / hass-config-lajv

Home Assistant Configuration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Date incorrect format

Tobiasn2005 opened this issue · comments

Hi all,

I have this setup in my sensor.yaml:

day:
  value_template: >
    {% set days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] %}
    {{ strptime(states('sensor.date'), '%Y-%m-%d').day }}
    {{ days[now().weekday()] }}
month:
  value_template: >
    {% set months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] %}
    {{ strptime(states('sensor.date'), '%Y-%m-%d').day }}
    {{ months[now().month-1] }}
date_string:
  friendly_name: "Full Date"
  value_template: "{{ states('sensor.day') }}, {{ states('sensor.month') }} {{ now().year }}"

And in my ui-lovelace.yaml I have this:

        - entity: sensor.time
          hold_action:
            action: none
          style:
            color: 'rgba(255, 255, 255, 0.7)'
            font-size: 5.41vw
            font-weight: 200
            left: 2.7%
            letter-spacing: '-0.05vw'
            max-width: 1px
            top: 10%
          tap_action:
            action: none
          type: state-label
        - entity: sensor.date_string
          hold_action:
            action: none
          style:
            color: 'rgba(255, 255, 255, 0.3)'
            font-size: 1.3vw
            font-weight: 300
            left: 18.1%
            letter-spacing: '-0.05vw'
            text-align: left
            top: 17%
            width: 30%
          tap_action:
            action: none
          type: state-label

But when opening my dashboard I see the day numer on front of the actual day:

image

How can I get rid of that?

@Tobiasn2005 I had the same issue.
I fixed it by replacing %d in the day template with %dd. See my code below.

day:
  value_template: >
    {% set days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] %}
    {{ strptime(states('sensor.date'), '%Y-%m-%dd').day }}
    {{ days[now().weekday()] }}

Glad you worked it out! Sorry for not getting to you earlier.