good project, i’m italian too… but there is a problem.
With mercatoelettrico we can know the current PUN, but the useful PUN is the “month” PUN.
Like this: PUN Oggi 2023: il Prezzo dell'Energia Elettrica quanto vale?
the current PUN is useful only for statistics.
Anyway i used your project and made it “better” ![:slight_smile: :slight_smile:](https://community.home-assistant.io/images/emoji/twitter/slight_smile.png?v=10)
# Energy (PUN)
# Multiscrape
multiscrape:
# Costi
# PUN
- name: 'PUN Orario'
resource: 'https://www.mercatoelettrico.org/It/Esiti/MGP/TabellaEsitiMGPPrezzi.aspx'
method: 'GET'
verify_ssl: true
log_response: false
timeout: 10
scan_interval: 1800
parser: 'lxml'
list_separator: ','
form_submit:
resource: 'https://www.mercatoelettrico.org/It/Tools/Accessodati.aspx?ReturnUrl=%2fIt%2fEsiti%2fMGP%2fTabellaEsitiMGPPrezzi.aspx'
select: '#form1'
input:
'ctl00$ContentPlaceHolder1$CBAccetto1' : 'on'
'ctl00$ContentPlaceHolder1$CBAccetto2' : 'on'
'ctl00$ContentPlaceHolder1$Button1' : 'Accetto'
input_filter:
- 'ctl00$ContentPlaceHolder1$Button2'
- 'ctl00$vai'
- 'ctl00$LinkButton2'
- 'ctl00$LoginButton'
submit_once: false
resubmit_on_error: true
sensor:
- name: 'PUN Orario 1'
unique_id: 'energy_pun_hour_cost_1'
select: '#gvFabbisogno > tr:nth-child(2) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 2'
unique_id: 'energy_pun_hour_cost_2'
select: '#gvFabbisogno > tr:nth-child(3) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 3'
unique_id: 'energy_pun_hour_cost_3'
select: '#gvFabbisogno > tr:nth-child(4) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 4'
unique_id: 'energy_pun_hour_cost_4'
select: '#gvFabbisogno > tr:nth-child(5) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 5'
unique_id: 'energy_pun_hour_cost_5'
select: '#gvFabbisogno > tr:nth-child(6) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 6'
unique_id: 'energy_pun_hour_cost_6'
select: '#gvFabbisogno > tr:nth-child(7) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 7'
unique_id: 'energy_pun_hour_cost_7'
select: '#gvFabbisogno > tr:nth-child(8) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 8'
unique_id: 'energy_pun_hour_cost_8'
select: '#gvFabbisogno > tr:nth-child(9) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 9'
unique_id: 'energy_pun_hour_cost_9'
select: '#gvFabbisogno > tr:nth-child(10) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 10'
unique_id: 'energy_pun_hour_cost_10'
select: '#gvFabbisogno > tr:nth-child(11) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 11'
unique_id: 'energy_pun_hour_cost_11'
select: '#gvFabbisogno > tr:nth-child(12) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 12'
unique_id: 'energy_pun_hour_cost_12'
select: '#gvFabbisogno > tr:nth-child(13) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 13'
unique_id: 'energy_pun_hour_cost_13'
select: '#gvFabbisogno > tr:nth-child(14) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 14'
unique_id: 'energy_pun_hour_cost_14'
select: '#gvFabbisogno > tr:nth-child(15) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 15'
unique_id: 'energy_pun_hour_cost_15'
select: '#gvFabbisogno > tr:nth-child(16) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 16'
unique_id: 'energy_pun_hour_cost_16'
select: '#gvFabbisogno > tr:nth-child(17) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 17'
unique_id: 'energy_pun_hour_cost_17'
select: '#gvFabbisogno > tr:nth-child(18) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 18'
unique_id: 'energy_pun_hour_cost_18'
select: '#gvFabbisogno > tr:nth-child(19) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 19'
unique_id: 'energy_pun_hour_cost_19'
select: '#gvFabbisogno > tr:nth-child(20) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 20'
unique_id: 'energy_pun_hour_cost_20'
select: '#gvFabbisogno > tr:nth-child(21) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 21'
unique_id: 'energy_pun_hour_cost_21'
select: '#gvFabbisogno > tr:nth-child(22) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 22'
unique_id: 'energy_pun_hour_cost_22'
select: '#gvFabbisogno > tr:nth-child(23) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 23'
unique_id: 'energy_pun_hour_cost_23'
select: '#gvFabbisogno > tr:nth-child(24) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
- name: 'PUN Orario 24'
unique_id: 'energy_pun_hour_cost_24'
select: '#gvFabbisogno > tr:nth-child(25) > td:nth-child(2)'
value_template: '{{ ( ( value | replace (",", ".") | float(default=0) ) / 1000 | float(default=0) ) | round(6, default=0) | float(default=0) }}'
force_update: true
icon: mdi:currency-eur
unit_of_measurement: '€/kWh'
device_class: monetary
state_class: total
button:
name: 'Aggiornamento Valori PUN Orario'
# -------------------------------------------------------------------------------------------------------------------
# Sensors
sensor:
# Costi
- platform: template
sensors:
# PUN
energy_pun_current_cost:
friendly_name: 'PUN Attuale'
value_template: >-
{% set energy_pun_current_cost_value = ( states( "sensor.energy_pun_hour_cost_" + ( now().hour | string ) ) | float(default=0) ) %}
{% if energy_pun_current_cost_value == "unknown" or energy_pun_current_cost_value == "unavailable" or ( energy_pun_current_cost_value | float(default=0) <= 0 ) %}
0.0
{% else %}
{{ energy_pun_current_cost_value }}
{% endif %}
availability_template: >-
{% set energy_pun_current_cost_availability = ( states( "sensor.energy_pun_hour_cost_" + ( now().hour | string ) ) | float(default=0) ) %}
{% if energy_pun_current_cost_availability == "unknown" or energy_pun_current_cost_availability == "unavailable" or ( energy_pun_current_cost_availability | float(default=0) <= 0 ) %}
false
{% else %}
true
{% endif %}
attribute_templates:
Orario_1: >-
{% if is_state("sensor.energy_pun_hour_cost_1", "unknown") or is_state("sensor.energy_pun_hour_cost_1", "unavailable") or ( states("sensor.energy_pun_hour_cost_1") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_1") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_2: >-
{% if is_state("sensor.energy_pun_hour_cost_2", "unknown") or is_state("sensor.energy_pun_hour_cost_2", "unavailable") or ( states("sensor.energy_pun_hour_cost_2") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_2") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_3: >-
{% if is_state("sensor.energy_pun_hour_cost_3", "unknown") or is_state("sensor.energy_pun_hour_cost_3", "unavailable") or ( states("sensor.energy_pun_hour_cost_3") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_3") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_4: >-
{% if is_state("sensor.energy_pun_hour_cost_4", "unknown") or is_state("sensor.energy_pun_hour_cost_4", "unavailable") or ( states("sensor.energy_pun_hour_cost_4") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_4") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_5: >-
{% if is_state("sensor.energy_pun_hour_cost_5", "unknown") or is_state("sensor.energy_pun_hour_cost_5", "unavailable") or ( states("sensor.energy_pun_hour_cost_5") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_5") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_6: >-
{% if is_state("sensor.energy_pun_hour_cost_6", "unknown") or is_state("sensor.energy_pun_hour_cost_6", "unavailable") or ( states("sensor.energy_pun_hour_cost_6") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_6") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_7: >-
{% if is_state("sensor.energy_pun_hour_cost_7", "unknown") or is_state("sensor.energy_pun_hour_cost_7", "unavailable") or ( states("sensor.energy_pun_hour_cost_7") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_7") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_8: >-
{% if is_state("sensor.energy_pun_hour_cost_8", "unknown") or is_state("sensor.energy_pun_hour_cost_8", "unavailable") or ( states("sensor.energy_pun_hour_cost_8") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_8") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_9: >-
{% if is_state("sensor.energy_pun_hour_cost_9", "unknown") or is_state("sensor.energy_pun_hour_cost_9", "unavailable") or ( states("sensor.energy_pun_hour_cost_9") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_9") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_10: >-
{% if is_state("sensor.energy_pun_hour_cost_10", "unknown") or is_state("sensor.energy_pun_hour_cost_10", "unavailable") or ( states("sensor.energy_pun_hour_cost_10") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_10") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_11: >-
{% if is_state("sensor.energy_pun_hour_cost_11", "unknown") or is_state("sensor.energy_pun_hour_cost_11", "unavailable") or ( states("sensor.energy_pun_hour_cost_11") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_11") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_12: >-
{% if is_state("sensor.energy_pun_hour_cost_12", "unknown") or is_state("sensor.energy_pun_hour_cost_12", "unavailable") or ( states("sensor.energy_pun_hour_cost_12") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_12") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_13: >-
{% if is_state("sensor.energy_pun_hour_cost_13", "unknown") or is_state("sensor.energy_pun_hour_cost_13", "unavailable") or ( states("sensor.energy_pun_hour_cost_13") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_13") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_14: >-
{% if is_state("sensor.energy_pun_hour_cost_14", "unknown") or is_state("sensor.energy_pun_hour_cost_14", "unavailable") or ( states("sensor.energy_pun_hour_cost_14") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_14") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_15: >-
{% if is_state("sensor.energy_pun_hour_cost_15", "unknown") or is_state("sensor.energy_pun_hour_cost_15", "unavailable") or ( states("sensor.energy_pun_hour_cost_15") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_15") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_16: >-
{% if is_state("sensor.energy_pun_hour_cost_16", "unknown") or is_state("sensor.energy_pun_hour_cost_16", "unavailable") or ( states("sensor.energy_pun_hour_cost_16") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_16") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_17: >-
{% if is_state("sensor.energy_pun_hour_cost_17", "unknown") or is_state("sensor.energy_pun_hour_cost_17", "unavailable") or ( states("sensor.energy_pun_hour_cost_17") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_17") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_18: >-
{% if is_state("sensor.energy_pun_hour_cost_18", "unknown") or is_state("sensor.energy_pun_hour_cost_18", "unavailable") or ( states("sensor.energy_pun_hour_cost_18") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_18") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_19: >-
{% if is_state("sensor.energy_pun_hour_cost_19", "unknown") or is_state("sensor.energy_pun_hour_cost_19", "unavailable") or ( states("sensor.energy_pun_hour_cost_19") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_19") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_20: >-
{% if is_state("sensor.energy_pun_hour_cost_20", "unknown") or is_state("sensor.energy_pun_hour_cost_20", "unavailable") or ( states("sensor.energy_pun_hour_cost_20") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_20") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_21: >-
{% if is_state("sensor.energy_pun_hour_cost_21", "unknown") or is_state("sensor.energy_pun_hour_cost_21", "unavailable") or ( states("sensor.energy_pun_hour_cost_21") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_21") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_22: >-
{% if is_state("sensor.energy_pun_hour_cost_22", "unknown") or is_state("sensor.energy_pun_hour_cost_22", "unavailable") or ( states("sensor.energy_pun_hour_cost_22") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_22") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_23: >-
{% if is_state("sensor.energy_pun_hour_cost_23", "unknown") or is_state("sensor.energy_pun_hour_cost_23", "unavailable") or ( states("sensor.energy_pun_hour_cost_23") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_23") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
Orario_24: >-
{% if is_state("sensor.energy_pun_hour_cost_24", "unknown") or is_state("sensor.energy_pun_hour_cost_24", "unavailable") or ( states("sensor.energy_pun_hour_cost_24") | float(default=0) <= 0 ) %}
Non Disponibile
{% else %}
{{ states("sensor.energy_pun_hour_cost_24") | replace (".", ",") | default("Errore") }} €/kWh
{% endif %}
icon_template: mdi:chart-bar
unit_of_measurement: '€/kWh'
device_class: monetary
# -------------------------------------------------------------------------------------------------------------------