I have an integration (linky) that provide me electrical consumption of my home.
I get the data 2 days after. So the data I get today is about 2 days ago.
How can I simple use this information to build a new sensor with the value I get today but the date for (2 days ago) ?
A bit more complex:
Linky send me also attributes data of the last month daily consumtion (latest 31 days, but with a delta of 2 days). How to rebuild consistent data into HA ?
I don’t think there is a way to write a timestamp to an entity, I can’t find one in the docs antway and I assume you have also looked.
This is not ideal but you have 2 choices. (maybe more if someone can think of something clever)
My first thought was to toggle an input boolean ‘when’ you want the data to appear to be written and use that instead (the last changed value) The issue here is that you’d have a 0 value sensor for a couple of days until its populated.
My second thought was to create a sensor then use logic to display the last changed value with a - 2 day offset, this would always be applied and would always show correctly pecieved values as the data is always 2 days older than when it was posted.
Are you saying there are no attributes with the actual date of the data? Looking at the code, it seems like it’s getting an entire table from the linky website…so I would assume the attribute ‘time’ is the actual date of the reading.
If it doesn’t provide an attribute with the actual usage date, you can create a template sensor to fake that out.
sensor:
- platform: template
sensors:
power_consumption_delta:
friendly_name: "Power Consumption Update"
# Updates when linky_yesterday updates
value_template: "{{ state('sensor.linky_yesterday') }}"
attribute_templates:
# Convert now to 2 days ago (convert 2 days into seconds and subtract)
timestamp: "{{ ((as_timestamp(now()) | int) - 60*60*24*2) | timestamp_local }}"
# Grab the other attributes because why not
other_attribute: "{{ state_attr('sensor.linky_yesterday', 'other_attribute') }}"
another_attribute: "{{ state_attr('sensor.linky_yesterday', 'another_attribute') }}"
My guess is…you just want the history card to not have the wrong date. The history card is only going by updates. Even this template sensor will still be off by 2 days.
You could just switch to a graph that doesn’t show the date.
Now all you’ll see is your consumption charts in your favorite style without the date looking wrong.