Comments (3)
The drawback with this method is that you always need to unpack attributes
for every row and I am afraid this might make my dashboard sluggish in the feature so I wanted to put the hourly sensors into their own table so I could use an index when computing daily,weekly,monthly,yearly averages.
Create a new table eloverblik
:
CREATE TABLE eloverblik(
sensor varchar(100),
metering_date date,
value numeric,
insource_date timestamp without time zone,
PRIMARY KEY (metering_date, sensor)
);
Optional: Add the values you have saved so far:
with CTE as (
select *
,row_number() over (partition by entity_id, state, metering_date order by time desc) as rn
from (
select time,
entity_id,
cast(state as decimal)
,to_date(replace(cast(json_extract_path(attributes::json,'metering_date') as text),'"',''),'YYYY-MM-DD') as metering_date
from public.ltss
where entity_id like 'sensor.eloverblik_%'
) a
)
insert into eloverblik
select entity_id as sensor,
metering_date,
state as value,
time as insource_date
from cte where rn = 1 and entity_id != 'sensor.eloverblik_energy_total'
I am excludingtotal
because I don't want to mix the types of sensors (hourly/total) and because I can compute the daily total from the hourly sensors.
To automatically update eloverblik
create this function and trigger:
CREATE OR REPLACE FUNCTION eloverblik_insert()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS
$$
BEGIN
if NEW.entity_id like 'sensor.eloverblik_energy_%'
and NEW.entity_id <> 'sensor.eloverblik_energy_total'
THEN
INSERT INTO eloverblik(sensor, metering_date, value, insource_date)
VALUES(NEW.entity_id,to_date(replace(cast(json_extract_path(NEW.attributes::json,'metering_date') as text),'"',''),'YYYY-MM-DD'),cast(NEW.state as decimal),now())
ON CONFLICT (metering_date,sensor) DO UPDATE SET (value, insource_date) = (cast(NEW.state as decimal),now());
END IF;
RETURN NEW;
END;
$$
CREATE TRIGGER eloverblik_insert
AFTER INSERT
ON ltss
FOR EACH ROW
EXECUTE PROCEDURE eloverblik_insert();
Let me know if you'd rather have this in the wiki.
from homeassistant-eloverblik.
it should not be in the issue tracker. You are welcome to create a PR to include the information in some documentation.
from homeassistant-eloverblik.
Closing the issue as no PR have been received and this really do not belong in the issue tracker.
from homeassistant-eloverblik.
Related Issues (20)
- Long term statistics/Energy dashboard release HOT 2
- Blande realtime og Eloverblik historiske data HOT 1
- Feature request: Get CO2 data HOT 3
- Elspotpris.dk HOT 2
- Unsupported operand type(s) for -: 'datetime.datetime' and 'float' HOT 2
- Error from eloverblik when getting meter rading data: 404 - No readings found in result. HOT 3
- Opdatere ikke statistics efter jeg har sat integration op HOT 5
- Stadig sensorer med unknown status HOT 6
- Data 2 dage bagud? HOT 4
- Problemer med opdatering af data HOT 4
- Får ikke data (har vedhæftet log) HOT 2
- Stops working after a 2-3 days HOT 4
- Hvilket Målepunkt ID skal tilknyttes ? HOT 2
- Missing data HOT 5
- Displaying total energy cost in energy dashboard HOT 2
- Automatisk opdatering af data HOT 2
- Add support for multiple meters HOT 2
- Data for sensor.eloverblik_energy_statistic er forskudt med en dag. HOT 4
- Can't load statistic sensors HOT 6
- REFRESH TOKEN HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from homeassistant-eloverblik.