Influxdb query MAX since start of day

Hello everybody,

I’m looking for to find the good query to get the temperature max from the start of day to now.

I found the good request for the last hour or last 2 days, but I didn’t find for the start of day. This my request, and I’m looking to change the “1h” in other thing and not for example 2015-08-17T23:48:00Z because I should change every day, and I really don’t want :slight_smile:

- platform: influxdb
      - name: Temp max
        unit_of_measurement: "°C"
        group_function: max
        where: '"entity_id" = ''temperature'' and time > now() - 1h'
        measurement: '"°C"'


I’m using this :

- name: max jardin
  unit_of_measurement: °C
  measurement: '"°C"'
  group_function: max
  where: '"entity_id" = ''netatmo_jardin_temperature'' AND time >= {{(as_timestamp(now()) - (now().hour * 3600) - (now().minute * 60) - (now().second)) | round(0)}}s'
  field: value
  database: hassio

This is mix of influxdb query and templating :slight_smile:

Works pretty good, except at really start of day (from 0h00 to 0h05) where there’s no value because the value is not changing so often.

Great ! Thank you !

After your answer, I looked for to the same thing with use the sensor, with the date, and use it in my request like that :

It’s work well in the “template” page, but no in the InfluxDB request. ( That avoid to calcul for each time) and I believe crazy :thinking::grimacing:

Adding another way of calculating the start of a day, week, or year. Using the same code as above, but altering the template in the where clause:

where: >-
  "entity_id" = 'outside_temperature' AND time >= {{as_timestamp(now().year ~ '-01') | round(0)}}s
##week (starting on monday)
where: >-
  "entity_id" = 'outside_temperature' AND time >= {{(as_timestamp(today_at("00:00")) - now().weekday() * 86400) | round(0)}}s
where: >-
  "entity_id" = 'outside_temperature' AND time >= {{as_timestamp(today_at("00:00")) | round(0)}}s

I found these to be a bit more readable and certainly shorter.