Youless on a gas meter - actual usage

Hi,

I use a youless to measure gas consumption, which returns a JSON I can add into HA.

{"cnt":"29097,180","pwr":771,"lvl":42,"dev":"(±1%)","det":"","con":"*","sts":"","raw":350}

The important fields are pwr (current gas cubic meter consumption/1000 per hour) and cnt (current meter reading)
I can get pwr into HA with a rest sensor:

    - platform: rest
      resource: http://ip-of-youless/a?f=j
      value_template: '{{ value_json.pwr }}'
      method: GET
      name: gas usage
      unit_of_measurement: "m3/h"

Is there a way to get the actual mÂł consumption, maybe using the meter reading field (cnt)? Here are two readings taken in different times:

  1. {"cnt":"29097,180","pwr":771,"lvl":42,"dev":"(±1%)","det":"","con":"*","sts":"","raw":350}
  2. {"cnt":"29097,310","pwr":763,"lvl":45,"dev":"(±4%)","det":"","con":"*","sts":"","raw":345}

While the consumption is about 0.8 mÂł/h, the actual consumption is 0.12 mÂł (2.cnt - 1.cnt). Can this sensor be created?

Thanks

You want to look at the statistics sensor:

So, for example, make a rest sensor for the ‘cnt’ value, then use that sensor in the Statistics sensor.

If you wanted to know the total consumption in the past 24 hours, you could make your statistics sensor be of type ‘total’ with a max_age of 24 hours.

Help me out, please


  - platform: rest
    resource: http://192.168.178.89/a?f=j
    value_template: '{{ value_json.cnt }}'
    method: GET
    name: Gas Actual Usage
    unit_of_measurement: "m3"
  - platform: statistics
    entity_id: sensor.gas_actual_usage

But when I add it to lovelace it shows the status a unknown

Home_Assistant

For clarity, Domoticz can show the following reports (this case water) with the same input data. I’m trying to replicated these in HA

The reason the statistic sensor says “Unknown” is because the rest sensor is outputting a text value. Change your value_template to:

 value_template: '{{ value_json.cnt | int }}'

that should make it an integer value rather than text and the statistics sensor should then work properly. As the documentation says, the sensor will report the “mean” over the last 20 samples
 which is not really what you want. If you want to to look at how much gas you’ve consumed in the past 24 hours, you’d set the sensor up like so:

  - platform: statistics
    entity_id: sensor.gas_actual_usage
    max_age:
      hours: 24

Note: it may take some time before there are enough reading for the statistics sensor to populate.

Since this is plotting the absolute value of the counter (i.e., total gas consumed since the meter was started) - it’s still not going to be what you want. To replicate the graphs that you see with Domoticz, you’d have to do something more sophisticated with a package like Grafana and InfluxDB, which is a plotting package that uses the history database make all sorts of plots. But that’s a much bigger deal (I’ve never done it, so I can’t help you there).

1 Like

The static sensor still shows zero.

image

The device sends units with a comma as a decimal separator, could this be the problem?

I missed that this was actually a decimal value i.e., float
 try this:

 value_template: '{{ value_json.cnt | float }}'

You may have to have your computer that’s running HA set to a region that uses commas as as the decimal separator for it to work, but I’m not sure.

1 Like

Hi,

When using this float it issant reading the value for cnt.

 value_template: '{{ value_json.cnt | float }}'

For cnt the value starts en ends with " I think this is the issue:
{“cnt”:“55602,513”,“pwr”:169,“lvl”:8,“dev”:"(±0%)",“det”:"",“con”:“OK”,“sts”:"(45)",“raw”:75}

Hi when using the following rest its working I get the data in HA, but I get a error in the log:
sensor.stats: parsing error, expected number and received
How can I fix this?

- platform: rest
    resource: http://192.168.x.x/a?f=j
    value_template: '{{ value_json.cnt}}'
    method: GET
    name: Meterstand
    unit_of_measurement: "kWh"