How to use value_template to extract data from the sensors command

I can’t debug your code because you haven’t formatted it as requested. You have pasted it in like text, so the quotes are turned to invalid “smart” quotes, and you appear to have lost a load of backslashes from my template.

However, as a first step, it looks from that screenshot that there is more than one space before the number you want, unlike in your initial post (again, if you’d formatted that as code, that would have been visible to me). Try these templates:

'{{ (value|regex_findall("Package id 0:\s*\+?(\-?[\d\.]*)°"))[0] }}'
'{{ (value|regex_findall("Composite:\s*\+?(\-?[\d\.]*)°"))[0] }}'

Here’s a breakdown of what that regex pattern is looking for:

Composite:\s*    Find "Composite:" followed by any amount of whitespace
\+?              There might be a plus sign which we do not need
(                Start the "match" section: the bit we want
\-?              There might be a minus sign which we do need
[\d\.]*          Keep going over any combination of digits and decimal points
)                End of the "match" section
°                and there should be a degrees sign to finish

It’ll return a list of matches, which should contain just one e.g. ["36.9"].

2 Likes