Update Energy Package

This commit is contained in:
2022-07-22 08:42:12 -07:00
parent 6023c81531
commit 91e4efd531
3 changed files with 349 additions and 47 deletions

View File

@@ -0,0 +1,79 @@
#!/usr/bin/python3
# ---
# Script to generate Power Share and Panel OK sensors for the solar panels
# by serial number.
import sys
import jinja2 as j2
# Serial Numbers for Panel Inverters
INVERTER_SNS = [
202147113780,
202147116830,
202147117162,
202147117631,
202147122858,
202147123517,
202147125027,
202147125590,
202147125734,
202147125902,
202147126079,
202147126357,
202147126997,
202147128369,
202147129445,
202147130152,
202147130290,
]
# Jinja2 Snippet for Panel Sensors
POWER_SHARE_SENSORS = '''---
# -----------------------------------------------------------------------------
# Panel/Inverter Monitor Sensors
sensor:
- name: Envoy Inverter Average Power
platform: min_max
type: mean
entity_ids:
[% for sn in serial_numbers %] - sensor.envoy_202221032900_inverter_[[sn]]
[% endfor %]
# Panel/Inverter Power Share Sensors
template:
sensor:
[% for sn in serial_numbers %] - name: Envoy 202221032900 Inverter [[sn]] Power Share
unit_of_measurement: "%"
availability: "{{ states('sensor.envoy_inverter_average_power')|float > 5 }}"
state: >
{% if states('sensor.envoy_inverter_average_power')|float == 0 %}
undefined
{% else %}
{{ (100 *
states('sensor.envoy_202221032900_inverter_[[sn]]')|float
/ states('sensor.envoy_inverter_average_power')|float
) | round(1)
}}
{% endif %}
[% endfor %]
'''
def main():
"""Generate Power Share Sensor Section for the YAML File."""
env = j2.Environment(
block_start_string='[%',
block_end_string='%]',
variable_start_string='[[',
variable_end_string=']]',
comment_start_string='[#',
comment_end_string='#]',
)
tmpl = env.from_string(POWER_SHARE_SENSORS)
sys.stdout.write(tmpl.render(serial_numbers=INVERTER_SNS))
if __name__ == '__main__':
main()