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:
{"cnt":"29097,180","pwr":771,"lvl":42,"dev":"(±1%)","det":"","con":"*","sts":"","raw":350}
{"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](//community-assets.home-assistant.io/original/3X/f/7/f7098a79db42728ca87e797c839ea7cedbc504af.png)
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](//community-assets.home-assistant.io/original/3X/b/6/b63b4e33a26d441484309450ca60cbc099a0f0a5.png)
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"