Code Monkey home page Code Monkey logo

ha-checkwatt's Introduction

Home Assistant CheckWatt Custom Integration

This integration uses cloud polling from the CheckWatt EnergyInbalance portal using a reverse engineered private API.

The strategy for this integration is to reduce the amount of sensors published while at the same time maximize the information available and provide them as attributes.

The integration also aims to balance the user needs for information with loads on CheckWatts servers why some data may not always be up-to date.

Out-of-the box, this integration provides two sensors:

  • CheckWatt Daily Net Income : Your estimated net income today
  • CheckWatt Annual Net Income : Your estimated annual net income
  • Battery State of Charge: Your batterys state of charge

The Daily Net Income sensor also have an attribute that provides information about tomorrows estimated Net Income.

checkwatt main

Known Issues and Limitations

  1. The integration uses undocumented API's used by the EnergyInBalance portal. These can change at any time and render this integration useless without any prior notice.
  2. The monetary information from EnergyInBalance is always provisional and can change before you receive your invoice from CheckWatt.
  3. The annual yeild sensor includes today's and tomorrow's estimated net income.
  4. CheckWatt EnergyInBalance does not (always) provide Grid In/Out information. Why it is recommended to use other data sources for your Energy Panel.
  5. The FCR-D state and status is pulled from a logbook parameter within the API and is a very fragile piece of information. Use with care.
  6. The integration will update the Energy sensors once per minute, the Daily Net Income sensor once every fifteenth minute and the Annual Net Income around 2 am every morning. This to not put too much stress on the CheckWatt servers (the net income operation is slow resource heavy)

Installation

HACS installation

Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

Git installation

  1. Make sure you have git installed on your machine.
  2. Navigate to you home assistant configuration folder.
  3. Create a custom_components folder of it does not exist, navigate down into it after creation.
  4. Execute the following command: git clone https://github.com/faanskit/ha-checkwatt.git checkwatt
  5. Restart Home-Assistant.

Enable the integration

Go to Settings / Devices & Services / Integrations. Click + ADD INTEGRATION

Find CheckWatt from the list of available brands:

checkwatt config step 1

Enter your EnergyInBalance credentials and press SUBMIT:

Take note that Home Assistant will store your credentials and if this is a security concern for you, abort at this stage.

checkwatt config step 2

The integration will now install and assuming it all went well you will get a success message and the possibility to add its sensors to an area of your choice.

checkwatt config step 3

On your Overview you will now have two new sensors in a new group:

checkwatt config done

These sensors will show you your estimated daily and annual net income alongside with some basic attributes like Street Address, Zip Code and City.

The Daily Net Income sensor will also show tomorrows estimated net income as an attribute.

checkwatt basic daily checkwatt basic annual

Configuration

The integration provides basic sensors for most peoples needs. The integration can also be a one-stop-shop for the Home Assistant Energy panel and can therefore be configured to also fetch all required data for that from EnergyInBalance.

For those who need additional information, detailed attributes can be provided by configuring the integration accordingly. Through the detailed sensors you can get gross revenue, fees, fee rates, FCR-D status and much more.

If you need more sensor and more detailed attributes in the sensors, configure the integration as follows.

Go to Settings / Devices & Services / CheckWatt. Click CONFIGURE:

checkwatt options step 1

Select if you want the integration to provide energy sensors and if detailed attributes shall be provided.

Press SUBMIT and the configurations will be stored:

checkwatt options step 2

After the configuration is done you need to restart the integration. Click ... and select Reload checkwatt options step 3

After the system as reload you will have 1 device and 9 sensors available. checkwatt options done

Your sensors will now also contain a lot of detailed attributes. checkwatt detailed daily checkwatt detailed annual

Setting up Energy Panel

With the energy sensors provided by the integration, it is possible to configure the Home Assistant Energy Panel. The Energy panel is available on the left-hand menu of Home Assistant by default.

When you enter the energy panel the first time you will be guided by a Wizard:

checkwatt energy step 1

For the Grid Consumption, select the Import Energy sensor from the integration and complement it with the cost tracker using the Spot Price VAT sensors.

Take note that you should use the sensor that includes VAT for Electricity that you purchase. Please also note that this sensor does not include markups from your electricity provider.

checkwatt energy step 2

For Grid Consumption, select the Export Energy sensor from the integration and complement it with the cost tracker using the Spot Price sensors.

Take note that you should use the sensor that excludes VAT for Electricity that you sell.

checkwatt energy step 3

When configured, it looks like this. Press SAVE + NEXT to continue the Wizard.

checkwatt energy step 4

Add the Solar Energy sensor from the integration and press SAVE + NEXT

checkwatt energy step 5

Add the Battery Energy sensors from the integration. Energy going in to the battery = Battery Charging Energy Sensor Energy going out of the battery = Battery Discharging Energy Sensor

Press SAVE + NEXT

checkwatt energy step 6

Finish off the Wizard and the result will look like this. Please be advised that it will take a few hours before the Energy Panels start showing data.

Also, currently EnergyInBalance does not always provide proper Grid Input and Output why this data cannot be relied upon.

For now, you need to pull that data from another integration.

checkwatt energy done

Final result

When the system is fully set-up it you have sensors that provides you with your daily and annual net income and if you have configured it accordingly, you also have sensors available for the Home Assistant Energy Dashboard.

The final result can look like this:

checkwatt main

Events

The integration publish events which can be be used to drive automations.

Below is a sample of an automation that acts when CheckWatt fails to engage your battery and deactivates it.

alias: Deactivated
description: ""
trigger:
  - platform: state
    entity_id:
      - event.skarfva_fcr_d_state
    attribute: event_type
    from: fcrd_activated
    to: fcrd_deactivated
condition: []
action:
  - service: notify.faanskit
    data:
      message: "CheckWatt failed, please investigate."
mode: single

Expert Section

If you think that some of the attributes provided should be sensors, please consider to use Templates before you register it as an issue. If it can be done via a Template Sensor, it will most likely be rejected.

Use templates

This is an example of a Template based Sensor that pulls tomorrows estimated daily net income from the attribute of the CheckWatt Daily Net Income sensor.

It goes without saying, but this should be put in your configuration.yaml:

template:
  - sensor:
      - name: "CheckWatt Tomorrow Net Income"
        unique_id: checkwatt_tomorrow_yield
        state: "{{ state_attr('sensor.skarfva_checkwatt_daily_yield', 'tomorrow_gross_income')}}"
        unit_of_measurement: "SEK"
        device_class: "monetary"
        state_class: total

The result will look something like this:

template based sensor

Use developer tools

The names of the attributes can be found in the Home Assistant Developer Tools section in your Home Assistant environment under the STATES sheet:

home assistant developer tools

Acknowledgements

This integration was loosely based on the ha-esolar integration. It was developed by @faanskit with support from:

This integration could not have been made without the excellent work done by the Home Assistant team.

If you like what have been done here and want to help I would recommend that you firstly look into supporting Home Assistant.

You can do this by purchasing some swag from their store or paying for a Nabu Casa subscription. None of this could happen without them.

Licenses

The integration is provided as-is without any warranties and published under The MIT License.

ha-checkwatt's People

Contributors

angoyd avatar faanskit avatar flopp999 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ha-checkwatt's Issues

Sensors

I don’t know if it’s an issue or not but I can’t see live flow from grid, solar etc, just seeing total over time. It would be great to see production right now

Discrepancy of local daily net income and EiB Daily revenue

I noticed that there is a discrepancy the local daily net income sensor and EiB portal Daily revenue. In my current case the local sensor state 15.41 and the EiB Daily revenue states 17.31. Is that to be expected with the APIs being used? Am I missing something or perhaps looking at the wrong thing? The local sensor is being updated continuously as far as I can see.

Fails to load integration

integration stopped working, and I’m guessing it might be related to today’s update of Core.

Logger: custom_components.checkwatt
Source: helpers/update_coordinator.py:300
Integration: CheckWatt (documentation, issues)
First occurred: 18:06:32 (74 occurrences)
Last logged: 19:00:48

Unexpected error fetching checkwatt data: 'CheckwattManager' object has no attribute 'fcrd_percentage'

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 300, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/checkwatt/__init__.py", line 225, in _async_update_data
    "fcr_d_state": cw_inst.fcrd_percentage,
                   ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'CheckwattManager' object has no attribute 'fcrd_percentage'

UI install not working

I am unable to install using 1) HACS link or 2) copy repository url into custom repositories in HACS UI. Only method working is manual cloning.

  1. returns “ Repository faanskit/ha-checkwatt not found”
  2. returns “ Repository 'faanskit/ha-checkwatt' exists in the store.” yet it is nowhere to be found, despite reboot etc.

On HAoS, odroid blue. All up to date.

Mimer-SVK integration works by method 2, for instance.

v0.2.0 Sometimes corrupts configuration

An upgrade to v0.2.0 can sometimes make the configuration of CheckWatt integration corrupt.
The only known way to fix this is to uninstall and install again.

As long as you have not changed language settings, the data from previous installation should be intact.

Uninstall like this:
image

The install it again.

Sorry for the inconvenience. The root-cause is likely attributed to the removal of old configuration attributes while at the same time adding new. Home Assistant seems not to be resilient to this.

Error in log

2023-12-28 20:27:49.636 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.guldet_battery_soc (<class 'custom_components.checkwatt.sensor.CheckwattBatterySoCSensor'>) is using state class 'total' which is impossible considering device class ('battery') it is using; expected None or one of 'measurement'

sensor name can be confusing

sensor.[DisplayName]_spot_price_vat

sensor.[DisplayName]_spot_price_incl_vat

the name used today can be interpreted as ONLY the VAT for the spot price

Lost network, or failed login leads to component crash

Sample log from crash

2023-12-28 19:58:12.727 ERROR (MainThread) [pycheckwatt] An error occurred during the request. URL: https://services.cnet.se/checkwattapi/v2/user/LoginEiB?audience=eib, Headers: {'accept': 'application/json, text/plain, */*', 'accept-language': 'sv-SE,sv;q=0.9,en-SE;q=0.8,en;q=0.7,en-US;q=0.6', 'content-type': 'application/json', 'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Windows"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'cross-site', 'wslog-os': '', 'wslog-platform': 'controlpanel', 'authorization': 'Basic bWFyY3VzLmthcmxzc29uQHVzYS5uZXQ6TGlsbGt1azEw'}. Error: Cannot connect to host services.cnet.se:443 ssl:default [Name or service not known]
2023-12-28 19:58:12.729 ERROR (MainThread) [custom_components.checkwatt] Authentication failed while fetching checkwatt data: 
  File "/workspaces/core/homeassistant/data_entry_flow.py", line 395, in _async_handle_step
    self._raise_if_step_does_not_exist(flow, step_id)
  File "/workspaces/core/homeassistant/data_entry_flow.py", line 443, in _raise_if_step_does_not_exist
    raise UnknownStep(
homeassistant.data_entry_flow.UnknownStep: Handler ConfigEntriesFlowManager doesn't support step reauth

Failed to authorize

The integration can not login to energyinbalance.

Message is "Failed to authorize" and in the log it says:

This error originated from a custom integration.

Logger: pycheckwatt
Source: custom_components/checkwatt/config_flow.py:42
integration: CheckWatt (documentation, issues)
First occurred: 21:03:26 (1 occurrences)
Last logged: 21:04:19

CheckWatt has requested to back down by enabling the kill-switch

I have even tryed to reset the password to one without special signs.

Add sensor for annual income

This sensor only be updated during startup and once daily and contain the following attributes as the regular sensor.

Street Address:
Zip Code:
City:
Annual Gross Income:
Annual Fees:
Annual Fee Rate:

Custom component not found in add integration screen

Hello,
I am using a homeassistant green and have git cloned the repository under the config folder in a custom_components folder and I can see all the data using the terminal however when going to the add integration popup Checkwatt is not found. I have tried restarting the homeassistant and hard refreshing and using a new browser so should not be a cookies issue atleast.

Sensor shows revenue, does not consider fees.

The current checkwatt sensor only pulls the revenue endpoint.
To match what ends in your pocket and shows in EIB, fees needs to be deducted.

In pyCheckwatt, pull the /fee's endpoint and detract that from the /revenue endpoint.

Make Annual Sensor Optional

The Annual Sensor is resource intense and delays the start of HA almost a minute.
Make it configurable to have it enabled or not. Default off.

(a) A new option in config
(b) Only perform ge_revenueannual if configured.
(c) Only create sensor if configured

Add battery test sensor?

As I believe you are already parsing the logs for the FCR-D state, would it be possible to also parse for the latest battery test run add a sensor with the result? Having that value, seeing it over time, and also give the possibility for automations/alerts in HA could be beneficial for multiple reasons.

Division by zero

Logger: custom_components.checkwatt
Källa: helpers/update_coordinator.py:318
integration: CheckWatt (dokumentation, ärenden)
Inträffade först: 28 mars 2024 kl. 23:11:35 (37 händelser)
Senast loggade: 08:48:31

Unexpected error fetching checkwatt data: float division by zero
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 318, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/checkwatt/init.py", line 388, in _async_update_data
if not await cw_inst.get_fcrd_month_net_revenue():
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pycheckwatt/init.py", line 393, in get_fcrd_month_net_revenue
self.dailyaverage = self.revenuemonth / int(dayswithmoney)
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
ZeroDivisionError: float division by zero

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.