select state from statistics where metadata_id = (select id from statistics_meta where statistic_id = 'sensor.givtcp_sa2219g385_import_energy_total_kwh')
and time(created) >= '00:00:00' and time(created) <= '00:01:00' order by created desc limit 1
Now, it seems that the field “created” now only contains NULL.
I’m not a DB programmer or Home Assistant guru, so if anyone can point me in the right direction, I’d be most pleased.
Regards, Martin
SELECT state FROM statistics
WHERE metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = 'sensor.electricity')
AND time(created_ts, 'auto') >= '00:00:00' AND time(created_ts, 'auto') <= '00:01:00'
ORDER BY created_ts
DESC LIMIT 1
I’m looking for the first entry after midnight. But the >= AND <= seem a bit fragile.
Is there a better SQL command to do this?