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

Version 2.0 #17

Merged
merged 8 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/hacs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: HACS Validation

on:
pull_request:
push:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
hacs:
name: HACS Validation
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4.1.1

- name: 🚀 Run HACS validation
uses: hacs/action@main
with:
category: integration
19 changes: 19 additions & 0 deletions .github/workflows/hassfest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Hassfest

on:
pull_request:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
hassfest:
name: Hassfest
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4.1.1

- name: 🚀 Run hassfest validation
uses: home-assistant/actions/hassfest@master
26 changes: 0 additions & 26 deletions .github/workflows/main.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/pylint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Pylint

on:
pull_request:
push:
workflow_dispatch:

env:
DEFAULT_PYTHON: "3.11"

jobs:
pylint:
name: Pylint
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4.1.1

- name: 🏗 Set up Poetry
run: pipx install poetry

- name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/setup-python@v5.0.0
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: "poetry"

- name: 🏗 Install Python dependencies
run: poetry install --no-interaction

- name: 🚀 Run Pylint
run: poetry run pylint custom_components/tarifa_20td
47 changes: 47 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: Release

on:
release:
types:
- published

jobs:
release:
name: Release the Spook! 👻
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4.1.1

- name: 🔢 Adjust version number
shell: bash
run: |
version="${{ github.event.release.tag_name }}"
version="${version,,}"
version="${version#v}"
yq e -P -o=json \
-i ".version = \"${version}\"" \
"${{ github.workspace }}/custom_components/tariff_20td/manifest.json"
yq e -P -o=json \
-i ".version = \"${version}\"" \
"${{ github.workspace }}/custom_components/tariff_20td/integrations/tariff_20td_inverse/manifest.json"

- name: 📦 Created zipped release package
shell: bash
run: |
cd "${{ github.workspace }}/custom_components/tariff_20td"
zip tariff_20td.zip -r ./

- name: 🔏 Sign release package
uses: sigstore/gh-action-sigstore-python@v2.1.1
with:
inputs: ${{ github.workspace }}/custom_components/tariff_20td/tariff_20td.zip

- name: ⬆️ Upload zip to release
uses: softprops/action-gh-release@v2.0.4
with:
files: ${{ github.workspace }}/custom_components/tariff_20td/tariff_20td.zip
35 changes: 35 additions & 0 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Ruff

on:
pull_request:
workflow_dispatch:

env:
DEFAULT_PYTHON: "3.11"

jobs:
ruff:
name: Ruff
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4.1.1

- name: 🏗 Set up Poetry
run: pipx install poetry

- name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/setup-python@v5.0.0
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache: "poetry"

- name: 🏗 Install Python dependencies
run: poetry install --no-interaction

- name: 🚀 Run ruff linter
run: poetry run ruff check --output-format=github .

- name: 🚀 Run ruff formatter
run: poetry run ruff format --check .
73 changes: 73 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
repos:
- repo: local
hooks:
- id: ruff-check
name: 🐶 Ruff Linter
language: system
types: [python]
entry: poetry run ruff check --fix
require_serial: true
stages: [commit, push, manual]
- id: ruff-format
name: 🐶 Ruff Formatter
language: system
types: [python]
entry: poetry run ruff format
require_serial: true
stages: [commit, push, manual]
- id: check-json
name: { Check JSON files
language: system
types: [json]
entry: poetry run check-json
- id: check-toml
name: ✅ Check TOML files
language: system
types: [toml]
entry: poetry run check-toml
- id: check-yaml
name: ✅ Check YAML files
language: system
types: [yaml]
entry: poetry run check-yaml
- id: check-merge-conflict
name: 💥 Check for merge conflicts
language: system
types: [text]
entry: poetry run check-merge-conflict
- id: check-symlinks
name: 🔗 Check for broken symlinks
language: system
types: [symlink]
entry: poetry run check-symlinks
- id: end-of-file-fixer
name: ⮐ Fix End of Files
language: system
types: [text]
entry: poetry run end-of-file-fixer
stages: [commit, push, manual]
- id: no-commit-to-branch
name: 🛑 Don't commit to main branch
language: system
entry: poetry run no-commit-to-branch
pass_filenames: false
always_run: true
args:
- --branch=mainsudo
- id: poetry
name: 📜 Check pyproject with Poetry
language: system
entry: poetry check
pass_filenames: false
always_run: true
- id: pylint
name: 🌟 Starring code with pylint
language: system
types: [python]
entry: poetry run pylint
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
name: 🎨 Format using prettier
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
# Tarifa 2.0 TD

Componente para Home Assistant para crear un sensor con el precio actual para usuarios con tarifa de tres tramos con precios fijos.
Componente para Home Assistant para crear un sensor con el precio actual para usuarios con tarifas 2.0 TD (tres periodos) y 3.0 TD (seis periodos).

Permite saber en cada momento el precio del kWh según si es valle, llana o punta, teniendo en cuenta que los festivos y fines de semana siempre es valle.

Además crea un sensor que calcula los costes fijos diarios (potencia, alquiler de contador, bono social...).

## Instalación

Puedes instalar el componente usando HACS, para ello basta con añadir este repositorio a los repositorios personalizados y buscarlo escribiendo «Tarifa».

## Configuración

Una vez instalado, ve a _Dispositivos y Servicios -> Añadir Integración_ y busca _Tarifa_.

El asistente te solicitará 4 precios. Los tres primeros son los precios por kWh de tu tarifa.

El cuarto es el coste fijo por día. Normalmente este coste suele incluir potencia, bono social y alguna cuota. Lo más fácil es buscar la última factura y dividir estos costes fijos por el número de días.

El asistente primero te solicitará elegir la tarifa correspondiente: 2.0 o 3.0.

## Uso
Una vez configurado el componente, en el panel de energía añade tu sensor de energía consumida total e indica que quieres realizar el control de costes usando una entidad con el precio actual seleccionado _Precio kWh_ como entidad.

Así mismo, puedes añadir una nueva línea de consumo con el sensor _Costes fijos_ (que siempre valdrá 0) y en sus costes configurar _Usar una entidad que realiza un seguimiento de los costes totales_ seleccionando _Costes Fijos Totales_, de esta forma cada día añadirá el coste fijo y así tener una idea más cercana del precio final.
Lo habitual será la 2.0 TD que es la doméstica con 3 periodos.

Además, el sensor `sensor.precio_kWh` dispone del atributo «Period» con el periodo actual (P1 = punta, P2 = llana, P3 = valle), que puede utilizarse para automatizaciones.
En el siguiente paso, deberemos indicar el coste diario y los precios de cada uno de los periodos.

El coste fijo por día se refiere a costes fijos no dependientes del consumo. Normalmente este coste suele incluir potencia, bono social y alguna cuota. Lo más fácil es buscar
la última factura y dividir estos costes fijos por el número de días e introducir el resultado.

## Uso

## Futuras ideas
Una vez configurado el componente, en el panel de energía añade tu sensor de energía consumida total e indica que quieres realizar el control de costes usando una entidad con el
precio actual seleccionado _Precio kWh_ como entidad.

Aunque actualmente está muy bajo y apenas supone diferencia, si el coste del mecanismo del gas volviese a subir, me gustaría añadir la opción de incrementar los costes añadiendo a la precio del momento el MAG asociado.
Así mismo, puedes añadir una nueva línea de consumo con el sensor _Costes fijos_ (que siempre valdrá 0) y en sus costes configurar _Usar una entidad que realiza un seguimiento de
los costes totales_ seleccionando _Costes Fijos Totales_, de esta forma cada día añadirá el coste fijo y así tener una idea más cercana del precio final.

Además, el sensor `sensor.precio_kWh` dispone del atributo «Period» con el periodo actual (P1 = punta, P2 = llana, P3 = valle para el caso de 2.0, o de P1 a P6 para 3.0),
que puede utilizarse para automatizaciones.

## Balance Neto

Expand Down
Loading