marlar

Eksempel på ekstra sensor

May 17th, 2022 (edited)
193
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  - platform: rest
  2.     name: elpriser_raw_dk1
  3.     value_template: "{{ value_json.success }}"
  4.     json_attributes_path: "$.result"
  5.     json_attributes:
  6.      - updatetime
  7.       - region
  8.       - records
  9.     resource_template: >
  10.      {% set s = {
  11.         'region': 'DK1',
  12.         'vat': 25,
  13.         'abonnement': 0.00,
  14.         'elafgift': 1.12875,
  15.         'systemydelse': 0.09,
  16.         'transport_lavlast': 0.3754,
  17.         'transport_spidslast': 0.9564,
  18.         } %}
  19.       {% set cdt = now() %}
  20.       {% set transport = s.transport_spidslast if (cdt.month >= 10 or cdt.month <= 3) and cdt.hour >= 17 and cdt.hour < 20 else s.transport_lavlast %}
  21.       {% set additional_cost = s.abonnement + s.elafgift + s.systemydelse + transport %}
  22.       {% set EUR = states('sensor.currency_eur_dkk') | float(7.44060) %}
  23.       https://api.energidataservice.dk/datastore_search_sql?sql=SELECT "SpotPriceEUR"/1000*{{ EUR }} AS "PriceDKK" , ROUND(CAST(FLOAT8 ("SpotPriceEUR"*{{ EUR/1000*(1+s.vat/100) }}%2B{{additional_cost}}) as numeric),2) AS "TotalPriceDKK" ,"HourDK" FROM "elspotprices" WHERE "PriceArea"='{{s.region}}' AND "HourDK" >= '{{ now().date() }}' order by "HourDK"&region={{ s.region }}&updatetime={{ now() }}
  24.     scan_interval: 3600
  25.  
  26.   - platform: template
  27.     sensors:
  28.       elpriser_dk1:
  29.         friendly_name: "Elpriser DK1"
  30.         value_template: "{{ state_attr('sensor.elpriser_raw_dk1', 'records')[now().hour + (now().date() | string > state_attr('sensor.elpriser_raw_dk1', 'updatetime'))*24].TotalPriceDKK }}"
  31.         device_class: energy
  32.         attribute_templates:
  33.           current_price: "{{ states('sensor.elpriser_dk1') }}"
  34.           updatetime: "{{ state_attr('sensor.elpriser_raw_dk1', 'updatetime') }}"
  35.           currency: DKK
  36.           country: Denmark
  37.           region: "{{ state_attr('sensor.elpriser_raw_dk1', 'region') }}"
  38.           unit: kWh
  39.           min: >
  40.            {% set ns = namespace(value=100) %}
  41.             {% for r in state_attr("sensor.elpriser_raw_dk1", "records") %}
  42.             {% set ns.value = min(ns.value, r.TotalPriceDKK | float) %}
  43.             {% endfor %}
  44.             {{ ns.value }}
  45.           max: >
  46.            {% set ns = namespace(value=0) %}
  47.             {% for r in state_attr("sensor.elpriser_raw_dk1", "records") %}
  48.             {% set ns.value = max(ns.value, r.TotalPriceDKK | float) %}
  49.             {% endfor %}
  50.             {{ ns.value }}
  51.           priser: "{{ state_attr('sensor.elpriser_raw_dk1', 'records') }}"
  52.         unit_of_measurement: "DKK/kWh"
  53.  
RAW Paste Data Copied