Making an Accurate Rain Graph, Day, Month, Year (Netamo, SmartMixn and Others.)

I have had Home Assistant for a bit over two years now and there does not seem to be a way to make an accurate (Monthly) rain graph, from the data given from my Netamo Rain Sensor.

I have also found very few posts directly relating, to what you would think being a simple task to create a rain graph in Home Assistant. I may also be a Luddite.

I have put this post together to capture the code I have used for any other Newbies that need a template to start with but would also like any advice you can give to make my graphs more accurate. I have tried utility meters to no avail. The Monthly Data is what I really need help with.

The Netamo Rain Sensor reports the following sensors.

  • Rain Rate (mm/h)
  • Rain Per Hour (mm)
  • Rain Accumulated Per Day (mm) - Resets and Midnight
    9am prefered to align with the weatherman in Australia.

This is a snip of how those sensors look in history stats, during a rainfall event.

SmartMixn Phone and Web App
SmartMixin is an application that provides access to your weather station and 40K+ other stations worldwide. It helps you see and understand weather data.

I have all My Weather Station Data recorded there for over two years now, you can click on the link and see the data.

I have added the Web App as a Web Page Dashboard and gives me access to all my graphs and accurate data.

The Mobile App give you more access to historical comparisons, charts and exporting csv files of your data. I wish they had an open API so I could import that data straight into Home Assistant, or an Integration.

The below image shows 87.7mm for January.

APEX CHARTS Monthly Rain Fall Graph
I am using the Rain Per Hour Sensor. It is close but not quite right because of the uneven shift of data over the month. Using the long term statistics option in this card is key.
The below graph shows 82.3 for January, because of the shift in data, and being on the 12 June Currently (Last 30 days is not in line with the months)

          - type: custom:apexcharts-card
            graph_span: 365d
            header:
              show: true
              title: Monthly Rainfall
              show_states: false
            apex_config:
              fill:
                type: gradient
                gradient:
                  type: vertical
                  shadeIntensity: 0.0
                  opacityFrom: 1
                  opacityTo: 0.5
                  stops: 10
              chart:
                height: 150px
              grid:
                show: false
                borderColor: darkslateblue
                strokeDashArray: 2
              dataLabels:
                background:
                  borderWidth: 0
                  opacity: 0
                  foreColor: white
                offsetY: -10
              plotOptions:
                bar:
                  borderRadius: 0
                  dataLabels:
                    position: top
            span:
              start: month
              offset: '-334.5833333333333d'
            series:
              - entity: sensor.netatmo_devonport_tas_indoor_rain_rain_last_hour
                color: deepskyblue
                type: column
                group_by:
                  func: sum
                  duration: 30.41666666666667d
                  fill: zero
                statistics:
                  type: state
                  period: hour
                  align: end
                show:
                  name_in_header: false
                  datalabels: true

APEX CHARTS Daily Rain Fall Graph 30 Days
I am using the Rain Accumulated Per Day sensor. Using the MAX function and duration of 1d. when trying to use the same sensor in the above card it does not work properly. Using the long term statistics option in this card is key.
This one seems close to accurate

          - type: custom:apexcharts-card
            graph_span: 30d
            header:
              show: true
              title: Daily Rainfall
              show_states: false
            span:
              end: day
            apex_config:
              fill:
                type: gradient
                gradient:
                  type: vertical
                  shadeIntensity: 0.0
                  opacityFrom: 1
                  opacityTo: 0.5
                  stops: 10
              chart:
                height: 150px
              grid:
                show: false
                borderColor: darkslateblue
                strokeDashArray: 2
              dataLabels:
                background:
                  borderWidth: 0
                  opacity: 0
                  foreColor: white
                offsetY: -10
              plotOptions:
                bar:
                  borderRadius: 0
                  dataLabels:
                    position: top
            series:
              - entity: sensor.netatmo_devonport_tas_indoor_rain_rain_today
                color: deepskyblue
                type: column
                group_by:
                  func: max
                  duration: 1d
                statistics:
                  type: state
                show:
                  name_in_header: false
                  datalabels: true

MINI GRAPH CARD Last 7 Days Rain
I am using a template, statistics sensor to Accumulate the last 7 Days (10080mins) of Data.
This one seems close to accurate and drives my sprinkler system
image

Sensor:

# Rain Last 7 Days
-platform: template
 sensors:
  - platform: statistics
    name: "Rain last 7 days"
    unique_id: afe4b9f2-d0a6-4c42-86eb-786737f2ea14
    entity_id: sensor.netatmo_devonport_tas_indoor_rain_rain_today
    state_characteristic: sum_differences_nonnegative
    max_age:
      minutes: 10080
    precision: 1
    keep_last_sample: true

Card:

  - type: custom:mini-graph-card
    entities:
      - entity: sensor.rain_last_7_days
        color: lightblue
    name: Rain Last 7 Days
    group_by: date
    show:
      graph: bar
      extrema: false
    hours_to_show: 168
    points_per_hour: 1
    cache: true
    animate: true
    aggregate_func: last

MINI GRAPH CARD Rain Last 24Hrs
Directly reads the Rain Per Hour sensor and gives a good appreciation of the rain fallen in the last 24hrs.
This one seems accurate
image

type: custom:mini-graph-card
entities:
  - entity: sensor.netatmo_devonport_tas_indoor_rain_rain_last_hour
    color: lightblue
name: Rain Last 24hrs
group_by: hour
show:
  graph: bar
  extrema: false
hours_to_show: 24
points_per_hour: 1
cache: true
animate: true
agregate_func: last

RAIN GAUGE CARD Rain Last 24Hrs
Directly reads the Rain Accumulated Per Day sensor and gives a good appreciation of the rain fallen in the last 24hrs.
This one seems accurate

- type: custom:rain-gauge-card
  entity: sensor.netatmo_devonport_tas_indoor_rain_rain_today
  hourly_rate_entity: sensor.netatmo_devonport_tas_indoor_rain_rain_last_hour
  name: Daily Rain
  show_warning: false
  show_error: false

Any advice you can give to make my graphs more accurate would be much appreciated.

UPDATE
I managed to fix the accuracy issues in the APEX CHARTS Rainfall Graphs. They now mirror my data stored on SmartMixn, from the same weather sensors.

APEX CHARTS Monthly Rain Fall Graph (12 Months)

Some Important settings

# For the "Rain This Month" (VISIBLE IN CHART)(Using the Rain Accumulated Per Day sensor)
graph_span: 12month # 12 month graph span
span:
  end: month # Span ends at the end of the month
group_by:
  func: sum # Sum
  duration: 1month # 1 Month Data
  fill: zero
statistics: # Grabs Long Term Statistics
  type: state
  period: day # Grabs 1 day at a time
  align: start
  show:
    name_in_header: true # shows name in header
    datalabels: true # makes data labels visible above bars
    in_chart: true # makes bars visible in chart
    legend_value: false # hides from legend
    extremas: false # hides extremas

# For the "Rain Last 12 Months" (ONLY VISIBLE IN HEADER)(Using the Rain Accumulated Per Day sensor)
  group_by:
    func: sum # Sum
    duration: 12month # 12 month duration
    fill: zero
  statistics: # Long Term Statistics
    type: state
    period: day
    align: end
  show:
    name_in_header: true # Show only Total in Header
    datalabels: false # Do not show data labels above graph
    in_chart: false # Do not show bars in graph
    legend_value: false # Do not show in legend

COMPLETE CODE FOR MONTHLY RAINFALL (12 MONTHS) GRAPH

          - type: custom:apexcharts-card
            graph_span: 12month
            span:
              end: month
              offset: '-0d'
            header:
              show: true
              show_states: true
            apex_config:
              fill:
                type: gradient
                gradient:
                  type: vertical
                  shadeIntensity: 0
                  opacityFrom: 1
                  opacityTo: 0.5
                  stops: 10
              chart:
                height: 150px
              grid:
                show: false
                borderColor: darkslateblue
                strokeDashArray: 2
              dataLabels:
                background:
                  borderWidth: 0
                  opacity: 0
                  foreColor: white
                offsetY: -10
              plotOptions:
                bar:
                  borderRadius: 0
                  dataLabels:
                    position: top
            series:
              - entity: sensor.netatmo_devonport_tas_indoor_rain_rain_today
                name: Rain This Month
                color: deepskyblue
                type: column
                group_by:
                  func: sum
                  duration: 1month
                  fill: zero
                statistics:
                  type: state
                  period: day
                  align: start
                show:
                  name_in_header: true
                  datalabels: true
                  in_chart: true
                  legend_value: false
                  extremas: false
              - entity: sensor.netatmo_devonport_tas_indoor_rain_rain_today
                name: Rain Last 12 Months
                color: deepskyblue
                type: column
                group_by:
                  func: sum
                  duration: 12month
                  fill: zero
                statistics:
                  type: state
                  period: day
                  align: end
                show:
                  name_in_header: true
                  datalabels: false
                  in_chart: false
                  legend_value: false

APEX CHARTS Daily Rain Fall Graph (30 Days)

Some Important Settings:

# For the "Rain Today" (VISIBLE IN CHART)(Using the Rain Accumulated Per Day sensor)
graph_span: 30d # 30 days graph span
span:
  end: day # Span ends at the end of the day
group_by:
  func: max # Max
  duration: 1d # 1 Day Data
  fill: zero
statistics: # Grabs Long Term Statistics
  type: state
  period: day # Grabs 1 day at a time
  align: end
  show:
    name_in_header: true # shows name in header
    datalabels: true # makes data labels visible above bars
    in_chart: true # makes bars visible in chart
    legend_value: false # hides from legend
    extremas: false # hides extremas

# For the "Rain Last 30 Days" (ONLY VISIBLE IN HEADER)(Using the Rain Accumulated Per Day sensor)
  group_by:
    func: sum # Sum
    duration: 30d # 30 days duration
    fill: zero
  statistics: # Long Term Statistics
    type: state
    period: day
    align: end # align at end
  show:
    name_in_header: true # Show only Total in Header
    datalabels: false # Do not show data labels above graph
    in_chart: false # Do not show bars in graph
    legend_value: false # Do not show in legend

COMPLETE CODE FOR DAILY RAINFALL (30 DAYS) GRAPH

          - type: custom:apexcharts-card
            graph_span: 30d
            span:
              end: day
            header:
              show: true
              show_states: true
            apex_config:
              fill:
                type: gradient
                gradient:
                  type: vertical
                  shadeIntensity: 0
                  opacityFrom: 1
                  opacityTo: 0.5
                  stops: 10
              chart:
                height: 150px
              grid:
                show: false
                borderColor: darkslateblue
                strokeDashArray: 2
              dataLabels:
                background:
                  borderWidth: 0
                  opacity: 0
                  foreColor: white
                offsetY: -10
              plotOptions:
                bar:
                  borderRadius: 0
                  dataLabels:
                    position: top
            series:
              - entity: sensor.netatmo_devonport_tas_indoor_rain_rain_today
                name: Rain Today
                color: deepskyblue
                type: column
                group_by:
                  func: max
                  duration: 1d
                  fill: zero
                statistics:
                  type: state
                  period: day
                  align: end
                show:
                  name_in_header: true
                  datalabels: true
                  in_chart: true
                  legend_value: false
                  extremas: false
              - entity: sensor.netatmo_devonport_tas_indoor_rain_rain_today
                name: Rain Last 30 Days
                color: deepskyblue
                type: column
                group_by:
                  func: sum
                  duration: 30d
                  fill: zero
                statistics:
                  type: state
                  period: day
                  align: end
                show:
                  name_in_header: true
                  datalabels: false
                  in_chart: false
                  legend_value: false

APEX CHARTS Hourly Rain Fall Graph (24 Hours)


Some Important Settings:

# For the "Rain Now" (VISIBLE IN CHART)(Using the Rain Per Hour sensor)
graph_span: 24h # 24 hour graph span
span:
  end: hour # Span ends at the end of the hour
group_by:
  func: raw # Raw data
  duration: 1d # 1 Day Data
  fill: zero
statistics: # Grabs Long Term Statistics
  type: state
  period: hour # Grabs 1 hour at a time
  align: end
  show:
    name_in_header: true # shows name in header
    datalabels: true # makes data labels visible above bars
    in_chart: true # makes bars visible in chart
    legend_value: false # hides from legend
    extremas: false # hides extremas

# For the "Rain Today" (ONLY VISIBLE IN HEADER)(Using the Rain per Hour Sensor sensor)
  group_by:
    func: sum # Sum
    duration: 24h # 24 Hours duration
    fill: zero
  statistics: # Long Term Statistics
    type: state
    period: hour # Grabs 1 hour at a time
    align: end # align at end
  show:
    name_in_header: true # Show only Total in Header
    datalabels: false # Do not show data labels above graph
    in_chart: false # Do not show bars in graph
    legend_value: false # Do not show in legend

COMPLETE HOURLY RAINFALL (24 HOURS) GRAPH

      - type: vertical-stack
        cards:
          - type: custom:apexcharts-card
            graph_span: 24h
            span:
              end: hour
            header:
              show: true
              show_states: true
            apex_config:
              fill:
                type: gradient
                gradient:
                  type: vertical
                  shadeIntensity: 0
                  opacityFrom: 1
                  opacityTo: 0.5
                  stops: 10
              chart:
                height: 150px
              grid:
                show: false
                borderColor: darkslateblue
                strokeDashArray: 2
              dataLabels:
                background:
                  borderWidth: 0
                  opacity: 0
                  foreColor: white
                offsetY: -10
              plotOptions:
                bar:
                  borderRadius: 0
                  dataLabels:
                    position: top
            series:
              - entity: sensor.netatmo_devonport_tas_indoor_rain_rain_last_hour
                name: Rain Last Hour
                color: deepskyblue
                type: column
                group_by:
                  func: raw
                  duration: 1d
                  fill: zero
                statistics:
                  type: state
                  period: hour
                  align: end
                show:
                  name_in_header: true
                  datalabels: true
                  in_chart: true
                  legend_value: false
                  extremas: false
              - entity: sensor.netatmo_devonport_tas_indoor_rain_rain_last_hour
                name: Rain Last 24 Hours
                color: deepskyblue
                type: column
                group_by:
                  func: sum
                  duration: 24h
                  fill: zero
                statistics:
                  type: state
                  period: hour
                  align: end
                show:
                  name_in_header: true
                  datalabels: false
                  in_chart: false
                  legend_value: false