Average temperature during the specific date interval

Would you be so kind to help me how I can find average temperature for the specific time period?

I have the interval: <Input.datetime_startdate1 - Input.datetime_stopdate2>

I have temperature info: „sensor. temperature“

I do need info AVG(sensor. Temperature) period: <Input.datetime_startdate1 - Input.datetime_startdate2>

Thank you very much.

Best,

Robert

2 Likes

My first thought was the statistics sensor, but this only gives you the average for the previous number of minutes, and I think you might want something more specific.

Thank you for the link, however, I do know this very well. My problem could not be solved by this.

If I set the statistic sensor as:

  • platform: statistics
    name: temperature_statistics
    entity_id: sensor.pocasie_temperature
    max_age:
    hours: 10

everything works.
But I need to define the interval max_age: Input.datetime_startdate1 - Input.datetime_startdate2.

Perhaps this is the one you want:

Hello,
Did you find your correct syntax ?because I’m in the same situation as you.

Sorry, no help just yet, but this is something that my var integration should handle easily once I figure out how to hook the HA database.

@robo and @weado, did you ever find a solution? If you haven’t and you’re willing to install a custom component, I can show you how to do it with my variable component.

Yes :

  - platform: sql
    scan_interval: 600
    queries:
      - name: Mean
        query: SELECT AVG (state) as state FROM states WHERE entity_id = 'sensor.temp' AND last_updated > datetime('now','start of day');
        column: 'state'
        unit_of_measurement: '°C'
        value_template: "{{ ' %0.1f' % value }}"

If you find how can I select the record 1 day before, I take it… (I would like to have a an sensor with my record from yesterday at the same to compare the two values)

1 Like