syssi / esphome-smg-ii

ESPHome configuration to monitor and control a ISolar/EASUN SMG II inverter via RS232
Apache License 2.0
58 stars 9 forks source link

utility meter gas sensor #19

Closed amgstone closed 1 year ago

amgstone commented 1 year ago

I'm sorry that this is off topic, I'm trying to configure the gas meter, can you tell me if I configured the utility meter correctly?

syssi commented 1 year ago

Could you provide some details about your gas meter? How many pulses does the device send per m³?

amgstone commented 1 year ago

IMG-37beab1198708fed02ee9e98945a899d-V

syssi commented 1 year ago

https://www.samgas.com.ua/lichylnyk-gazu-membrannyy-samgaz-g25-rs2001-2 https://www.samgas.com.ua/sites/default/files/_samgaz_re_red_0_6_3_10-12-2018_14.pdf

I've trouble to translate the PDF document. Could you read the document and tell me the page which is about the low frequency pulses?

syssi commented 1 year ago

On the last reel after the comma is fixed permanent magnet for working with a low-frequency pulse generator. The design of the counting device has a plastic case in which the counting mechanism itself is assembled with the display display drums (Fig. 10):

amgstone commented 1 year ago

IMG_20230301_115533_208 IMG_20230301_115533_339

syssi commented 1 year ago
globals:
  - id: total_pulses
    type: int
    restore_value: true
    initial_value: '7470502'

esphome:
  name: gas
  friendly_name: gaz

esp8266:
  board: esp01_1m
  restore_from_flash: true

preferences:
  flash_write_interval: 10min

api:
  encryption:
    key: !secret api_encryption_key

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: !secret ap_wifi_ssid
    password: !secret ap_wifi_password

captive_portal:

binary_sensor:
  - platform: gpio
    id: reed
    pin:
      number: GPIO2
    name: "Reed contact closed"
    filters:
      - delayed_on: 20ms
    on_press:
      then:
        - lambda: id(total_pulses) += 1;
        - output.turn_off: led
    on_release:
      then:
        - output.turn_on: led

sensor:
  - platform: template
    name: "Gas Cubic meters used"
    device_class: gas
    unit_of_measurement: "m³"
    state_class: "total_increasing"
    icon: "mdi:fire"
    accuracy_decimals: 2
    lambda: |-
      return id(total_pulses) * 0.001;

output:
  - platform: gpio
    pin: GPIO0
    id: 'led'

Please give it a try. If you attach a LED to your setup it will be turned on on every pulse.

amgstone commented 1 year ago

I install yaml, everything is ok, but as soon as I insert the reader into the gas meter, esp becomes offline. 16776790712965149045181613314363

amgstone commented 1 year ago

when the sensor is inserted into the gas meter, esp does not want to install yaml

amgstone commented 1 year ago

http://joxi.ru/l2ZYZB5Iz9wGlm

amgstone commented 1 year ago

after unplugging and turning on the power, esp starts counting from the beginning, does not remember the last value

syssi commented 1 year ago

I will have to build the setup on my own this evening to get an idea what's going on here.

syssi commented 1 year ago
globals:
  - id: total_pulses
    type: int
    restore_value: true
    initial_value: '7470502'

esphome:
  name: gas
  friendly_name: gaz

esp8266:
  board: d1_mini
  restore_from_flash: true

preferences:
  flash_write_interval: 10min

api:
  encryption:
    key: !secret api_encryption_key

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: !secret ap_wifi_ssid
    password: !secret ap_wifi_password

captive_portal:

binary_sensor:
  - platform: gpio
    id: reed
    pin:
      number: GPIO5
    name: "Reed contact closed"
    filters:
      - delayed_on: 20ms
    on_press:
      then:
        - lambda: id(total_pulses) += 1;
        - output.turn_off: led
    on_release:
      then:
        - output.turn_on: led

sensor:
  - platform: template
    name: "Gas Cubic meters used"
    device_class: gas
    unit_of_measurement: "m³"
    state_class: "total_increasing"
    icon: "mdi:fire"
    accuracy_decimals: 2
    lambda: |-
      return id(total_pulses) * 0.001;

output:
  - platform: gpio
    pin: GPIO2
    id: 'led'

Please attach the red wire to GPIO5 / D1 and try again. :-)

syssi commented 1 year ago

I've tested the setup. It's working and the total pulses are stored every 10 minutes to the flash/rtc:

preferences:
  flash_write_interval: 10min

Does the LED of the wemos blink once on every round of the gas meter?

amgstone commented 1 year ago

with d1 does not respond

syssi commented 1 year ago

Could you try to describe the issue in detail? You could write the summary in your mother language if you like.

amgstone commented 1 year ago

when it was connected to d4, everything worked, but when I connected the sensor to the esp meter, it did not start. When I connected it to d1, the sensor did not work, did not react to the magnet.

syssi commented 1 year ago

You have to use a pull-up (a resistor between D1 and 3.3V).

amgstone commented 1 year ago

and how should it be connected according to the scheme? I have resistors.

syssi commented 1 year ago

I will paint the schematics later the day!

syssi commented 1 year ago

I've enabled the internet pull-up of the ESP. Please try this updated YAML:

globals:
  - id: total_pulses
    type: int
    restore_value: true
    initial_value: '7470502'

esphome:
  name: gas
  friendly_name: gaz

esp8266:
  board: d1_mini
  restore_from_flash: true

preferences:
  flash_write_interval: 10min

api:
  encryption:
    key: !secret api_encryption_key

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: !secret ap_wifi_ssid
    password: !secret ap_wifi_password

captive_portal:

binary_sensor:
  - platform: gpio
    id: reed
    pin:
      number: GPIO5
      mode: INPUT_PULLUP
    name: "Reed contact closed"
    filters:
      - delayed_on: 20ms
    on_press:
      then:
        - lambda: id(total_pulses) += 1;
        - output.turn_off: led
    on_release:
      then:
        - output.turn_on: led

sensor:
  - platform: template
    name: "Gas Cubic meters used"
    device_class: gas
    unit_of_measurement: "m³"
    state_class: "total_increasing"
    icon: "mdi:fire"
    accuracy_decimals: 2
    lambda: |-
      return id(total_pulses) * 0.001;

output:
  - platform: gpio
    pin: GPIO2
    id: 'led'
amgstone commented 1 year ago

work perfectly

amgstone commented 1 year ago

http://joxi.ru/gmvVao0sqYL5bm when I change the value to the current one and flash esp, nothing changes in HA, in the sensor: sensor.gas_gas_cubic_meters_used and add utility meter to yaml

syssi commented 1 year ago

I assume this multiplicator is wrong:

    lambda: |-
      return id(total_pulses) * 0.001;

Could you check how many times the reed contact is closed while the last digit of the gas meter is spinning? I assume it's closed once per round. So the multiplicator should be:

    lambda: |-
      return id(total_pulses) * 0.01;
syssi commented 1 year ago

The initial_value is written once to the RTC/ESP. I don't know how to override this initial value without changing the name of the variable.

amgstone commented 1 year ago

http://joxi.ru/Q2KqbERuLD4NKr then when i changed the value to 0.01

syssi commented 1 year ago

You could add a button entity to the YAML to initialize the total_pulses varable with a new value (0) on button press:

button:
  - platform: template
    name: "Set value"
    on_press:
      - lambda: id(total_pulses) = 0;

The new value is written to the flash/RTC after 10 minutes:

preferences:
  flash_write_interval: 10min
amgstone commented 1 year ago

initial values ​​can be changed in HA utility meter. But you need to add it to yaml.

syssi commented 1 year ago

Did you see the YAML above how to set the initial value of total_pulses using a temporary added button entity?

amgstone commented 1 year ago

http://joxi.ru/82Q4bdkuwejP0m work))))

syssi commented 1 year ago

Cool! Please compare the value of the gas meter with the value of the ESPHome node in a few days to verify the multiplication is correct and the ESPHome increments the counter just as fast as the gas meter.

amgstone commented 1 year ago

and the utility meter does not need to be added for statistics?

syssi commented 1 year ago

No. It's useless in my opinion and shouldn't be added to the YAML.

syssi commented 1 year ago

The Gas Cubic meters used sensor should be sufficient.

amgstone commented 1 year ago

Screenshot_2023-03-11-15-43-31-456_io homeassistant companion android for some reason, some impulses are present when there is no gas consumption Screenshot_2023-03-11-15-41-12-885_io homeassistant companion android

syssi commented 1 year ago

How long is the cable between the ESP and the reed contact?

amgstone commented 1 year ago

2 meters, original length

syssi commented 1 year ago

The enabled internal resistor isn't probably enough and you could increase the debounce time.

amgstone commented 1 year ago
syssi commented 1 year ago

Please try 150ms. If you miss pulses decrease the value step by step.