Skip to content
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

Including energy consumption in update_info() #74

Closed
allardhs opened this issue Dec 15, 2019 · 1 comment
Closed

Including energy consumption in update_info() #74

allardhs opened this issue Dec 15, 2019 · 1 comment

Comments

@allardhs
Copy link

For user like me without access to real-time electricity consumption data, it's still useful to access the consumption data that the API provides out of the box. In turn, this will allow the Home Assistant sensor to be able to query and use these values.

Therefore I would suggest including the following lines after line #297 in __init__.py in the update_info() function. Sorry, I'm not good with git otherwise I'd do a pull request.

         consumption(resolution: DAILY, last: 1) {
           nodes {
             from
             to
             consumption
             consumptionUnit
             unitPrice
             unitPriceVAT
             cost
             totalCost
             currency
           }
         }

Unfortunately, data are only provided only up till yesterday -- limited by Tibber. And even then, it's still not the most elegant solution, as ideally it would only need to query this once per day not every update cycle. But it does work fine at least for me and it's better than nothing...

The sensor.py in your Home Assistant Tibber component can then have the following lines added at the end of the async_update() function to display these values in the attributes.

This is probably not at all useful for people who do have real-time data. I can't judge that, but in that case you may wish to start this block with a condition if not home.has_real_time_consumption:

   try:
       await self._tibber_home.update_info()
   except (asyncio.TimeoutError, aiohttp.ClientError):
       return
   data = self._tibber_home.info["viewer"]["home"]
   self._device_state_attributes["grid_company"] = data["meteringPointData"]["gridCompany"]
   self._device_state_attributes["grid_company_production"] = data["meteringPointData"]["estimatedAnnualConsumption"]
   daily_consumption_data = data["consumption"]["nodes"][0]
   self._device_state_attributes["consumption_yesterday_" + str(daily_consumption_data["consumptionUnit"])] = daily_consumption_data["consumption"]
   self._device_state_attributes["consumption_yesterday_" + str(daily_consumption_data["currency"])] = round( daily_consumption_data["consumption"] * ( daily_consumption_data["unitPrice"] + daily_consumption_data["unitPriceVAT"]), 3 )

image

@Danielhiversen
Copy link
Owner

Thanks for your suggestion, but I am not planning to add that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants