Change the value of a sensor ["xx.xxx"]

Temperatura Caldaia (Server Blynk)

gives me this result [“70.688”]

I have to convert it to

70.7

If you have jq available locally, you could try adding | jq -r '.[0]' to the command line.

Try this:

    value_template: "{{ value[0] }}"

no.

i try

value_template: "{{ value | replace (‘[’, ‘’)| replace (‘]’,‘’)| round(1) }}"

result ----“71.250”

When you said this:

I assumed it received a list (because that’s how a list would appear) and so value[0] would return the first item in the list (which would be 70.688).

However, you reported that it didn’t work which means it’s not a list but a string (and it simply has the appearance of a list).

In that case, the simplest way to extract the value is to slice off the parts you don’t want which are the first two and last two characters.

  value_template: "{{ value[2:-2] | round(1) }}"

The technique used is python’s native string-slicing capability.

Here’s a screenshot of the Template Editor demonstrating that the technique works:

Screenshot from 2021-04-06 18-14-37

1 Like

Work, Thanks

1 Like