Time-based gas consumption measurement

Hi,
my gas meter is a SamGas Smart Meter which does not allow continuos readin of the optical port, as it only activated when the button for reading the values on the display is pressed, and only for 2 minutes. It also makes transmission at 169MHz with LoRa, 5 per day, but that would mean intercepting them, but I haven’t found any specification for this.
Then I would like to try to estimate the consumption based on the activation time the consumption read on the meter and the boiler specification.
I installed a flow meter (yf s201) at the water inlet of the gas boiler (condensing boiler for hot water production and heating) which correctly measures the water consumption. I also created a binary sensor that records the state of the sensor.
Now, by doing some test with the meter I can get the gas consumption in m³/min. This test is the same one that eating technicians use to estimate the consumption of gas boilers: open all the hot water taps, take the initil reading and after a minute take the second reading.
could it be convenient to take measurements with defined and longer times?

anyway, since this is an estimate, it could be enough… do you think it is a correct system even if approximate?

now the configuration problem: I can’t figure out how to measure the binary sensor activation time , that is the time it is in the ON state and how to the pass it to the integratin tha will calculate the gas consumption .
Coul you give me a starting point?
And of course some advice on wheter it is a method to try or not …
thanks

If I understood anything from your description, you can use this component:

Sorry but I’m newbie in yaml and homeassistant, i’m an electronics technicians and not a programmer , I still have trouble understanding how yaml and HA works!
So please if you can try to guide me…
this is the part of esphome file with duty time:

I writed this because without I have and errore during compiling but I don’t know if Is correct…

#Binary sensor external call
 - platform: homeassistant
    entity_id: binary_sensor.flow_meter_onoff
    id: binary_sensor_flow_meter_onoff

and this Is the duty_time initial test


#DutyTime 
  - platform: duty_time
    id: my_gas_sensor_work_time
    name: Gas Sensor Work Time
    lambda: "if(id(binary_sensor_flow_meter_onoff).state == true){ return id(my_gas_sensor_work_time);}"
    # Restore (optional, default: False)
    restore: false
    last_time: 
      name: gas sensor last_time turn on 

I started like this and now I can see a diagnostic sensor with the time running during hot water usage and updated every 60 sec, but there’s a problem with of statement.
I’ve tested " == on “, " == ‘on’” , " == true", “== 1” but I receive Always the update of the time every 60 sec as if statement is not present, if I write

return id(my_gas_sensor_work_time);

without the if

what I would like to do is to have an instantaneous value of the time spent actively so that I can then use it in a calculation to measure the gas consumed. Knowing the m³/min consumption of the boiler during the production of hot water, I can estimate how much I am consuming.

I guess the solution is simple but I really don’t know yaml. I wrote a lot in Arduino language (and I had fun :slight_smile: ) on esp and something in python, but here the basics are missing … I’ll learn
Thanks for any help

correct syntax for that conditon is:
if(id(binary_sensor_flow_meter_onoff).state)

I still don’t understand your setup. How yf s201 can be homeassistant sensor? Where is it wired to?

Duty time doesn’t need lambda conditions if you have just plain binary sensor.

yf s201 is a sensor of esp32 with esphome , but I have create a binary sensor with HA GUI , not directly in esphome file ( I guess you’re referring to

platform: homeassistant 
.....

)

so can i remove the lambda? i thought i had to use it because i will need it in the future to be able to skim the measurement. probably my reasoning of how sensors, actions, helpers, etc are used is wrong

Why?

Anyway, if you have valid working binary sensor with esphome id, you just need that id to use duty time:

sensor:
  - platform: duty_time
    id: my_binary_on_time
    name: My Binary Sensor On Time
    sensor: binary_sensor_flow_meter_onoff

I’m not familiar with HA setups in general.

I receive error compiling in this way

Couldn’t find ID ‘binary_sensor_flow_meter_onoff’. Please check you have defined an ID with that name in your configuration.

do you mean I should create a binary sensor in esphome and use it in duty_time?

Do you have have working binary sensor on your setup?

not really… it’s actually a threshold sensor created by the helper, and it’s configured with only an upper limit of 1

I read now that it is not really a binary sensor, even though its entity_id is " binary_sensor.flowmeteronoff" and with this setting I get the “on” and “off” states

Ok, now it’s working :slightly_smiling_face:
I created a binary sensor in esphome .yaml file and use the new id in duty_time platform. Now I see the total sensor up time and last time turn on

1 Like