Skip to content

Instantly share code, notes, and snippets.

@s1nnerman89
Last active March 10, 2023 11:19
Show Gist options
  • Save s1nnerman89/b77c291d5624e15fb3651cce9c02ecd5 to your computer and use it in GitHub Desktop.
Save s1nnerman89/b77c291d5624e15fb3651cce9c02ecd5 to your computer and use it in GitHub Desktop.
Homeassistant package per tracciamento prezzo tariffa bioraria Servizio Elettrico Nazionale
binary_sensor:
- platform: workday
country: IT
scrape:
- resource: https://www.servizioelettriconazionale.it/it-IT/tariffe/uso-domestico/biorarie/residente
sensor:
- name: "Tariffa F1"
select: "div.table:nth-child(6) table:nth-child(1) tr:nth-child(2) td:nth-child(2)"
- name: "Tariffa F23"
select: "div.table:nth-child(6) table:nth-child(1) tr:nth-child(3) td:nth-child(2)"
sensor:
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_utc'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
- 'beat'
- platform: template
sensors:
actual_arera_price:
value_template: >-
{% set t = strptime(states('sensor.time'), '%H:%M') %}
{%- if t.hour >=8 and t.hour <19 and is_state('binary_sensor.workday_sensor', 'on') -%}
{{ states("sensor.tariffa_f1") | replace(",",".") | float }}
{%- elif (t.hour >=19 or t.hour <8) and is_state('binary_sensor.workday_sensor', 'on') -%}
{{ states("sensor.tariffa_f23") | replace(",",".") | float }}
{%- elif is_state('binary_sensor.workday_sensor', 'off') -%}
{{ states("sensor.tariffa_f23") | replace(",",".") | float }}
{%- endif -%}
friendly_name: Actual ARERA Price
unit_of_measurement: €/kWh
actual_arera_rate:
value_template: >-
{% set cur_rate = states('sensor.actual_arera_price') | float %}
{%- if cur_rate == states("sensor.tariffa_f23") | replace(",",".") | float -%}F23
{%- elif cur_rate == states("sensor.tariffa_f1") | replace(",",".") | float -%}F1
{%- endif -%}
friendly_name: Actual ARERA Rate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment