Not able to use statistics on custom sensor

I’ve a sensor which is getting a currency-exchange by using a rest-api:

- resource: "https://www.quandl.com/api/v3/datasets/BOE/XUDLSKD?column_index=1&rows=1&api_key=abc123"
  sensor:
    - name: Dollarkurs
      unit_of_measurement: "SEK/USD"
      unique_id: sek_usd_kurs_lbma
      value_template: "{{ value_json.dataset.data[0][1] }}"

I’m able to get the value properly. But when I want to use the statistics sensor to display the maximum value the last 30 days, it says that it’s not supported for this sensor. Is it possible to have statistics for custom sensor?

You need to set the state_class to measurement

That should not be required.

Can you take a screenshot of the sensor state in Developer Tools → States ?

Yes, this is how it looks like:

When you click on the entity to get the more info pop up does it show a line graph or a strip chart?

Also can you post the exact error wording?

Yes, I can see a graph:

The exact error message:

Invalid config for [sensor.statistics]: The configured characteristic 'max' is not supported for the configured source sensor. Got OrderedDict([('platform', 'statistics'), ('name', 'Högst dollarkurs senaste 30 dagarna'), ('entity_id', 'sensor.dollarkurs'), ('state_characteristic', 'max'), ('max_age', OrderedDict([('days', 10)])), ('unique_id', 'max_dollarkus')]). (See ?, line ?). 

This is how I configure the statistics:

- platform: statistics
  name: "Högst dollarkurs senaste 30 dagarna"
  entity_id: sensor.dollarkurs
  state_characteristic: max
  max_age:
    days: 30
  unique_id: "max_dollarkus"
  

state_characteristic: value_max

See: https://www.home-assistant.io/integrations/statistics/#numeric-source-sensor

1 Like

I did read the documentation but I guess I was in a hurry when reading the exact parameter name. I saw “mean” and assumed “max”. Thanks!