Creating a Daily Click Counter in Home Assistant

Hey everyone, I’ve been diving into Home Assistant lately and decided to tackle a project that’s been on my mind: creating a daily click counter using my sensor.whatpulse_clicks_sensor. The goal is to track my daily clicks by subtracting the previous day’s total from the current one, store the total at midnight, and have it update dynamically without issues on restart. Let me walk you through my journey so far and where I’m stuck.

The Setup

I started by setting up an input_number helper to store the midnight value. Here’s the automation I created to update it every day at 00:00:

yaml

  • 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 the daily clicks:

yaml
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”

Challenges Faced

  1. Error Messages: I encountered a Message malformed: value should be a string for dictionary value error when saving the automations. It’s a bit confusing since the syntax seems correct.
  2. Math Operations on input_number: It appears Home Assistant doesn’t allow direct math operations on input_number entities within template sensors. I’m not sure if my code is off or if there’s a workaround.
  3. Template Sensors Unavailable: Even when things saved without errors, the template sensors showed as “unavailable” on my dashboard. This is frustrating because the setup seemed solid.

Seeking Solutions

I’ve seen suggestions to use template sensors instead of input_number, but converting didn’t solve the persistence issue across reboots. Has anyone successfully implemented a daily counter like this? Any insights or alternative approaches would be greatly appreciated!

Thanks in advance for your help! I’m really excited to crack this one and would love to share the solution once I get it working. :blush: