Facebook
From Henrik, 1 Week ago, written in YAML.
Embed
Download Paste or View Raw
Hits: 99
  1. # xyz = gatunamn, dvs sensor från Tibber-integrationen
  2. template:
  3.   - sensor:
  4.       - name: 'Accumulated consumption (int)'
  5.         unique_id: accumulated_consumption_int
  6.         state: >
  7.          {{ states('sensor.accumulated_consumption_xyz') | int }}
  8.         state_class: measurement
  9.       - name: 'Predicted electricity price (monthly)'
  10.         unique_id: predicted_electricity_price_monthly
  11.         state: >
  12.          {## Först beräknas antal dagar som är kvar i innervarande månad ##}
  13.           {% set dt = now() %}
  14.           {% set days_in_month = (dt.replace(month=dt.month%12+1, day=1)-timedelta(days=1)).day %}
  15.           {% set day_current = dt.day %}
  16.           {% set hours_passed = (day_current*24)+dt.hour %}
  17.           {% set hours_left = (days_in_month-dt.day)*24 %}
  18.           {## Ta fram de uppgifter vi har från Tibber integrationen ##}
  19.           {% set monthly_cost = float(states('sensor.monthly_cost_xyz')) %}
  20.           {## Statistics mean sensor ##}
  21.           {% set electricity_consumption_mean = float(states('sensor.electricity_consumption_mean_7_days')) %}
  22.           {% set electricity_price_mean = float(states('sensor.electricity_price_mean_7_days')) %}
  23.           {## Beräkna prediction ##}
  24.           {% set mean_kwh_hour = electricity_consumption_mean/24 %}
  25.           {% set prediction_left = hours_left*mean_kwh_hour*electricity_price_mean %}
  26.           {## Slutligen ta fram den väldigt enkla uppskattningen ##}
  27.           {% set prediction = monthly_cost+prediction_left %}
  28.           {{ prediction | int }}        
  29.   - trigger: # Sampla förbrukningen per dag för att få max-värde. Kanske kan använda energy-API istället?
  30.       - platform: time
  31.         at: '23:59:55'
  32.     sensor:
  33.       - name: 'Electricity Consumption (max)'
  34.         unique_id: electricity_consumption_max
  35.         state: >
  36.          {{ states('sensor.accumulated_consumption_xyz') }}
  37.         state_class: measurement
  38.         unit_of_measurement: "kWh"      
  39.  
  40. sensor:
  41.   - platform: statistics
  42.     name: 'Electricity Price (mean 7-days)'
  43.     unique_id: electricity_price_mean
  44.     entity_id: sensor.nordpool_kwh_se3_sek_3_095_0
  45.     state_characteristic: mean
  46.     sampling_size: 168
  47.     max_age:
  48.       days: 7
  49.   - platform: statistics
  50.     name: 'Electricity Consumption (mean 7-days)'
  51.     unique_id: electricity_consumption_mean
  52.     entity_id: sensor.electricity_consumption_max
  53.     state_characteristic: mean
  54.     sampling_size: 7
  55.     max_age:
  56.       days: 7
  57.   - platform: nordpool
  58.     VAT: False
  59.     low_price_cutoff: 0.95
  60.     region: "SE3"
  61.     precision: 3
  62.     price_type: kWh
  63.     additional_costs: "{{0.0|float}}"