[SOLVED]Gas Reed Sensor GPIO Raspberry Pi

Hello everyone in the forum,

I have a Raspberry Pi 4 with an SSD hard drive and the HA Image 9.0 (Home Assistant 2022.10.4 Supervisor 2022.10.0 Operating System 9.2 Frontend 20221010.0 - latest) I have also set up SSH access, Terminal, File Editor, HACS and Studio Code Server.
I set up the USB IR reading head (IR Schreib/Lesekopf USB (Optokopf)-ART0027) for my electricity meter (Iskra MT681).
That works well. Now I would like to include my gas meter. With daily, weekly, monthly and annual consumption.
Via reed contact (Elster IN-Z62) on the gas meter and the GPIO on the Raspberry Pi 4.
How do I have to connect the reed contact? Against crowd? With resistance?

What do I have to enter in the configuration.yaml?

Found on the board here:

binary_sensor:
  - platform: rpi_gpio
    invert_logic: true
    ports:
      18: GAS METER

counters:
  gas counter:
    steps: 1

or this:

sensor 1:
  platform: template
  sensors:
    daily_gas_in_m3:
      unit_of_measurement: "mÂł"
      #state_class: total_increasing
      #device_class: gas
      value_template: "{{ (states('sensor.daily_gas') | float / 100) }}"

utility_meter:
  daily_gas:
    source: counter.gascounter
    cycle: daily

binary_sensor:
  - platform: rpi_gpio
    invert_logic: true
    ports:
      18: GAS METER

Who wants and can help me please?

I’m a total newbie to HA.

Greetings Martin

1 Like

Hello everyone,

I have a solution from an Austrian user. I have created a template folder. The folder must be linked. In the folder is a gas.yaml and a strom.yaml.
So I don’t need a WiFi connection to record the measured values.
CU-Martin

Hallo an Alle,

ich habe eine Lösung von einem Österreichischen User.Ich habe einen template Ordner angelegt.Der Ordner muß verlinkt werden.Im Ordner ist eine gas.yaml und eine strom.yaml.
So brauche ich keine WiFi Verbindung zur Erfassung der Messwerte.
CU-Martin




configuration.yaml

template: !include_dir_merge_named template

#USB-Sensor Weidmann--------------
sensor:
  - platform: edl21
    name: Stromzaehler
    serial_port: /dev/ttyUSB0
#Reedkontakt am Gaszaehler----------------
binary_sensor:
  - platform: rpi_gpio
    sensors:
      - port: 18
        name: "Gaszaehler"
        unique_id: "gaszaehler_pin"
        bouncetime: 80
        pull_mode: "DOWN"

gas.yaml

sensor:
  - unique_id: gasverbrauch_m3
    name: Gasverbrauch m3
    state: "{{ states ('counter.gaszahler') | float*0.01 }}"
    icon: mdi:fire
    unit_of_measurement: mÂł
    device_class: gas
    state_class: total_increasing

  - unique_id: gasverbrauch_kWh
    name: Gasverbrauch kWh
    state: "{{ states ('counter.gaszahler') | float*0.1 }}"
    icon: mdi:fire
    unit_of_measurement: kWh
    device_class: gas
    state_class: total_increasing

strom.yaml

- sensor:
    - name: Strombezug
      state: >
        {% set pwrin = states('sensor.stromzaehler_positive_active_energy_in_tariff_t1') | float %}
        {{ pwrin / 1000 | round(3) }}
      unit_of_measurement: kWh
      state_class: total_increasing
      device_class: energy
    #zusatz 27.09.2022
    - name: Nettobezug
      state: >
        {% set pwrin = states('sensor.stromzaehler_sum_active_instantaneous_power') | float %}
        {{ pwrin / 1000 | round(3) }}
      unit_of_measurement: kWh
      state_class: total_increasing
      device_class: energy

1 Like

Hallo,

bei mir steht der Sensor “Gasverbrauch m3” dauerhaft auf unavailable. Hab die Gas.yaml erstellt, verlinked und den Namen in der Zeile
state: “{{ states (‘counter.gaszahler’) | float*0.01 }}” auf counter.gaszaehler angepasst.

irgendwie passt die Syntax mit der Berechnung des Sensortemplates nicht :frowning:

Hat jemand eine Idee woran es liegen kann?

Thx Thomas