As I already noticed, the states will in future create a pointer on a certain state if this is already present in the database. Sounds logical. My question:
I have a lot of sql based sensors, will they work as before?
I use these sensors with a scan interval of 300. That reduces the db accesses and saves cpu use compared to the components.
Some examples:
- name: "average_cpu_use"
query: >
SELECT ROUND(avg(state),2) 'value'
FROM states
where entity_id = 'sensor.processor_use' and created >= datetime('now','-24 hours');
column: "value"
unit_of_measurement: "%"
- name: "weekly_total_rain"
query: >
SELECT ROUND(SUM(state),2) 'value'
FROM(
SELECT state, created
FROM(
SELECT state, created FROM states
WHERE entity_id = 'variable.last_rain_total_at_night'
order by created desc
)
GROUP BY strftime('%d:%m',created) order by created desc limit 7
);
column: "value"
unit_of_measurement: mm
- name: "weekly_avg_temperature"
query: >
SELECT ROUND(avg(state),2) 'value'
FROM states where entity_id = 'sensor.outside_temperature' and created >= datetime('now','-7 days');
column: "value"
unit_of_measurement: "°C"
- name: "daily_max_temperature"
query: >
SELECT MAX(ROUND(state,2)) 'value'
FROM states where entity_id = 'sensor.outside_temperature' and state not in('unknown','unavailable') and strftime('%Y-%m-%d',created) = date('now');
column: "value"
unit_of_measurement: "°C"