Hi!
I want to Split a value from another Sensor:
value_template: '{{ states.sensor.sprit.state | split(" ")[0] }}'
But that is not the right Syntax:( can someone help me?
Hi!
I want to Split a value from another Sensor:
value_template: '{{ states.sensor.sprit.state | split(" ")[0] }}'
But that is not the right Syntax:( can someone help me?
We’d need to see the raw output of “sprit” to help. Also - the template dev tool (buttons at bottom of left sidebar) is your friend for diagnosing this kind of thing. You can test till you get what you expect.
Ok
My first sensor:
- platform: scrape
resource: "http://www.clever-tanken.de/tankstelle_details/10824"
name: sprit
select: '#main-content-fuel-price-list'
value_template: '{{ value.split("-")[2] }}'
unit_of_measurement: '€'
The result of the first sensor: 1.11 9+ MTS €
But my result should look like 1.119 €
So my plan ist to split the value at the " " and after that i transform the 1.19 in a float and add 0.009
But I’m not sure about the synthax how to split the first value…
You were close.
'{{ states.sensor.sprit.state.split(" ")[0] }}'
Should should return 1.11
But to add the 0.009, you need to cast it as a float (since what you’ve got is a string)
{{ states.sensor.sprit.state.split(' ')[0] | float + 0.009 }}
should do the trick.
Thank you! That works!
Hi I wonder if you help me with mine
Sensor is
sensor.mybuttoncardsensor
Output is
Mixed dry recycling (blue lidded bin) and glass (black box or basket)
syntax I have is
return entity.state.split(“|”)[0]
What I’m looking for is to display just the 1st 20 characters of output.
is this possible
Try:
entity.state|truncate(20, true, '')
You can find the Jinja documentation for the truncate
filter here.