Correct syntax to extract rightmost character for template value

So I’m trying to setup a sensor that will return the rightmost minute value of the current time.

05:43 return 3
05:04 return 4
05:00 return 0

I’m able to extract the 2 digit minute value, using this but i need to further refine it to 0-9 of whatever 10 min block it is in.

  - platform: template
    sensors:
      minutevalue:
        value_template: "{{ as_timestamp(now()) | timestamp_custom('%-M')  }}"
        entity_id: sensor.time

I’m just not sure how to manipulate the string to return the rightmost digit. I tried this but it returns unknown (my thinking was convert it to string with string() then [-1:]) but I’m very new to python so I’m sure I messed some syntax up.

  - platform: template
    sensors:
      minutevalue:
        value_template: "{{ string (as_timestamp(now()) | timestamp_custom('%-M'))[-1:]  }}"
        entity_id: sensor.time
value_template: "{{ (as_timestamp(now()) | timestamp_custom('%-M'))[-1:]  }}"

Thanks I tried that but there was still an issue. the : in [-1:] needed to be removed. This works now. Figured it out just before you responded, but thanks for the asssist.

value_template: "{{ (as_timestamp(now()) | timestamp_custom('%-M')) [-1] }}"

Just in case anyone was interested in the why. I’m creating a framed touchscreen and my main view displays an overview camera of the house. I don’t really want/need that being the only thing on the screen (boring and a bit worried about burn in). So this is kind of hacky but I replace the live image with a set of 10 family photos until motion is detected.


            cards:
              - type: conditional
                conditions:
                  - entity: binary_sensor.driveway_motion
                    state: "on"
                card:
                  type: picture-entity
                  camera_view: live
                  entity: camera.driveway
                    
              - type: conditional
                conditions:
                  - entity: binary_sensor.driveway_motion
                    state: "off"
                card:
                  type: picture-entity
                  entity: sensor.minutevalue
                  state_image:
                    "0": /local/slideshow/0.jpg
                    "1": /local/slideshow/1.jpg
                    "2": /local/slideshow/2.jpg
                    "3": /local/slideshow/3.jpg
                    "4": /local/slideshow/4.jpg
                    "5": /local/slideshow/5.jpg
                    "6": /local/slideshow/6.jpg
                    "7": /local/slideshow/7.jpg
                    "8": /local/slideshow/8.jpg
                    "9": /local/slideshow/9.jpg

Ha ha ha !
The ‘usual’ suspects !
(Not sure that translates but all posters seemed English primaries)

I don’t see a need to perform timestamp conversions.

sensor.time returns the time as a string so just slice the last character.

  - platform: template
    sensors:
      minutevalue:
        value_template: "{{ states('sensor.time')[-1] }}"

That’s true it would be more efficient/cleaner. Thanks

Hmm…that’s strange it worked fine for me:

But it also worked for me your other way too.