Creating a Daily Counter Readout from a Total Lifetime Counter Sensor

Hi everyone,

I’m trying to create a daily click counter in Home Assistant using my sensor.whatpulse_clicks_sensor, which tracks lifetime clicks. My goal is to:

  1. Track daily clicks by subtracting the previous day’s total from the current total.
  2. Store the total clicks at midnight so that I can use it for calculations the next day.
  3. Have the daily clicks update dynamically without breaking on restart.

Attempts So Far:

I first tried using an input_number helper (input_number.whatpulse_total_clicks_thru_yday) to store the midnight value and an automation to update it at midnight:

- alias: "Store WhatPulse Clicks at Midnight"
  id: store_whatpulse_clicks_midnight
  trigger:
    - platform: time
      at: "00:00:00"
  action:
    - service: input_number.set_value
      target:
        entity_id: input_number.whatpulse_total_clicks_thru_yday
      data:
        value: "{{ states('sensor.whatpulse_clicks_sensor') | int }}"
  mode: single

Then, I tried creating a template sensor to calculate daily clicks:

template:
  - sensor:
      - name: "WhatPulse Clicks Today"
        unique_id: whatpulse_clicks_today
        state: "{{ states('sensor.whatpulse_clicks_sensor') | int - states('input_number.whatpulse_total_clicks_thru_yday') | int }}"
        unit_of_measurement: "clicks"

Problems Encountered:

  1. “Message malformed: value should be a string for dictionary value” – When trying to save automations in the UI.
  2. Math on input_number not working – Home Assistant doesn’t seem to allow direct math operations on input_number helpers in template sensors – is this true? Maybe my code is wrong.
  3. Tried converting input_number to a sensor, but then got "extra keys not allowed @ data['0']" when saving the config.
  4. Even when it saves, the template sensors show as “unavailable” on my dashboard.

I’ve seen some solutions suggesting template sensors instead of input_number, but I can’t get things to persist across reboots.

Has anyone successfully created a daily counter like this? Any guidance would be appreciated!

Thanks in advance!

This is what a utility meter helper is for. In the UI, go to helpers and choose “utility meter”. Select your source sensor and choose “daily” as the meter cycle. There’s nothing else you have to do.

1 Like