Delimiter entity

Hello everyone
Does someone have any experience correcting an entity.
I have an entity called “Gas delivered”, which returns a value of “(22031150000)(00)(60)(1)(0-1:24.2.1)(m3)(09808.892)” which should have been 09808,892 m3. I would like to add this value to the energy tab eventually. Before I can, I wil have to correct the value of the entity first. Does anyone have an example how i can correct the value with delimiters for example?

split on value (m3), take second value, and then you only have to replace the last bracket with nothing, something alike


Close but your example results in (09808.892

Try this:

{{ [yoursensorvalue].split('(m3)(')[1].replace(')','')|float(0) }}

:slight_smile: … yep…need to check my writing AND my eyes

{{ states('sensor.gas_delivered').split('(m3)(')[1][:-1] }}

Add float(0) to the end of the template if the goal is to convert it from a string to a number.

{{ states('sensor.gas_delivered').split('(m3)(')[1][:-1] | float(0) }}

Use it in a Template Sensor.

All nice, guys, but I suspect the OP has no clue what you’re talking about :slight_smile:

OP, what is creating this sensor, i.e. what integration? (code welcome)

Thank you all very much for your response.

Chris B you are right, I am starting with HA.

Brief explanation, the device that creates the entity is the Slimmelezer. 
Manufactured by Zuiderwijk (and was also promoted on the energy tab for a 
while) and is (according to HA) based on ESPhome (source code is not in my 
ESPhome enviroment)

The solution of vingerha, tom_I and Taras appeals to me, but I am still 
looking for where to put this.

thanks again for the help provided! 

I did some testing

{{ states('sensor.gas_delivered').split('(m3)(') }} 

gives a value of

{{ states('sensor.gas_delivered').split('(m3)(')[1][:-1] | float(0) }}

gives an error

UndefinedError: list object has no element 1

Like I explained in my post, in a Template Sensor. Read the documentation and it contains examples of how to create a Template Sensor (and, like many things, it’s defined in the configuration.yaml file).

That means the value of sensor.gas_delivered isn’t always like what you described it would be (because the template I posted definitely works with the value you posted, as demonstrated in the screenshot).

I did some homework this week and came to the following setup in my configuration.yaml:

  - sensor:
      - name: "Gas verbruik"
        unit_of_measurement: "m3"
        device_class: energy
        state_class: total_increasing
        state: >
          {% set gas = states.sensor.gas_delivered.state.split('(')[7][:-1] | float(0) %}
          {{ gas }}

I’m getting the values that I am looking for, but for some reason I cannot read this value into the energy module. Em I miss something? Does anyone have experience with this?

Change the device_class to gas.

  - sensor:
      - name: "Gas verbruik"
        unit_of_measurement: "m3"
        device_class: gas
        state_class: total_increasing
        state: "{{ states('sensor.gas_delivered').split('(')[7][:-1] | float(0) }}"

Thank you for the quick response,
your answer sounded very plausible (and looks promising in the developers tab)
unfortunately I still can’t read the value in the energy tab
even after a restart …
I pull my hair out

Did you add it to the Energy dashboard?

Go to Configuration > Dashboards > Energy > Add Gas Source

Screenshot from 2022-03-19 17-09-49

Hi Taras, that’s exactly where I’m trying to add this, but unfortunately the added sensor isn’t there

I see the problem now.

Replace this:

        unit_of_measurement: "m3"

with this:

        unit_of_measurement: "m³"

then execute Configuration > Settings > Server Controls > Reload Template Entities (or restart Home Assistant).

Here is how it looks on my system:

Screenshot from 2022-03-19 18-12-31


The following table lists the correct units of measurement (and it shows that is the unit for gas).

that’s it, thank you so much Taras!! I can add it now.
Although I don’t see any value trickling in at the moment, I assume that this is only a matter of time

thank you so much for all your help

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.