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:
- Track daily clicks by subtracting the previous day’s total from the current total.
- Store the total clicks at midnight so that I can use it for calculations the next day.
- 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:
- “Message malformed: value should be a string for dictionary value” – When trying to save automations in the UI.
- Math on
input_number
not working – Home Assistant doesn’t seem to allow direct math operations oninput_number
helpers in template sensors – is this true? Maybe my code is wrong. - Tried converting
input_number
to a sensor, but then got"extra keys not allowed @ data['0']"
when saving the config. - 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!