From 25d38899f37cea630e8650d62fd55efbea86f91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Karamati=C4=87?= Date: Thu, 26 Dec 2024 20:33:56 +0100 Subject: [PATCH] Enphase: support for sparse production.json In some cases production.json does not list CT meters, not even as a disabled resource. To support that use case, we need to check the length of array before iterating on, potentially non-existing, keys. --- templates/definition/meter/enphase.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/definition/meter/enphase.yaml b/templates/definition/meter/enphase.yaml index dbb9f6b1ad..581e4c677d 100644 --- a/templates/definition/meter/enphase.yaml +++ b/templates/definition/meter/enphase.yaml @@ -41,7 +41,7 @@ render: | password: {{ .token }} insecure: true {{- end }} - jq: if .production[] | select(.measurementType == "production").activeCount >= 1 then .production[] | select(.measurementType == "production").wNow else .production[] | select(.type == "inverters").wNow end + jq: if (.production | length) > 1 and (.production[] | select(.measurementType == "production").activeCount >= 1) then .production[] | select(.measurementType == "production").wNow else .production[] | select(.type == "inverters").wNow end energy: source: http uri: http://{{ .host }}/production.json @@ -51,7 +51,7 @@ render: | password: {{ .token }} insecure: true {{- end }} - jq: if .production[] | select(.measurementType == "production").activeCount >= 1 then .production[] | select(.measurementType == "production").whLifetime else .production[] | select(.type == "inverters").whLifetime end + jq: if (.production | length) > 1 and (.production[] | select(.measurementType == "production").activeCount >= 1) then .production[] | select(.measurementType == "production").whLifetime else .production[] | select(.type == "inverters").whLifetime end scale: 0.001 {{- end }} {{- if eq .usage "battery" }}