Advertisement
dykandDK

HA - YAML - Apex chart with weekly Solcast forecast

Sep 30th, 2024 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 4.72 KB | None | 0 0
  1. type: custom:apexcharts-card
  2. apex_config:
  3.   plotOptions:
  4.     bar:
  5.       columnWidth: 90%
  6.       dataLabels:
  7.         position: bottom
  8.   chart:
  9.     height: 275px
  10.     defaultLocale: da
  11.     locales:
  12.       - name: da
  13.         options:
  14.           shortDays:
  15.            - SØN
  16.             - MAN
  17.             - TIR
  18.             - ONS
  19.             - TOR
  20.             - FRE
  21.             - LØR
  22.   dataLabels:
  23.     enabled: true
  24.     style:
  25.       fontSize: 12px
  26.       colors:
  27.        - '#fff'
  28.     distributed: true
  29.     background:
  30.       enabled: false
  31.     formatter: |
  32.      EVAL:function(value) {
  33.         return value.toFixed(1);
  34.       }
  35.   xaxis:
  36.     labels:
  37.       position: 'on'
  38.       hideOverlappingLabels: false
  39.       showDuplicates: true
  40.       show: true
  41.       format: ddd
  42.       style:
  43.         fontSize: 12px
  44.         fontWeight: 400
  45.     axisBorder:
  46.       show: true
  47.       color: grey
  48.     tooltip:
  49.       enabled: false
  50. all_series_config:
  51.   unit: ' kWh'
  52. experimental:
  53.   color_threshold: true
  54.   hidden_by_default: true
  55. header:
  56.   title: Ugens forventede solproduktion
  57.   show: true
  58.   standard_format: true
  59.   show_states: true
  60.   colorize_states: true
  61. graph_span: 1week
  62. span:
  63.   start: day
  64.   offset: '-0h'
  65. series:
  66.   - entity: sensor.solcast_pv_forecast_forecast_tomorrow
  67.     name: Prognose
  68.     type: column
  69.     show:
  70.       in_header: false
  71.       in_chart: true
  72.       legend_value: false
  73.       datalabels: true
  74.     float_precision: 2
  75.     data_generator: >
  76.      // REMOVE ME
  77.  
  78.  
  79.       const date = new Date();
  80.  
  81.       let day = date.getDate();
  82.  
  83.       let month = date.getMonth();
  84.  
  85.       let year = date.getFullYear();
  86.  
  87.       let curDate = new Date(year,month,day)
  88.  
  89.       const list = [];
  90.  
  91.       list.push(hass.states['sensor.solcast_pv_forecast_forecast_today'].state);
  92.  
  93.       list.push(hass.states['sensor.solcast_pv_forecast_forecast_tomorrow'].state);
  94.  
  95.       list.push(hass.states['sensor.solcast_pv_forecast_forecast_day_3'].state);
  96.  
  97.       list.push(hass.states['sensor.solcast_pv_forecast_forecast_day_4'].state);
  98.  
  99.       list.push(hass.states['sensor.solcast_pv_forecast_forecast_day_5'].state);
  100.  
  101.       list.push(hass.states['sensor.solcast_pv_forecast_forecast_day_6'].state);
  102.  
  103.       list.push(hass.states['sensor.solcast_pv_forecast_forecast_day_7'].state);
  104.  
  105.       const data = [];
  106.  
  107.       for(let i = 0; i <= list.length-1; i++) {
  108.         let d1=new Date(curDate.getTime()+(60*60*24*1000*i));
  109.         data.push([d1, list[i]]);
  110.       }
  111.  
  112.       return data;
  113.     group_by:
  114.       func: first
  115.       duration: 1day
  116.     extend_to: false
  117.     color_threshold:
  118.       - value: 30
  119.         color: darkgreen
  120.       - value: 25
  121.         color: green
  122.       - value: 20
  123.         color: '#c3cc1f'
  124.       - value: 15
  125.         color: '#ded012'
  126.       - value: 10
  127.         color: orange
  128.       - value: 5
  129.         color: red
  130.       - value: 0
  131.         color: darkred
  132.   - entity: sensor.solcast_pv_forecast_forecast_tomorrow
  133.     name: Total
  134.     type: column
  135.     show:
  136.       in_header: true
  137.       in_chart: false
  138.     float_precision: 2
  139.     transform: >
  140.      // REMOVE ME
  141.  
  142.       var total = 0;
  143.  
  144.       total +=
  145.       Number(hass.states['sensor.solcast_pv_forecast_forecast_today'].state);
  146.  
  147.       total +=
  148.       Number(hass.states['sensor.solcast_pv_forecast_forecast_tomorrow'].state);
  149.  
  150.       total +=
  151.       Number(hass.states['sensor.solcast_pv_forecast_forecast_day_3'].state);
  152.  
  153.       total +=
  154.       Number(hass.states['sensor.solcast_pv_forecast_forecast_day_4'].state);
  155.  
  156.       total +=
  157.       Number(hass.states['sensor.solcast_pv_forecast_forecast_day_5'].state);
  158.  
  159.       total +=
  160.       Number(hass.states['sensor.solcast_pv_forecast_forecast_day_6'].state);
  161.  
  162.       total +=
  163.       Number(hass.states['sensor.solcast_pv_forecast_forecast_day_7'].state);
  164.  
  165.       return total;
  166.   - entity: sensor.solcast_pv_forecast_forecast_tomorrow
  167.     name: Gns. pr. dag
  168.     type: column
  169.     show:
  170.       in_header: true
  171.       in_chart: false
  172.     float_precision: 2
  173.     transform: >
  174.      // REMOVE ME
  175.  
  176.       var total = 0;
  177.  
  178.       total +=
  179.       Number(hass.states['sensor.solcast_pv_forecast_forecast_today'].state);
  180.  
  181.       total +=
  182.       Number(hass.states['sensor.solcast_pv_forecast_forecast_tomorrow'].state);
  183.  
  184.       total +=
  185.       Number(hass.states['sensor.solcast_pv_forecast_forecast_day_3'].state);
  186.  
  187.       total +=
  188.       Number(hass.states['sensor.solcast_pv_forecast_forecast_day_4'].state);
  189.  
  190.       total +=
  191.       Number(hass.states['sensor.solcast_pv_forecast_forecast_day_5'].state);
  192.  
  193.       total +=
  194.       Number(hass.states['sensor.solcast_pv_forecast_forecast_day_6'].state);
  195.  
  196.       total +=
  197.       Number(hass.states['sensor.solcast_pv_forecast_forecast_day_7'].state);
  198.  
  199.       return total/7;
  200.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement