Advertisement
rhessellund

Solar forecast home assistant

Jun 6th, 2025
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. type: sections
  2. max_columns: 4
  3. title: Estimat
  4. path: estimat
  5. sections:
  6. - type: grid
  7. cards:
  8. - type: entities
  9. entities:
  10. - entity: sensor.energy_next_hour
  11. name: Next Hour
  12. - entity: sensor.energy_production_today_remaining
  13. name: Today remaining
  14. - entity: sensor.energy_current_hour
  15. name: Current Hour
  16. - entity: sensor.energy_production_today
  17. name: Today
  18. - entity: sensor.energy_production_tomorrow
  19. name: Tomorrow
  20. - entity: sensor.power_production_now
  21. name: Now
  22. - entity: sensor.power_highest_peak_time_today
  23. name: Peaktime today
  24. - entity: sensor.power_highest_peak_time_tomorrow
  25. name: peaktime tomorrow
  26. show_header_toggle: false
  27. title: Solar production forescast
  28. - type: entity
  29. entity: sensor.esphome_web_b2bf74_sun12k_daily_production
  30. name: Produktion i dag
  31. - type: entity
  32. entity: sensor.deye_samlet_pv_effekt
  33. name: Nuværende sol effekt
  34. - type: entity
  35. entity: sensor.seplos_battery_1_battery
  36. name: Battery
  37. - type: entity
  38. entity: sensor.nord_pool_dk1_current_price
  39. name: Salgspris
  40. - type: grid
  41. cards:
  42. - title: Energy distribution today
  43. type: energy-distribution
  44. link_dashboard: true
  45. - type: custom:apexcharts-card
  46. apex_config:
  47. chart:
  48. height: 200
  49. xaxis:
  50. type: datetime
  51. labels:
  52. datetimeFormatter:
  53. hour: HH
  54. tickPlacement: between
  55. graph_span: 2d
  56. span:
  57. end: day
  58. offset: +1d
  59. now:
  60. show: true
  61. label: Nu
  62. header:
  63. show: true
  64. show_states: true
  65. colorize_states: true
  66. yaxis:
  67. - min: -1
  68. max: 1.5
  69. decimals: 1
  70. apex_config:
  71. tickAmount: 5
  72. forceNiceScale: true
  73. series:
  74. - entity: sensor.energi_data_service_salg
  75. name: Lige nu
  76. color: orange
  77. type: column
  78. show:
  79. in_header: raw
  80. in_chart: true
  81. float_precision: 2
  82. unit: " kr."
  83. data_generator: >
  84. /**
  85. * Get HEX color of data point based on value.
  86. *
  87. * @param value { float }
  88. * @returns { string }
  89. */
  90. var colorByValue = function (value) {
  91. if (value <= -0.5) { return '#ff0303'; } // Dark red
  92. else if (value < 0) { return '#e65555' } // Red
  93. else if (value < 0.5) { return '#fc8905' } // Orange
  94. else if (value < 1.0) { return '#fce005' } // Yellow
  95. else { return '#2abf1d' } // Green
  96. }
  97.  
  98.  
  99. /**
  100. * Build data point object.
  101. *
  102. * @param item { object }
  103. * @param isForecast { boolean }
  104. * @returns { object }
  105. */
  106. var buildDataPoint = function (item, isForecast = false) {
  107. return {
  108. x: new Date(item['hour']).getTime(),
  109. y: item['price'],
  110. fillColor: isForecast ? '#a1a1aa' : colorByValue(item['price'])
  111. }
  112. }
  113.  
  114.  
  115. // Expected data points.
  116.  
  117. // Has to equal the value set in "group_span" but as hours.
  118.  
  119. // Which means, if you ie. have set "1d" as group span, you should
  120. set this to 24.
  121.  
  122. var expectedDataPoints = 48;
  123.  
  124.  
  125. // Data points
  126.  
  127. var data = [];
  128.  
  129.  
  130. // No prices available.
  131.  
  132. // Return empty dataset.
  133.  
  134. if (!entity.attributes.raw_today) {
  135. return data;
  136. }
  137.  
  138.  
  139. // Offset of hours set in "span" option.
  140.  
  141. // Note: Only set this, if offset is negative.
  142.  
  143. var offsetHours = 24;
  144.  
  145.  
  146. // Get current timestamp (incl. offset).
  147.  
  148. var currentTime = new Date().getTime() - (3600000 * offsetHours);
  149.  
  150.  
  151. // Loop through all today's hours and collect prices,
  152.  
  153. // but discard hours which have already passed.
  154.  
  155. entity.attributes.raw_today.filter(item => new
  156. Date(item['hour']).getTime() > currentTime).forEach(item => {
  157. data.push(buildDataPoint(item));
  158. });
  159.  
  160.  
  161. // If tomorrow prices is available,
  162.  
  163. // we'll add those to our dataset.
  164.  
  165. if (entity.attributes.tomorrow_valid) {
  166. entity.attributes.raw_tomorrow.forEach(item => {
  167. data.push(buildDataPoint(item));
  168. });
  169. }
  170.  
  171.  
  172. // Determine if we could use a few forecasted today points
  173.  
  174. // to forfill our expected data points.
  175.  
  176. var forecastValuesNeeded = expectedDataPoints - data.length;
  177.  
  178.  
  179. // If forecast values are needed and they are available,
  180.  
  181. // add forecast data points to our data set,
  182.  
  183. // until our expected data points has been reached.
  184.  
  185. if (forecastValuesNeeded > 0 && entity.attributes.forecast) {
  186. var lastKnownDatapointTimestamp = data[data.length - 1]['x'];
  187. entity.attributes.forecast.filter(item => new Date(item['hour']).getTime() > lastKnownDatapointTimestamp).slice(0, forecastValuesNeeded).forEach(item => {
  188. data.push(buildDataPoint(item, true));
  189. });
  190. }
  191.  
  192.  
  193. return data;
  194. - entity: sensor.energi_data_service_salg
  195. name: Lavest i dag
  196. attribute: today_min
  197. color: var(--energy-grid-consumption-color)
  198. transform: |
  199. return entity.attributes.today_min?.price ?? null
  200. float_precision: 2
  201. unit: " kr."
  202. show:
  203. in_chart: false
  204. - entity: sensor.energi_data_service_salg
  205. name: Højest i dag
  206. attribute: today_max
  207. color: var(--energy-grid-consumption-color)
  208. transform: |
  209. return entity.attributes.today_max?.price ?? null
  210. float_precision: 2
  211. unit: " kr."
  212. show:
  213. in_chart: false
  214. - entity: sensor.energi_data_service_salg
  215. name: Gns. i dag
  216. attribute: today_mean
  217. color: var(--energy-grid-consumption-color)
  218. float_precision: 2
  219. unit: " kr."
  220. show:
  221. in_chart: false
  222.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement