Git Product home page Git Product logo

energyscore's People

Contributors

kamaradclimber avatar knudsvik avatar misa1515 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

energyscore's Issues

Support energy sensors that resets at midnight

Since version 0.4.0 the score adds up constantly. It shows a value higher than 100%. This did not happen before this version.

Screenshot_1

The attributes show this:

state_class: measurement
energy_entity: sensor.zonneplan_p1_electricity_consumption_today
price_entity: sensor.zonneplan_current_electricity_tariff
quality: 1
total_energy:
2022-12-28T12:00:00+0100: 8.65
2022-12-28T13:00:00+0100: 9.1
2022-12-28T14:00:00+0100: 9.68
2022-12-28T15:00:00+0100: 10.2
2022-12-28T16:00:00+0100: 10.81
2022-12-28T17:00:00+0100: 11.52
2022-12-28T18:00:00+0100: 12.34
2022-12-28T19:00:00+0100: 13.08
2022-12-28T20:00:00+0100: 13.68
2022-12-28T21:00:00+0100: 14.12
2022-12-28T22:00:00+0100: 14.54
2022-12-28T23:00:00+0100: 14.95
2022-12-29T00:00:00+0100: 0.38
2022-12-29T01:00:00+0100: 0.8
2022-12-29T02:00:00+0100: 0.96
2022-12-29T03:00:00+0100: 1.63
2022-12-29T04:00:00+0100: 2.03
2022-12-29T05:00:00+0100: 2.45
2022-12-29T06:00:00+0100: 3.04
2022-12-29T07:00:00+0100: 3.47
2022-12-29T08:00:00+0100: 3.89
2022-12-29T09:00:00+0100: 4.54
2022-12-29T10:00:00+0100: 5.02
2022-12-29T11:00:00+0100: 5.34
price:
2022-12-28T12:00:00+0100: 0.21
2022-12-28T13:00:00+0100: 0.19
2022-12-28T14:00:00+0100: 0.16
2022-12-28T15:00:00+0100: 0.19
2022-12-28T16:00:00+0100: 0.2
2022-12-28T17:00:00+0100: 0.21
2022-12-28T18:00:00+0100: 0.21
2022-12-28T19:00:00+0100: 0.18
2022-12-28T20:00:00+0100: 0.18
2022-12-28T21:00:00+0100: 0.15
2022-12-28T22:00:00+0100: 0.12
2022-12-28T23:00:00+0100: 0.1
2022-12-29T00:00:00+0100: 0.08
2022-12-29T01:00:00+0100: 0.08
2022-12-29T02:00:00+0100: 0.07
2022-12-29T03:00:00+0100: 0.07
2022-12-29T04:00:00+0100: 0.07
2022-12-29T05:00:00+0100: 0.08
2022-12-29T06:00:00+0100: 0.08
2022-12-29T07:00:00+0100: 0.08
2022-12-29T08:00:00+0100: 0.12
2022-12-29T09:00:00+0100: 0.18
2022-12-29T10:00:00+0100: 0.2
2022-12-29T11:00:00+0100: 0.19
last_updated: '2022-12-29T11:59:46.345340+01:00'
unit_of_measurement: '%'
icon: mdi:speedometer
friendly_name: Total Energy Score

Minimum time

A dishwasher that runs for 90 minutes cannot score 100% even when run in the chespest hour. Could be 100% if run during the two cheapest hours.?

  • Add in YAML data schema
  • Add functionality
  • Add configFlow
  • Add tests
  • Update read-me for explaining configuration

Test: restoring

Probably have to mock an entity with attributes first to have something to restore.

  • version with dicts and datetimes that has to be processed
  • version with UNKNOWN/UNAVAILABLE state
  • version without mocking something first?

Better handling of time

Dicts should maybe have clock hours like "17-18" instead of "17". See how nordpool does this with full date time objects. This may need to be broken down into an even smaller item (just replace with datetime). Using datetime objects should also fix elif self.attr[ENERGY_YESTERDAY] is not None: to check if it actually is from yesterday.. no need to use the value if it's a week old. Be aware that the times are in UTC in database, need to verify local.

Icon

Having a default and optional icon defined in the config. The default is already in place in .const, but has not been implemented.

Data update frequency

Updating should be close to the whole hours, e.g. every minute between 13:58 and 14:02. Alternatively push updates when a new value of energy or price is available, see some info here.

Coverage

Get coverage report and badge

verify last hour on energy state

Introduced new potential bug with Nordpool: when processing new data, energy last hour is just added from the hour before. How to verify that it is still in sync with the state?

Sensor name

Sensor name is now name, should be named after yaml config.

AttributeError: 'NoneType' object has no attribute 'platform'

Version of the custom_component

0.3.1

Configuration

 - platform: energyscore
    name: House Energy Score
    unique_id: a6e5f61a-0761-478a-8520-87612e0c1ea5
    price_entity: sensor.electricity_cost
    energy_entity: sensor.home_energy_meter_gen5_electric_consumed_kwh

Describe the bug

Sensor initialization is throwing an error at https://github.com/knudsvik/EnergyScore/blob/master/custom_components/energyscore/sensor.py#L114-L116. I assume it happens because the price_entity is not setup yet when the sensor is built.

I've confirmed this hypothesis by simply removing the line (the integration is then working as expected).

I would suggest to delay this piece of code to later (async_added_to_hass or later in process_new_data since there is no way to know the order of entity bootstrap as far as I know).

Debug log

2022-12-22 18:29:13.546 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up energyscore platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/energyscore/sensor.py", line 63, in async_setup_platform
    async_add_entities([EnergyScore(hass, config)], update_before_add=False)
  File "/config/custom_components/energyscore/sensor.py", line 116, in __init__
    if entity_reg.async_get(self._price_entity).platform == "nordpool":
AttributeError: 'NoneType' object has no attribute 'platform'

Name could be optional

Define a sensor name based on the entity_id if the name is not provided. PowerCalc does this.

Service to purge data

Create a service to purge attribute data like price and energy, to clean poor data.

First hour energy

Energy in the first hour of the day does not seem to be recorded in the attributes. Leading to wrong score and wrong quality

QC input of correct device_class

Check that the input entities are of device_class energy and currency? See https://www.home-assistant.io/integrations/sensor/

UI:

  • Can only choose energy entities that is proper energy entities (total) and of correct type (energy)
  • Can only choose price entities

YAML:

  • Choosing wrong device class raises an a warning or similar in the log and cancels setup
  • Test

** EnergyScore sensors **

  • Cost and potential are MONETARY, see link

Potential savings

Potential savings in local currency if the energy use was moved to the cheapest hour.. or cheapest hours rather.

potential also needs actual price, so maybe that is a third sensor

  • Setup automatically adds new saving sensor from config entry to same device
  • Setup automatically adds new cost sensor from config entry to same device
  • Setup yaml automatically adds new saving sensor
  • Setup yaml automatically adds new cost sensor
  • Calculate cost for current day
  • Calculate potential savings for the current day or the last x hours
  • Saving and cost sensors have quality indicators
  • Restore
  • Readme

Tests:

  • Cost sensor is added from yaml
  • Potential sensor is added from yaml
  • Both sensors are added from config entry
  • All three sensors belong to same device
  • Quality for both new sensors
  • Currency of both new sensors are the same as price sensor, see this link
  • Handle energy with different UoM on price than energy
  • Restoring state of cost
  • Cost cycles resetting at midnight
  • Cost sensor update correctly
  • Cost sensor functions with resetting totals
  • Cost sensor exceptions
  • Sensors restore differently another day or same day
  • Restoring state of potential cost
  • Potential sensor update correctly
  • Potential sensor resetting at midnight
  • Potential sensor functions with resetting totals
  • Potential sensor exceptions
  • Restoring UoM on cost and potential
  • Restoring UoM if changed entity with different uom? (yaml)
  • Cost should not be restored if not for same day

Improve config flow handling of unique id

There are two async methods to set and check unique id in a config flow step, but if implemented as-is it will be over written by the class instantiation. See here for docs.

Necessary if an options flow is to be created, e.g. changing the entities (will change the unique ID per now) or future options.

  • Add functionality
  • Add tests to check abort string

Visualisation

Create a custom visualisation, eg. based on apexchart. Could have energyscore, energy, quality, sensitivity. Code and picture to be included in repo.

Example from user in Home Assistant Norge facebook thread:
image

`type: custom:apexcharts-card
apex_config:
legend: false
chart:
height: 240px
show:
loading: false
experimental:
color_threshold: true
header:
show: true
show_states: true
colorize_states: false
chart_type: radialBar
series:

  • entity: sensor.electricity_price_adresse
    name: Timespris, strøm
    max: 1
    show:
    in_chart: true
    header_color_threshold: true
    color_threshold:
    • value: 0
      color: green
    • value: 50
      color: orange
    • value: 70
      color: orangered
    • value: 90
      color: red
  • entity: sensor.ps_cap_hour_estimate
    name: Timesestimat
    show:
    in_chart: true
    header_color_threshold: true
    max: 10
    color_threshold:
    • value: 0
      color: green
    • value: 50
      color: orange
    • value: 75
      color: orangered
    • value: 90
      color: red
  • entity: sensor.total_energy_score
    name: Energyscore
    show:
    in_chart: true
    header_color_threshold: true
    color_threshold:
    • value: 0
      color: red
    • value: 45
      color: orange
    • value: 55
      color: green`

MIT license

Is there a need to update the MIT license?

Sensor unavailable

Sensor unavailability should be showed with which of them is unavailable. Currently it does not report to the logger which of them.

Refactoring dicts

Refactor dicts:

  • Should only need one dict to hold energy and price?
  • Do not really need a dict for energy_total?
  • Prices should be saved to dict even when there is no energy data in dict. Needs to handle uneven lengths of price and energy
  • The dicts could be stored in an attribute, that way it can be restored.

Tests

Config

  • Basic config is working
  • Config with and without unique_id
  • config with something else than entities
  • Config without name
  • energy_entity not being total_increasing
  • #49

Process new data

  • give dummy energy and price data in float and string, assert it returns the correct int
  • give dummy data with different date, assert blank sheet
  • assert max yesterday when date is yesterday
  • if not enough data yet, assert logger debug message
  • assert arrays and normalized arrays
  • assert self score

Restore data

  • Strings can be used to create number values (also in dicts)

Update

  • state is unavailable throws right exception
  • state is unknown throws right exception

Some info on testing here: https://developers.home-assistant.io/docs/development_testing/
Custom component tutorial has some intro on testing.

Time to analyze over

An EV charger should maybe look for best timing over a week, not just the intra-day

  • Add in YAML data schema
  • Add functionality
  • Add configFlow
  • Limit to 2-168 hours? (one hour does not make sense)
  • Test default is 24 hours in yaml without configuring
  • Test functionality for rolling hours of 1, 2, 3, 24 (not needed since default), 72, 168?
  • Test outside limits
  • Update read-me for explaining configuration
  • Update readme with limits

Data from nordpool sensor's attribute?

Could get data from NordPool sensors attribute for the whole day, but does it matter if the integration can remember states through restarts? It could help with being more correct throughout the day since it knows the price for the whole day in advance,.

Sensitivity

The sensitivity for energy-price current day could be an attribute. Needs to look at historic price-variations, either by saving them or looking at the long term statistics of the entity.

Treshold energy

Optional input: Treshold for energy use, e.g. for a dishwasher that uses a tiny bit of standby power.

  • Add in YAML data schema
  • Add functionality
  • Add configFlow
  • Add tests
  • Update read-me for explaining configuration

Part of the day to analyze on

Users may want to only run dishwasher between 07:00 and 22:00. Would make sense to be able to configure this and only normalise price for these hours.

  • Add in YAML data schema
  • Add functionality
  • Add configFlow
  • Add tests
  • Update read-me for explaining configuration

Score is reset every day at midnight

Version of the custom_component

0.3.2

Configuration

 - platform: energyscore
    name: House Energy Score
    unique_id: a6e5f61a-0761-478a-8520-87612e0c1ea5
    price_entity: sensor.electricity_cost
    energy_entity: sensor.home_energy_meter_gen5_electric_consumed_kw

Describe the bug

Score is reset to 100% everyday at midnight.
It means the only moment where score is precise is 1min before midnight.

image

I think the correct behavior would be to have a rolling score on the last 24h.

Algo improvement

When energy usage is 0, the dot-function is reducing the score (if energy same day in not cheapest hour). Usage = 0 should not be included in calc..

ConfigFlow

  • Add new sensor from UI
  • UUID generated automatically
  • Remove sensor from UI - info here.

Create log file

As the developer I want users to send me a log file with all relevant entries when they encounter issues.

ZeroDivisionError: float division by zero

Version of the custom_component

0.3.1

Configuration

 - platform: energyscore
    name: House Energy Score
    unique_id: a6e5f61a-0761-478a-8520-87612e0c1ea5
    price_entity: sensor.electricity_cost
    energy_entity: sensor.home_energy_meter_gen5_electric_consumed_kw

Describe the bug

Update of the entity fails with:

Traceback (most recent call last):
  File "/config/custom_components/energyscore/sensor.py", line 268, in async_update
    self._state = self.process_new_data()
  File "/config/custom_components/energyscore/sensor.py", line 233, in process_new_data
    _norm_prices = normalise_price(self.attr[PRICES])
  File "/config/custom_components/energyscore/sensor.py", line 73, in normalise_price
    return {
  File "/config/custom_components/energyscore/sensor.py", line 74, in <dictcomp>
    key: (max_value - value) / (max_value - min_value)
ZeroDivisionError: float division by zero

(line numbers are a bit shifted because I added some log lines to understand the issue).

The price dictionary contains 2 values with the same value (thus the division by zero).

It happens on a setup without nordpool sensor: it's a simple price sensor to follow peak/offpeak price.

UoM

Sensor UoM should be %, now it does not have anything.

sensor updates

Sensor updates from real entities provided in config. See line 126 here for an example.

Quality indicator

Attribute that is some kind of a quality indicator:

  • length of dictionary == hours passed today (means that every hour has data. For both price and energy.

Integration name without unique_id

Integration name in HA without unique_id is now sensor, should be EnergyScore

Something to do with unique_id it seems, when defining it the it will change to energyscore for the sensors that have a valid input. For those without it still is sensor. Several other components use entry.get(CONF_UNIQUE_ID) instead of just config[CONF_UNIQUE_ID], e.g. modbus, bayesian or generic thermostat.

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.