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
- Is there a workaround?
- 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:
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).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.