I'm trying to determine an average temperature over one day, for home assistant. I have linked sensors to home assistant, which send data to phpmyadmin. I can't send the sensors separately via home assistant, but they are all listed in the folder status. See below.
By sending a sql code via home assistant, I can search values in the database. So now I'm trying to find the average of the last 100 measurements (+/- 1 day). To achieve this, I have written the following sql code.
SELECT AVG(`state`)
FROM states
WHERE state_id > (select state_id
FROM states
WHERE entity_id='sensor.weatherstation_ground_temperature'
AND state <> unknown
ORDER BY state_id DESC
OFFSET 0 ROWS FETCH FIRST 100 ROWS ONLY)
If I type this into phpmyadmin, I get the following error:
1064 - There is an error in the syntax used for 'OFFSET 0 ROWS FETCH FIRST 100 ROWS ONLY) LIMIT 0, 25' in line 1.
My question is: what am I doing wrong, or is there a better way?