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

Make site data available #28

Open
yann-disanto opened this issue Jul 11, 2024 · 3 comments
Open

Make site data available #28

yann-disanto opened this issue Jul 11, 2024 · 3 comments

Comments

@yann-disanto
Copy link

Is your feature request related to a problem? Please describe.
I like very much the auto production rate gauge displayed on the comwatt site homepage and I would like to be able to have the same in home-assistant.

Describe the solution you'd like
To compute the rate, looking at the website requests, it retrieves the site data using site-networks-ts for the last 6 minutes (start=now-6minutes, end=now). Then it uses the productions and consumptions measures to compute the rate (basically it does sum(productions)/sum(consumptions))

So I played a bit with your comwatt client and could compute the same value as displayed on the website with:

site_data = client.get_site_networks_ts_time_ago(siteId)
# Using only the 3 first measures (last 6 minutes)
production = sum(site_data['productions'][:3])
consumption = sum(site_data['consumptions'][:3])
auto_production_rate = production / consumption
print(f'Auto production rate: {auto_production_rate * 100:.0f}%')

I not familiar with the home-assistant integrations api but maybe this Comwatt integration could setup some kind of "site device" for each user site with sensors for each provided data (productions, consumptions, injections, withdrawals, etc). Not sure if it should also provide the computed value or if it should be computed by users in their home-assistant. I'm willing to help and contribute with some guidance 😃.

@MateoGreil
Copy link
Owner

Hello,

Don't you think you could find the same with the actual sensors ?

With something like that :

{% set grid_power_drawn = states('sensor.echange_reseau_soutirage_power')|float %}
{% set grid_power_injected = states('sensor.echange_reseau_injection_power')|float %}
{% set solar_power_production = states('sensor.solaire_en_autoproduction_power')|float %}

{% set total_consumption = grid_power_drawn + (solar_power_production - grid_power_injected) %}

{% if total_consumption == 0 %}
  100.00
{% else %}
  {{ ((solar_power_production / total_consumption) * 100) | round(2) }}
{% endif %}

But if you really want those values, we can add it ;)

@yann-disanto
Copy link
Author

The sensors names are differents for me (sensor.echange_reseau_soutirage_injection_soutirage_power, sensor.echange_reseau_soutirage_injection_injection_power, sensor.solaire_en_autoproduction_power) but it does the trick 😃 , thanks a lot!

@MateoGreil
Copy link
Owner

Finalement je viens de penser : on pourrait le query directement depuis leur serveur, avec la meme query qui affiche :
400758361-9925b080-4ff8-4d99-9308-1afc80afd65c
Histoire d'avoir vraiment les meme données.
Je crois que c'est cette query :

curl 'https://energy.comwatt.com/api/aggregations/site-time-series?id=3349&measureKind=FLOW&aggregationLevel=NONE&start=2025-01-07T13%3A05%3A08%2B01%3A00&end=2025-01-07T13%3A11%3A08%2B01%3A00'

@MateoGreil MateoGreil reopened this Jan 7, 2025
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