Create sensor to show only today’s day “number” (i.e. 2018-06-12, my sensor would output the “12”)

Just curious if it’s possible to extract or read from my date sensor that I already have that shows the year, month, day to output a new sensor that just shows the number of the day only. Looking for a way to read the last two digits of the date sensor’s current state:

Capture2

it was working before I updated to hass.io but now it’s not. Here’s what I was using before that worked:

sensor:
  - platform: template
    sensors:
      today_number:
        value_template: '{{now().strftime("%-d")}}'

Try {{now().strftime("%d")}} on hassio.
Don’t know why, but there’s something different with this in hassio.

You could do it like this:

sensor:
  - platform: template
    sensors:
      today_number:
        value_template: "{{ states('sensor.date') | regex_replace('....-..-') }}"

From what I understand, using just now() in a template sensor may not work since it might not update as you expect. But using sensor.date is fine because it definitely generates state change events (which will cause this template sensor to update accordingly.)

1 Like

Thanks guys, looks like both of these work great, thanks!

1 Like