I want to log events to InfluxDB but entries are duplicated when HA restarts

I want to be able to keep track of certain events via a webhook with my phone. For example when I do some pull ups, I want to log them. It works really well, in theory, like this:

template:
  - trigger:
      - platform: webhook
        webhook_id: "randomwebhook17267321"
        local_only: false
    sensor:
      - name: "Pull ups"
        state: "{{ trigger.json.value }}"
        unit_of_measurement: "n"
        attributes:
          last_updated: "{{ now().isoformat() }}"

But there is a problem. Whenever I restart home assistant, the last value that was sent to this webhook gets repeated in InfluxDB, leading to duplicate entries and logged events that never happened. So for example I will get:

Time n
03/03/2025 10:44:22 7
03/03/2025 15:52:06 7 ← Restarted HA (not real pull ups)

This becomes a problem because I want to be able to do aggregate sum and max for each day, and those duplicated entries throw off the stats.

I think I’m probably starting off on the wrong foot by using a “sensor” to log data like this, and that the duplication of entries is a well known issue. So my question is

  1. Is there a workaround?
  2. Is there an alternative way I can do this? Maybe an integration that I have overlooked? I think I may end up writing to the InfluxDB directly.

Things I have already tried:

  1. input_number helper: doesn’t work because it ignores updates when the value is the same (e.g. if I did 3 pull ups and then later another 3 pullups, the second set wouldn’t be logged).
  2. counter helper: kind of works but because you can only increment it, you have to do extra work to group together entries that are part of the same set, making an assumption about the time window.

So I’ve decided to skip home assistant entirely for this. It doesn’t really need to go through HA at all, as I was only using it as an easy way to implement writing data to influx anyway. I have now exposed the influxdb through my cloudflare tunnel and I’m writing the data directly to the database with a POST request.

curl -i -XPOST "https://<domain>/write?db=homeassistant&u=<user>&p=<pass>" --data-binary 'n,entity_id=pull_ups value=6'

It’s a bit annoying sending the username and password in the request url but I’ve created a new user with write access just for this purpose. So I think the risk is fairly low. I’m aware the V2 has token access, which would be better I guess.