MateoGreil / homeassistant-comwatt

Comwatt Integration for HomeAssistant
17 stars 3 forks source link

Make site data available #28

Closed yann-disanto closed 2 months ago

yann-disanto commented 3 months ago

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 commented 3 months ago

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 commented 2 months ago

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!