Giter VIP home page Giter VIP logo

sensor.carbon_intensity_uk's Introduction

Carbon Intensity UK sensor

GitHub Release

GitHub Activity License

hacs Project Maintenance BuyMeCoffee

Discord Community Forum

Component to integrate with Carbon Intensity UK.

This component will set up the following platforms.

Platform Description
sensor Show info from Carbon Intensity UK API.

The sensor retrieves information using Carbon Intensity UK API library

alt Sensor attributes

Installation

  1. Using the tool of choice open the directory (folder) for your HA configuration (where you find configuration.yaml).
  2. If you do not have a custom_components directory (folder) there, you need to create it.
  3. In the custom_components directory (folder) create a new folder called carbon_intensity_uk.
  4. Download all the files from the custom_components/carbon_intensity_uk/ directory (folder) in this repository.
  5. Place the files you downloaded in the new directory (folder) you created.
  6. Restart Home Assistant
  7. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "Carbon Intensity UK"

Using your HA configuration directory (folder) as a starting point you should now also have this:

custom_components/carbon_intensity_uk/.translations/en.json
custom_components/carbon_intensity_uk/.translations/nb.json
custom_components/carbon_intensity_uk/.translations/sensor.nb.json
custom_components/carbon_intensity_uk/__init__.py
custom_components/carbon_intensity_uk/binary_sensor.py
custom_components/carbon_intensity_uk/config_flow.py
custom_components/carbon_intensity_uk/const.py
custom_components/carbon_intensity_uk/manifest.json
custom_components/carbon_intensity_uk/sensor.py
custom_components/carbon_intensity_uk/switch.py

Configuration is done in the UI

Contributions are welcome!

If you want to contribute to this please read the Contribution guidelines


sensor.carbon_intensity_uk's People

Contributors

badguy99 avatar jscruz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sensor.carbon_intensity_uk's Issues

Translation key migration

Build warning issue:

[TRANSLATIONS] config.title key has been moved out of config and into the root of strings.json. Starting Home Assistant 0.109 you only need to define this key in the root if the title needs to be different than the name of your integration in the manifest.

Error in icon intensity = INTENSITY[index] KeyError: 'very high'

I was running into an error with this plugin when the carbon intensity of the grid was "very high".

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 522, in _async_add_entity
    original_icon=entity.icon,
  File "/config/custom_components/carbon_intensity_uk/sensor.py", line 38, in icon
    intensity = INTENSITY[index]
KeyError: 'very high'

I managed to get this working again by changing the const.py file to include versions of the values without the underscore:

INTENSITY = {
    "very_low" : 0,
    "very low" : 0,
    "low" : 1,
    "moderate": 2,
    "high": 3,
    "very_high": 4,
    "very high": 4,
}

I haven't properly tested this but it seems to be working. It might be possible to delete the very_low and very_high values.

Change action location

In the build step, the warning message generated is the following:

Use hacs/integration/action@main instead of hacs/integration/action@master

Adding Future Forecast Graph

Is your feature request related to a problem? Please describe.
I thought it would be useful to be able to display a future value of the Carbon Intensity as a graph, to compliment your table. I am sharing here an MVP idea.

Seems possible that it could be cleaned up slightly and then integrated?

Describe the solution you'd like
Using ApexCharts it is possible to display future data using the data_generator option. Please note I have very poor Javascript knowledge so I actually just copied in all the values below, but I am sure this could be made with a loop:

type: custom:apexcharts-card
graph_span: 2d
header:
  show: true
  title: Carbon Intensity Forecast
now:
  show: true
span:
  start: hour
series:
  - entity: sensor.carbon_intensity_uk
    name: Forecast
    data_generator: >
      return [[entity.attributes.forecast[0].from,
      entity.attributes.forecast[0].intensity],
      [entity.attributes.forecast[1].from,
      entity.attributes.forecast[1].intensity],
      [entity.attributes.forecast[3].from,
      entity.attributes.forecast[3].intensity],
      [entity.attributes.forecast[4].from,
      entity.attributes.forecast[4].intensity],
      [entity.attributes.forecast[5].from,
      entity.attributes.forecast[5].intensity],
      [entity.attributes.forecast[6].from,
      entity.attributes.forecast[6].intensity],
      [entity.attributes.forecast[7].from,
      entity.attributes.forecast[7].intensity],
      [entity.attributes.forecast[8].from,
      entity.attributes.forecast[8].intensity],
      [entity.attributes.forecast[9].from,
      entity.attributes.forecast[9].intensity],
      [entity.attributes.forecast[10].from,
      entity.attributes.forecast[10].intensity],
      [entity.attributes.forecast[11].from,
      entity.attributes.forecast[11].intensity],
      [entity.attributes.forecast[12].from,
      entity.attributes.forecast[12].intensity],
      [entity.attributes.forecast[13].from,
      entity.attributes.forecast[13].intensity],
      [entity.attributes.forecast[14].from,
      entity.attributes.forecast[14].intensity],
      [entity.attributes.forecast[15].from,
      entity.attributes.forecast[15].intensity],
      [entity.attributes.forecast[16].from,
      entity.attributes.forecast[16].intensity],
      [entity.attributes.forecast[17].from,
      entity.attributes.forecast[17].intensity],
      [entity.attributes.forecast[18].from,
      entity.attributes.forecast[18].intensity],
      [entity.attributes.forecast[19].from,
      entity.attributes.forecast[19].intensity],
      [entity.attributes.forecast[20].from,
      entity.attributes.forecast[20].intensity],
      [entity.attributes.forecast[21].from,
      entity.attributes.forecast[21].intensity],
      [entity.attributes.forecast[22].from,
      entity.attributes.forecast[22].intensity],
      [entity.attributes.forecast[23].from,
      entity.attributes.forecast[23].intensity],
      [entity.attributes.forecast[24].from,
      entity.attributes.forecast[24].intensity],
      [entity.attributes.forecast[25].from,
      entity.attributes.forecast[25].intensity],
      [entity.attributes.forecast[26].from,
      entity.attributes.forecast[26].intensity],
      [entity.attributes.forecast[27].from,
      entity.attributes.forecast[27].intensity],
      [entity.attributes.forecast[28].from,
      entity.attributes.forecast[28].intensity],
      [entity.attributes.forecast[29].from,
      entity.attributes.forecast[29].intensity],
      [entity.attributes.forecast[30].from,
      entity.attributes.forecast[30].intensity],
      [entity.attributes.forecast[31].from,
      entity.attributes.forecast[31].intensity],
      [entity.attributes.forecast[32].from,
      entity.attributes.forecast[32].intensity],
      [entity.attributes.forecast[33].from,
      entity.attributes.forecast[33].intensity],
      [entity.attributes.forecast[34].from,
      entity.attributes.forecast[34].intensity],
      [entity.attributes.forecast[35].from,
      entity.attributes.forecast[35].intensity],
      [entity.attributes.forecast[36].from,
      entity.attributes.forecast[36].intensity],
      [entity.attributes.forecast[37].from,
      entity.attributes.forecast[37].intensity],
      [entity.attributes.forecast[38].from,
      entity.attributes.forecast[38].intensity],
      [entity.attributes.forecast[39].from,
      entity.attributes.forecast[39].intensity],
      [entity.attributes.forecast[40].from,
      entity.attributes.forecast[40].intensity],
      [entity.attributes.forecast[41].from,
      entity.attributes.forecast[41].intensity],
      [entity.attributes.forecast[42].from,
      entity.attributes.forecast[42].intensity],
      [entity.attributes.forecast[43].from,
      entity.attributes.forecast[43].intensity],
      [entity.attributes.forecast[44].from,
      entity.attributes.forecast[44].intensity],
      [entity.attributes.forecast[45].from,
      entity.attributes.forecast[45].intensity],
      [entity.attributes.forecast[46].from,
      entity.attributes.forecast[46].intensity],
      [entity.attributes.forecast[47].from,
      entity.attributes.forecast[47].intensity]];

image

Describe alternatives you've considered
I googled around for other graphing libraries that can show future values in Home Assistant but this seemed like one of the best.

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.