How to calculate daily total number of steps

I have a sensor which contains the current number of steps in a session. This sensor produces something like the following:

I.e. this sensor is an increasing value until a walk stops. At that point it is reset to zero.

I would like to create a sensor derived from walking pad steps that would produce a history_stat that is the sum of all the steps in that day: 4151+3284+902=8337.

It seems what I need is a way to calculate the local maxima values for the current day. Does anyone know how to achieve something like this?

You could try the total or total_increasing state classes.

Using total_increasing should give you a value that increases forever corresponding to your total steps (see explanation here). Perhaps not that helpful.

Using total would give you a value that increases throughout the day (I think?), as long as you can also set last_reset to be the start of each day (see explanation here).

Not that I’ve tried either for this type of use case, but that’s where I’d start.

1 Like

This worked! Thanks for the quick answer!

I’m trying to do the exact same. Adding up the local maxima to get a “Daily Steps” counter. But neither state_class: total nor state_class: total_increasing work for me. Both reset to zero every time the step counter drops to zero.

@Mobius7 How exactly did you solve this? Could you post your yaml?

Solved it myself by using an SQL sensor.

Under Integrations add the “SQL” Integration, then use the following settings:
Column: total_steps
Query:

SELECT
      SUM(B.state) +
      (
      SELECT A.state
      FROM
              states as A
              INNER JOIN states_meta as A_meta
              ON A.metadata_id = A_meta.metadata_id
      WHERE
              A_meta.entity_id = 'sensor.walkingpad_4'
      ORDER BY A.state_id DESC
      LIMIT 1
      ) AS total_steps
FROM
      states as A
      INNER JOIN states_meta as A_meta
      ON A.metadata_id = A_meta.metadata_id,
      states as B
      INNER JOIN states_meta as B_meta
      ON B.metadata_id = B_meta.metadata_id,
      states as C
      INNER JOIN states_meta as C_meta
      ON C.metadata_id = C_meta.metadata_id
WHERE
      A_meta.entity_id = 'sensor.walkingpad_4'
      AND A.old_state_id = B.state_id
      AND B.old_state_id = C.state_id
      AND CAST(A.state AS INTEGER) < CAST(B.state AS INTEGER)
      AND CAST(C.state AS INTEGER) < CAST(B.state AS INTEGER)
      AND strftime('%Y-%m-%d', B.last_updated_ts, 'unixepoch', 'localtime') = strftime('%Y-%m-%d', 'now', 'localtime')
ORDER BY B.state_id DESC

Replace sensor.walkingpad_4 with the name of your step sensor (in both places).