I used the CLI of Influx to figure out the query, Influx is a bit different from the SQL databases I have used before.
Start the Influx CLI by typing
influx in a terminal window, then select the correct database: use
show databases followed by
use database_name (that’s
use homeassistant if you haven’t specified your own database name in the
influx component declaration).
show measurements to see available measurement series, in my case “°C”, and then
show series to see available entities (in my case
All this combines to a query, in my case:
SELECT median(values) FROM "°C" WHERE entity_id='temperature_outdoor' AND time > now()-24h
This query calculates a median value of all the temperature measurements from my outdoor thermometer recorded the last 24h and returns a single float value.
NB! The single quotes around temperature_outdoor in the query are very important, without them there will be no answer! You’ll have to escape them in the sensor declaration using more quotes, check the docs.
Check https://home-assistant.io/components/sensor.influxdb/ on how to declare the
influxdb sensor component and https://docs.influxdata.com/influxdb/v1.4/query_language/functions/ for all available mathematical functions. You can find details on how to explore your database here: https://docs.influxdata.com/influxdb/v1.4/query_language/schema_exploration/
I can paste my own sensor declaration later tonight, I don’t have it in front of me right now.