New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Linky sensor #20535
New Linky sensor #20535
Conversation
I will update the documentation once this is considered ok. |
Until that times comes, I'm adding the |
I was wanting to actually redo this even better to use it with the utility metter. Can someone tell me if it would be bad if I access the database from here ? I need to add a lot of lines in it… |
self._peak_hours_cost = peak_hours_cost | ||
self._offpeak_hours_cost = offpeak_hours_cost | ||
self._unit = KILOWATT_HOUR | ||
self._icon = "mdi:flash" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this a constant
password = config[CONF_PASSWORD] | ||
timeout = config[CONF_TIMEOUT] | ||
"""Set up the Linky sensor.""" | ||
username = config.get(CONF_USERNAME) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use [] syntax for required and optional with default keys.
self._state = None | ||
self._attributes = {} | ||
self.update() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call this outside the init()
_LOGGER.debug("Start of update of linky data") | ||
self._lk.update() | ||
if not self._lk.success: | ||
self._state = STATE_UNAVAILABLE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set this to None
. Instead add another instance variable named _available
to the sensor and expose it with the property available. Don't forget to mark available = True
when the update is successful.
@property
def available(self):
"""Return the availablility of this sensor."""
return self._available
self._username = username | ||
self._password = password | ||
self._timeout = timeout | ||
self.client = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not create the client here? Regardless it should not be {}
but rather None
if it doesn't exist.
Please don't forget to run |
else: | ||
self._attributes["monthly_evolution"] = ( | ||
1 - ((self._lk.monthly[0][CONSUMPTION]) / | ||
(self._lk.compare_month))) * 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is small error in the formula. It should be:
self._attributes["monthly_evolution"] = (
self._lk.monthly[0][CONSUMPTION] / self._lk.compare_month - 1
) * 100
@grea09 Are you still working on this? It will need to be rebased and updated to match the latest architectural changes. |
self._peak_hours = peak_hours | ||
self._peak_hours_cost = peak_hours_cost | ||
self._offpeak_hours_cost = offpeak_hours_cost | ||
self._unit = KILOWATT_HOUR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use homeassistant.const.ENERGY_KILO_WATT_HOUR
else d[CONSUMPTION] | ||
for d in self._lk.halfhourly]) / 2 | ||
# From kW for 30 minutes to kWh | ||
self._attributes["peak_offpeak_percent"] = ((self._attributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some users share on the forum to have divison by Zero here. Perhaps add some protections.
I am planning to get 5 students starting on this at the end of the week. I will make sure they share their progress. |
Also I want to get an architectural change in HA core to extend access to history from components. This would impact the recorder and will probably take a lot of discussions to get accepted. |
I've created a simple PR to add more Linky sensors : #23726 I think you can take a look at it and add your work at the |
I was more wanting to have the sensor compatible with the utility metter. The issue is that there is no such thing as "today" with Enedis. You can have the consumption of the previous day around 8 o clock in France. So all the history is incorrect. I don't think adding more sensors will help that but it can help making the data clearer. I am personally more convinced to have a "realtime" consumption based on hopefully future API by Enedis or by Bayessian inference in the meantime. Also I would prefer to actually populate the history of the sensor like if it was counting the consumption all along (hence the core change). I think it would be interesting to think this through. I will make sure my students get in touch with you once they start the work on this. |
Hi @grea09 ! Indeed, hours are yesterday's hours and today isn't updated at all, haven't seen that the first time. So I removed it from my PR #23726. I agree that realtime API would be nice, but you are talking about High-Tech in France men ... always two step behind 😉
As I am new in Python and HA dev, I don't know what are you talking about the utility metter 😬 sorry.
As I understand well, making some kind of sum of every day consomption ?
If you want too, feel free to contact me. |
And as Enedis update Linky's data every day at 8AM, why not update the component only around that time ? |
They are VERY unreliable. They get something like 50% downtime. They unofficially also have maintenance downtime durring the night. But yes it can be done to update once every halfhour around that time and stop for the day once it got a response. |
return | ||
|
||
self._state = self._lk.daily[1][CONSUMPTION] | ||
self._attributes["halfhourly"] = [d[CONSUMPTION] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't do these calculations as part of the integration, instead it should be made a standalone integration, like the previous mentioned utility meter.
Home Assistant integrations should only represent the data from the source as-is. Things like summing up or calculating costs etc should happen in integrations that consume these raw-data-representing-integrations. This PR is conflating concerns and so should not be merged. |
Description:
I have coded a new sensor with more informations in attributes and possibly a behaviour change. The code has been done from the original custom component from @Pirionfr. I also fixed a bug in the implementation of the python library used for retrieving data.
This is done to be able to eventually create a lovelace card for energy consumption.
An example of what it could be like: (from @Imbuzi)
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>
Example entry for
configuration.yaml
(if applicable):Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices: