Using history stats

Hello everyone!

I thought I had read up properly on how to configure a few simple history-stats sensors, but unfortunately I’m not getting the right values.

I would be glad if someone with more “syntax-experience” could please have a quick look; maybe it is correct and the problem is somewhere else…

For information: The amount of rain is determined in a diy rain-gauge via a binary “rocker tilt sensor” (including a magnetic hall-sensor).

- platform: history_stats
  name: Rain in the last 2 days
  unique_id: sensor.rain_lasttwodays
  entity_id: binary_sensor.irrigator_regenmenge
  state: on
  type: count
  start: "{{ now() - timedelta(hours=48) }}"
  end: "{{ now() }}"  
  
- platform: history_stats
  name: Rain in the last 6 hours
  unique_id: sensor.rain_lastsixhours
  entity_id: binary_sensor.irrigator_regenmenge
  state: on
  type: count
  start: "{{ now() - timedelta(hours=6) }}"
  end: "{{ now() }}"

Many thanks in advance for your help!
:))

Braak

Not right how?

This is rain in the last 48 hours from now. Not the last two calendar days. Is that what you want instead?

The last six hours one looks ok.

Well I get no values at all …
;(

… even though the sensor reads out (counts) when it rains


That is a lot more descriptive than

Unfortunately I can’t read the language your graphs are in and have no idea what they are showing.

OK,

so first pic is a graph of the „6 hours sensor“ and second graph shows the actual value (calculated from the counts into mm/sqm).

As they show both the same time interval they both should show up values at least time shifted as the „6-hours-backwards“-sensor should show them later, no?

The history stats tests how often a binary sensor “regenmenge” is on. But from the graph it seems regenmenge is a sensor with a count, not a binary sensor (Which makes sense, menge is German for quantity). So unless you created a binary_sensor that goes on for rain and off for no rain, the history stats is indeed not doing anything.

For what I know it is a binary one:

binary_sensor.irrigator_regenmenge

Each time the hall sensor passed the magnet it turn on and immediately off again.

Can you show the history of that sensor (binary_sensor.irrigator_regenmenge) for the last 6 hours?

You mean the hall-sensor itself without the calculated one to mm/sqm?

I mean the binary sensor. The one you are using in your history stats.

That’s the logbook not the history graph.

The last rain was three days ago, and the example Tom gave was the last two days… So it works as intended.

I know, but a history graph shows nearly nothing as it is on only for a fraction of a second…

1 Like

I see.

Edwin has a point. The logbook entries are a lot older than 6 hours.

Okay but shouldn’t the history graph of that „older time period“ (see post above) not also show the same (time-shifted) values?

If you created the working sensor three days ago and showed it in a graph today, yes. But not if you just made it. It now shows from the last two days.

I know, but I have set it up two weeks ago and waited after the first rain (until now): shouldn’t it show up values then?

Change this:

state: on

To this:

state: "on"

For both your history stats sensors. on is different to "on".

on is a boolean (0/1)

"on" is a string.

States are always strings.