Help formatting template sensor output

Here is a typical output of a sensor I have HA.

Exited (143) 22 hours ago


I want to change the output to remove the numbers in brackets and replace ‘Exited’ with ‘Stopped’. E.g.

Stopped 22 hours ago


I replaced 'Exited' with 'Stopped' easy enough, but I'm having trouble remove the ' (143)' part (the numbers inside the brackets change)
sensor.docker_pi_hole_uptime:
  value_template: '{{ states.sensor.pi_hole_uptime | replace("Exited", "Stopped") }}'

It looks like I need to use Regex, which I barely know, and searching returned something like this should do it

replace("\([0-9]{3}\)", "")


That doesn’t work, so I’m hoping someone could help getting this formatted how I want :slightly_smiling_face:

try
‘stopped {{ states.sensor.pi_hole_uptime.state.split(")")[1] }}’

way to test it is to go to templates in developers tools and move it around till you get the output you want

1 Like

Perfect, thanks!

Could you explain what this part is actually doing/means?

split(")")[1]


It will hopefully help me understand it more for things in the future :slightly_smiling_face:

the split, splits/separates the content based on your instruction.
In this case it will look for the ) in your “Exited (143) 22 hours ago” state and the number 1 tells it to show the text to the right.
Zero would show left.

1 Like

Great, thanks again :+1:t3: