# 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
WHERE
ORDER BY A.state_id DESC
LIMIT 1
) AS total_steps
FROM
states as A
INNER JOIN states_meta as A_meta
states as B
INNER JOIN states_meta as B_meta
states as C
INNER JOIN states_meta as C_meta
Replace `sensor.walkingpad_4` with the name of your step sensor (in both places).