Guest User

Untitled

a guest
Apr 3rd, 2024
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.73 KB | None | 0 0
  1. ################################################################################
  2. # PACKAGE WITH SOLAR EV CHARGING CONTROL TEMPLATES, HELPERS AND AUTOMATIONS
  3. #
  4. # Created and maintained by DykandDK (github.com/DykandDK/)
  5. #
  6. # Revision History:
  7. # - 2023/09/30 - First version
  8. #
  9. ################################################################################
  10.  
  11. #───────────────────────────────────────────────────────────────────────────────
  12. # HELPERS
  13. #───────────────────────────────────────────────────────────────────────────────
  14. # This section includes defintions of input helpers that can be added to your
  15. # dashboard. The helpers are used in templates and automations.
  16. #───────────────────────────────────────────────────────────────────────────────
  17. input_boolean:
  18. #─────────────────────────────────────────────────────────────────────────────
  19. # Switch to toggle automatic adjustment of EV charging to solar production.
  20. # Used as condition in automation so it is possible to charge at full speed
  21. # during night or if prices are low.
  22. #─────────────────────────────────────────────────────────────────────────────
  23. solar_control_auto_adjust_charging:
  24. name: Automatically adjust charging
  25. icon: mdi:flash-auto
  26.  
  27. #─────────────────────────────────────────────────────────────────────────────
  28. # Switch to toggle automatic start and stop of EV charging based on current
  29. # solar production. Used as condition in automation so it is possible to
  30. # disable stop of charing if your car does not allow resume.
  31. #─────────────────────────────────────────────────────────────────────────────
  32. solar_control_auto_start_charging:
  33. name: Automatically start and stop charging
  34. icon: mdi:play-pause
  35.  
  36. input_number:
  37. #─────────────────────────────────────────────────────────────────────────────
  38. # Buffer in watts to exclude in calculation of excess solar energy available.
  39. # This can be used to save energy for other purposes, e.g. charging of house
  40. # battery or selling to the grid, depending on your inverter settings
  41. #─────────────────────────────────────────────────────────────────────────────
  42. solar_control_energy_buffer:
  43. name: Energy buffer in watts
  44. icon: mdi:home-minus
  45. unit_of_measurement: "W"
  46. min: 0
  47. max: 5000
  48. step: 100
  49. mode: slider
  50.  
  51. #───────────────────────────────────────────────────────────────────────────────
  52. # TEMPLATES
  53. #───────────────────────────────────────────────────────────────────────────────
  54. # The following templates will calculate excess solar production that can be
  55. # used for EV charging or other purposes.
  56. #───────────────────────────────────────────────────────────────────────────────
  57. template:
  58. - sensor:
  59. #─────────────────────────────────────────────────────────────────────────
  60. # This template will calculate excess energy from solar production that
  61. # can be used for EV charging or other purposes.
  62. #─────────────────────────────────────────────────────────────────────────
  63. - name: "Solar Control - Excess Solar Energy"
  64. unique_id: solar_control_excess_solar_energy
  65. unit_of_measurement: "W"
  66. icon: mdi:octagram-plus-outline
  67. state: >
  68. {#────────────────────────────────────────────────────────────────────
  69. CONFIGURATION
  70. ──────────────────────────────────────────────────────────────────────
  71. Change the each of the entities below to the entities providing the
  72. relevant information about current solar production, total house
  73. consumption and current EV charging. It is also possible to add a
  74. buffer that will be substracted from the calculation of excess solar
  75. energy available.
  76.  
  77. All sensors should provide the state in watts. If the sensors are
  78. using kW for measurement, multiply the value with 1,000 to convert
  79. to watts.
  80. ────────────────────────────────────────────────────────────────────#}
  81. {# Current total solar production in watts #}
  82. {% set solar_production = states('sensor.total_pv_power') | float %}
  83.  
  84. {# Current total consumption in watts #}
  85. {% set current_consumption = states('sensor.current_power_consumption') | float %}
  86.  
  87. {# Current EV charging in watts #}
  88. {% set ev_charging = states('sensor.lightspeed_charger_power') | float * 1000 %}
  89.  
  90. {#────────────────────────────────────────────────────────────────────
  91. END OF CONFIGURATION
  92. ────────────────────────────────────────────────────────────────────#}
  93. {{ (solar_production - current_consumption + ev_charging - states('input_number.solar_control_energy_buffer') | float) | int }}
  94.  
  95. #─────────────────────────────────────────────────────────────────────────
  96. # This template calculates the charging amps and whether 1 or 3 phase
  97. # charging should be used based on available excess solar production.
  98. #
  99. # The template is designed for used with the Easee Home Charger, but can
  100. # be used with other chargers where charging is controlled in amps
  101. #
  102. # Minimum amps per phase for this charger is 6A ~ 1.4 kW
  103. # Maximum amps per phase can be set in the configuration section below
  104. #─────────────────────────────────────────────────────────────────────────
  105. - name: "Solar Control - EV Charging"
  106. unique_id: solar_control_ev_charging
  107. icon: mdi:ev-station
  108. state: "{{ this.attributes.status | default('pause') }}"
  109. #state: "test"
  110. attributes:
  111. phases: >
  112. {#────────────────────────────────────────────────────────────────────
  113. CONFIGURATION
  114. ──────────────────────────────────────────────────────────────────────
  115. You can change the voltage or maximum allowed current per phase below
  116. ────────────────────────────────────────────────────────────────────#}
  117. {% set max_charging = states('sensor.solar_control_excess_solar_energy') | float %}
  118. {% set v = 235 %}
  119. {% set maxPhaseA = 16 %}
  120. {#────────────────────────────────────────────────────────────────────
  121. END OF CONFIGURATION
  122. ────────────────────────────────────────────────────────────────────#}
  123. {% if max_charging<(6*v) %}
  124. {% set phases = {"status": "pause", "count": 0, "P1": 0, "P2": 0, "P3": 0 } %}
  125. {% elif max_charging > (6*3*v) %}
  126. {% set maxCharge =(max_charging/3/v),maxPhaseA %}
  127. {% set phases = {"status": "charge", "count": 3, "P1": maxCharge|min|int, "P2": maxCharge|min|int, "P3": maxCharge|min|int } %}
  128. {% else %}
  129. {% set maxCharge = (max_charging/v),maxPhaseA %}
  130. {% set phases = {"status": "charge", "count": 1, "P1": maxCharge|min|int, "P2": 0, "P3": 0 } %}
  131. {% endif %}
  132. {{ phases }}
  133. status: "{{ iif(this.attributes.phases.status=='pause','Pause','Opladning ' + (this.attributes.phases.count|string) + ' '+ iif(this.attributes.phases.count==1,'fase','faser') +': '+(this.attributes.phases.P1|string)+'A') }}"
  134.  
  135. #───────────────────────────────────────────────────────────────────────────────
  136. # AUTOMATIONS
  137. #───────────────────────────────────────────────────────────────────────────────
  138. # The following automations will adjust EV charging to current solar production:
  139. #
  140. # 1) If automatic adjustment is enabled, adjust the current charging rate
  141. # (ampere) on Easee Home Charger based on calculated excess solar production
  142. #───────────────────────────────────────────────────────────────────────────────
  143. automation:
  144. #─────────────────────────────────────────────────────────────────────────────
  145. # This automation adjusts the current charging rate (in amperes) based on
  146. # calculated excess solar production, but only if automatic adjustment is enabled
  147. #─────────────────────────────────────────────────────────────────────────────
  148. - alias: "Solar control: Change EV charging ampere"
  149. id: solar_control_adjust_ev_charging
  150. description: "This automation changes the EV charging rate based on current solar production."
  151. trigger:
  152. - platform: state
  153. entity_id: sensor.solar_control_excess_solar_energy
  154. condition:
  155. - condition: state
  156. entity_id: input_boolean.solar_control_auto_adjust_charging
  157. state: "on"
  158. action:
  159. - service: input_number.set_value
  160. target:
  161. entity_id: number.lightspeed_charge_current
  162. data_template:
  163. value: >
  164. {% set max_charging = states('sensor.solar_control_excess_solar_energy') | float %}
  165. {% if max_charging > 0 %}
  166. {% set desired_current = max_charging / 230 %} # Assuming a standard voltage of 230V
  167. {% if desired_current > 16 %}
  168. 16 # Cap the current at 16A
  169. {% elif desired_current < 1 %}
  170. 1 # Set minimum current at 1A
  171. {% else %}
  172. {{ desired_current | round(0) }} # Round to the nearest whole number
  173. {% endif %}
  174. {% else %}
  175. 1 # Default to 1A if excess solar energy is not available
  176. {% endif %}
  177. mode: single
  178.  
Advertisement
Add Comment
Please, Sign In to add comment