A counter to be used with a gas meter

Hello,

I’m using a reed contact attached to GPIO 18 of my raspi to count the consumption of my gas meter. This works fine, the signal goes from off to on to off during each cycle of the meter. I can see this changing entity in my frontend.

Now I want to start counting the consumption. During each change from off to on, a counter shall be incremented by 0.01. I’ve already configured a counter in configuration.yaml:

binary_sensor:
  - platform: rpi_gpio
    invert_logic: true
    ports:
      18: GASZAEHLER
      
counter:
  gas_counter:
    initial: 30
    step: 0.01

Now I’m struggeling to configure an automation for this, to increment the counter?
What is the best option to do that?
And: I want to create a chart that will display my daily/weekly/monthly consumption. Grafana should be the best to do that? Other options?

I’m new to HA, as I was using pimatic before (and still do). So please leave me some good examples, that will be easy to understood for me. :slight_smile:

Many thanks!
Stefan

trigger:
  platform: state
  entity_id: binary_sensor.gaszaehler
  from: 'off'
  to: 'on'
action:
  service: counter.increment
  entity_id: counter.gas_counter

Use utility meters to keep track of daily/weekly/monthly consumption.

You can graph the utility meters if you wish. InfluxDB & Grafana would be better for cycle lengths longer than a week.

1 Like

Thanks @tom_l

I made a little progress, but still did not reach the target. The automation has been triggered, but the counter is still not updated. Where do I need to look at, to check possible reasons? Is there some logfile or debig mode that I have to check?
I also created a Utility meter, but as the counter seems not to be updated, this is also not working.

And it seems, that I cannot increment the counter by 0.01, as it is an integer value? So I have to multiply by 100 and later (in the display and stats) I have again to divide it by 100? Other possibilities?

I’m still a little lost here …

Many thanks
stefan

Yeah looks like that is the problem:

Screenshot_2020-09-09 Counter

It also does not work with step 1. This is my current automation:

- id: '1599567415142'
  alias: Gasmonitor
  description: ''
  trigger:
  - entity_id: binary_sensor.gaszaehler
    platform: state
    from: 'off'
    to: 'on'
  condition: []
  action:
  - data: {}
    service: counter.increment
    entity_id: counter.gas_counter
  mode: single

So you changed this config?

to

counter:
  gas_counter:
    initial: 30
    step: 1

and restarted. Correct?

yes, changed and restarted. But without effect.

What happens if you manually trigger the automation, does the counter increment?

Edit: try it like this:

  action:
    service: counter.increment
    data:
      entity_id: counter.gas_counter

Does not work as well. The counter stays at the initial value.
But I found out, that yesterday evening the counter has moved to 31, but reverted to 30 afterwards.

I found the solution:

The naming for the counter does not allow an underscore “_” like in my 1st post!
After removing the underscore, the counter is running as expected.
Isn’t there any way to detect this by a debug mode or logfile?
It’s a little bit annoying to search the error that way.

counter:
  gascounter:
    step: 1

Not working:

counter:
  gas_counter:
    step: 1

The alias should accept any lowercase letter, numbers and the underscore. You should definitely open an issue if it does not: