Hello everyone,
Hoping someone can help me resolve sensor / configuration setup puzzle that I’ve been working on. I ask for your pardon since my grasp on how templates work and how data states are recognized within HA is shaky at best.
Problem
I have a manual gas meter that doesn’t have any of the cool ways to read data from it (someone has to do a manual read every cycle), but I would like to set up a virtual gas meter based on measured consumption rates from two of my major appliances that I can know the states of within HASS: My HVAC furnace which is driven by a Nest thermostat, and my fireplace which I control with a custom controller built with ESPhome. Using the device states and known information about consumption rates, I’d like to calculate the usage and feed this into the energy panel.
Specifics about the devices
For the HVAC, this uses a consistent rate which I have calculated to be approximately 1.42857144 ft³ / minute or 85.7142864 ft³ / hour. To this effect, I found this post somewhat helpful but wondered if the solution was as elegant as it could be considering it needed three separate entities to do the job. It also only focuses on one device, where I’m trying to combine at least two with different math.
For the fireplace, things are a little more complicated because the consumption rate adjusts in a linear fashion based on how open the valve feed is, which I can read as a number from 0 (pilot) to 10 (full blast). With the valve open all the way, it’s basically 30 ft³ / hour and decreases linearly as you close each step. If the valve is set to 5, the flow is 50% of max. So my math says [30 ft³/hour * (valve value * 0.1)].
Why I need help?
While I can appreciate that any problem has a number of potential solutions, I’m getting a little lost in my own head about how to go about this as well as failing to understand how to pass information templates and effectively use things like [total_increasing]. I don’t quite understand how to properly trigger a sensor to ‘pulse’ a usage number into another sensor and integrate those values over time in a way that the gas consumption feature in the energy panel can understand.
So far, I only have
- platform: template
sensors:
total_natural_gas_usage:
unit_of_measurement: "ft³"
value_template: "{{ states('sensor.current_natural_gas_usage') | float }}"
device_class: gas
attribute_templates:
state_class: total_increasing
…which seems to load into the Energy Panel without issue, but the values being generated by…
- name: current_natural_gas_usage
unit_of_measurement: "ft³/s"
device_class: gas
icon: mdi-gas-cylinder
state_class: measurement
state: >
{% if DEVICE_IS_ON_AND_CONSUMING %}
{{ DO_MATH }}
{% endif %}
… and while this makes the Gas Monitor do things, the numbers are clearly not right.
At this point I’m questioning if I’m going about this all wrong and before I spin my wheels on it for days and days, I figured I’d ask if there was a straightforward way and get a hint on where to go next. I considered doing things in NodeRed or MQTT but maybe that complicates things? I don’t know…
To that end, any guidance or if anyone has solved this is different ways, I’d love to compare notes and would appreciate the engagement!