Water consumption meter: how to restore values?

Hello everyone,

I have a water pulse meter that sends 1 pulse for every liter. I’m attempting to integrate it into Home Assistant with a simple goal - to store the total consumed liters. I went through several examples and ended up with the code below, which has an issue: after restarting, my consumption shows a value of 1,073,741,824 liters. I’m completely lost and have no idea what I might be doing wrong. Any suggestions would be greatly appreciated.

This is my yaml:

esphome:
  .....
  on_boot:
    - pulse_meter.set_total_pulses:
        id: counter_hot
        value: !lambda "return id(total_hot_count);"

globals:
  - id: total_hot_count
    type: int
    restore_value: yes
    initial_value: '0'

....

api:
....
  services:
    - service: set_total_hot
      variables:
        new_total_hot: int
      then:
        - pulse_meter.set_total_pulses:
            id: counter_hot
            value: !lambda 'return new_total_hot;'
...
  - platform: pulse_meter
    id: "counter_hot"
    pin: 36
    internal_filter: 500ms
    unit_of_measurement: "liter/min"
    name: 'Hot water consumption'
    filters:
      - multiply: 0.5
    total:
      unit_of_measurement: 'liter'
      name: 'Total hot water'
      filters:
        - lambda: |-
            id(total_hot_count) += id(counter_hot).raw_state;
            return x/2;
  ...

I’d start with adding some logging when total_hot_count changes - to see values received and stored.