How to add a value to a sensor

Helllo all,

Who want to help an inexperrienced yalm user with a question that is simple for you bu I don’t know how to do it.

Ik heb de onderstaande sensors gemaakt:
verbruik 3626
begin 2087
verschil 1539
planning 1500
result -39

Next:

template:
  - sensor:
      - name: “Gas consumption"
        unit_of_measurement: “m3"
        state: >
          {% set verbruik = states('sensor.gas_consumed') | float %}
          {% set planning = states('sensor.gas_planning') | float %}
          {% set begin = states('sensor.gas_begin') | float %}
          {{ (planning-(verbruik-begin)) | round(1, default=0) }}

This works fine and gives the value -39.

Now I want to store this value in the sensor result. How do I get this done now?

Thank you for help.
Peter

I don’t understand the question. You have a working sensor, it has the correct value, so what do you want?

2 Likes

I found the correct value in the script. I also want to be able to display the value in the dashboard. To do that I wanted to write the value in the sensor.result. Only I don’t know how to store the value in the sensor.result.

But maybe I should approach that in a different way? I’m new to yaml so I may be doing it all wrong this way.

You have not shown a script. You have only shown a template sensor. From what you are saying you have already accomplished what you want to do. Now just add the sensor ( sensor.gas_consumption ) to your dashboard in an Entities card.

I had already installed the sensor.gas consumption on the dashboard. It gives the value 3626. I just want to show the result of the calculation (-39) on the dashboard.

Let me know if I am wrong but if in the dashboard you have 3626, you have than “sensor.gas_consumed”… In the dashboard, you should have “sensor.gas_consumption”.

2 Likes

sensor.gas_consumed gives 3626
sensor.gas_consumption 0.0 unit_of_measurement: m3 friendly_name: gas_consumption

So how can I replace the 0.0 with -39 (the result from(planning-(verbruik-begin)) into sensor.gas_consumption

So what you actually mean is that there is a problem with your template.

Use the Developer Tools template editor to try and work out what the issue is. Put this in, what does it give:

          {% set verbruik = states('sensor.gas_consumed') | float %}
          {% set planning = states('sensor.gas_planning') | float %}
          {% set begin = states('sensor.gas_begin') | float %}
          {{ (planning-(verbruik-begin)) }}

-3627.647

Deze template luistert naar de volgende gebeurtenissen met gewijzigde status:

  • Entiteit: sensor.gas_begin
  • Entiteit: sensor.gas_consumed
  • Entiteit: sensor.gas_planning
1 Like

Dear people,
Thank you for your help. It took me two days to get this done. Tried all options to no avail. It turns out that one of the sensors turned out to be a boolean instead of a sensor. Stupid mistake, luckily it works now. Thank you .

Regards,

Peter

1 Like