2026/01/06

도어센서를 이용한 누적 가스사용량 기록




교체된 계량기가 원격검침을 위한 리드센서 넣는 공간이 있어 거기에 도어센서를 넣어 가스사용량 카운트.
계량기에서 소수부가 3자리 있는데 2번째 자리가 바뀔 때 마크네틱에 의해 도어센서의 on신호가 발생하는데 그걸 이용해 카운터 센서에 기록하는 자동화를 구성.
그리고 템플릿 센서와 유틸리티 미터 센서를 이용해 일일사용량 기록.

마지막으로 에너지패널에 일일 가스사용량으로 만든 유틸리티 미터를 등록.



** 카운터 센서의 최초값은 계량기를 확인한 후 counter.set_value 서비스로 직접 입력해 넣으면 그 값에 누적해 기록됨. 보정이 필요할 때도 해당 명령을 이용해 카운터 값 변경.
** 카운터 센서는 정수기반이라 최초값 입력시 소숫점 마지막 자리는 버리고 두번째 자리까지 정수로 입력후 센서값에 0.01을 곱하는 템플릿센서를 만들어 유틸리티 미터의 소스로 등록.


configuration.yaml
counter: !include counter.yaml
automation: !include automations.yaml
template: !include template.yaml
utility_meter: !include utility_meter.yaml


counter.yaml
gas_pulse:
  name: gas pulse

automations.yaml
- id: 입력-Gas/Count
  alias: 입력-Gas/Count
  trigger:
    - platform: state
      entity_id: binary_sensor.gas_contact
      from: 'off'
      to: 'on'
  actions:
    - action: counter.increment
      target:
        entity_id: counter.gas_pulse

template.yaml
sensor:
  - name: "Gas Total"
    unique_id: gas_total
    state: "{{ states('counter.gas_pulse') | int(0) * 0.01 }}"
    unit_of_measurement: m³
    device_class: gas
    state_class: total_increasing

utility_meter.ymal
gas_daily:
  name: 가스사용량
  unique_id: 'gas_daily'
  source: sensor.gas_total
  cycle: daily