diff --git a/templates/definition/charger/daheimladen-pro.yaml b/templates/definition/charger/daheimladen-pro.yaml index 8b8b7e7b0..56b4e2a25 100644 --- a/templates/definition/charger/daheimladen-pro.yaml +++ b/templates/definition/charger/daheimladen-pro.yaml @@ -13,5 +13,5 @@ params: default: 502 render: | type: daheimladen - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} phases1p3p: true diff --git a/templates/definition/charger/daheimladen.yaml b/templates/definition/charger/daheimladen.yaml index c009f10e9..461478990 100644 --- a/templates/definition/charger/daheimladen.yaml +++ b/templates/definition/charger/daheimladen.yaml @@ -15,4 +15,4 @@ params: default: 502 render: | type: daheimladen - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} diff --git a/templates/definition/charger/e3dc-rscp.yaml b/templates/definition/charger/e3dc-rscp.yaml index a62ccbe70..b25fbf799 100644 --- a/templates/definition/charger/e3dc-rscp.yaml +++ b/templates/definition/charger/e3dc-rscp.yaml @@ -47,7 +47,7 @@ params: advanced: true render: | type: e3dc-rscp - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} user: {{ .user }} password: {{ .password }} key: {{ .key }} diff --git a/templates/definition/charger/etrel-duo.yaml b/templates/definition/charger/etrel-duo.yaml index bfbc80341..38730a5a9 100644 --- a/templates/definition/charger/etrel-duo.yaml +++ b/templates/definition/charger/etrel-duo.yaml @@ -17,4 +17,4 @@ params: render: | type: etrel connector: {{ .connector }} - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} diff --git a/templates/definition/charger/etrel.yaml b/templates/definition/charger/etrel.yaml index 56201b9d9..24e4091f2 100644 --- a/templates/definition/charger/etrel.yaml +++ b/templates/definition/charger/etrel.yaml @@ -18,4 +18,4 @@ params: default: 502 render: | type: etrel - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} diff --git a/templates/definition/charger/homematic.yaml b/templates/definition/charger/homematic.yaml index 13223c8f8..9e0cdb4a7 100644 --- a/templates/definition/charger/homematic.yaml +++ b/templates/definition/charger/homematic.yaml @@ -58,7 +58,7 @@ params: - preset: switchsocket render: | type: homematic - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} device: {{ .device }} user: {{ .user }} password: {{ .password }} diff --git a/templates/definition/charger/kermi.yaml b/templates/definition/charger/kermi.yaml index 0580f60a6..f6634c5c3 100644 --- a/templates/definition/charger/kermi.yaml +++ b/templates/definition/charger/kermi.yaml @@ -25,7 +25,7 @@ render: | timeout: {{ .watchdog }} # re-write at timeout/2 set: source: modbus - uri: {{ .host }}:502 + uri: {{ joinHostPort .host "502" }} id: 40 # WP register: address: 301 # PV Überschussleistung @@ -34,7 +34,7 @@ render: | scale: 10.0 power: source: modbus - uri: {{ .host }}:502 + uri: {{ joinHostPort .host "502" }} id: 40 register: address: 108 @@ -44,7 +44,7 @@ render: | {{- if eq .tempsource "warmwater" }} temp: source: modbus - uri: {{ .host }}:502 + uri: {{ joinHostPort .host "502" }} id: 51 # TWE register: address: 100 @@ -53,7 +53,7 @@ render: | scale: 0.1 limittemp: source: modbus - uri: {{ .host }}:502 + uri: {{ joinHostPort .host "502" }} id: 51 # TWE register: address: 101 @@ -64,7 +64,7 @@ render: | {{- if eq .tempsource "buffer" }} temp: source: modbus - uri: {{ .host }}:502 + uri: {{ joinHostPort .host "502" }} id: 50 # Speicher register: address: 1 @@ -73,7 +73,7 @@ render: | scale: 0.1 limittemp: source: modbus - uri: {{ .host }}:502 + uri: {{ joinHostPort .host "502" }} id: 50 # Speicher register: address: 2 diff --git a/templates/definition/charger/lambda-zewotherm.yaml b/templates/definition/charger/lambda-zewotherm.yaml index eb3d7d5ab..7a9b23627 100644 --- a/templates/definition/charger/lambda-zewotherm.yaml +++ b/templates/definition/charger/lambda-zewotherm.yaml @@ -58,7 +58,7 @@ render: | initial: 0 set: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 register: address: 102 # PV Überschussleistung @@ -67,7 +67,7 @@ render: | scale: {{ if eq .excess "plus" }}1{{ else }}-1{{ end }} power: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 register: address: 103 # aktuelle Aufnahmeleistung [E] der WP @@ -75,7 +75,7 @@ render: | decode: int16 energy: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 register: address: 1020 # kumulierter Stromverbrauch (Energieaufnahme) [E / Wh] seit dem letzten Reset @@ -85,7 +85,7 @@ render: | {{- if .tempsource }} temp: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 register: address: {{ if eq .tempsource "warmwater_top" -}} 2002 {{ else if eq .tempsource "warmwater_bottom" -}} 2003 {{ else if eq .tempsource "buffer_top" -}} 3002 {{ else }} 3003 {{- end }} # 2002 Trinkwasser Oben, 2003 Trinkwasser Unten, 3002 Wärmespeicher Oben, 3003 Wärmespeicher Unten @@ -94,7 +94,7 @@ render: | scale: 0.1 limittemp: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 register: address: {{ if eq .tempsource "warmwater_top" -}} 2050 {{ else if eq .tempsource "warmwater_bottom" -}} 2050 {{ else if eq .tempsource "buffer_top" -}} 3050 {{ else }} 3050 {{- end }} # 2050 Trinkwasser Speicher, 3050 Wärmespeicher diff --git a/templates/definition/charger/ochsner-bwwp.yaml b/templates/definition/charger/ochsner-bwwp.yaml index cd0126dc6..c1b8c3621 100644 --- a/templates/definition/charger/ochsner-bwwp.yaml +++ b/templates/definition/charger/ochsner-bwwp.yaml @@ -20,7 +20,7 @@ render: | source: delta # nur Differenz zu der von WP berechneten Überschussleistung (Reg. 2012) get: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} register: address: 2012 # totale von der WP berechnete Überschussleistung Auflösung 1 W @@ -28,7 +28,7 @@ render: | decode: int16 set: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} register: address: 2201 # SUR Überschussleistung Auflösung 1 W @@ -36,7 +36,7 @@ render: | decode: int16 temp: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} register: address: 2000 # angezeigte Temperatur Auflösung 0,1°C @@ -45,7 +45,7 @@ render: | scale: 0.1 limittemp: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} register: address: 2203 # Legionellen/Überschuss Solltemperatur Auflösung 0,1°C diff --git a/templates/definition/charger/wallbe-meter.yaml b/templates/definition/charger/wallbe-meter.yaml index 6561fc936..292bb5667 100644 --- a/templates/definition/charger/wallbe-meter.yaml +++ b/templates/definition/charger/wallbe-meter.yaml @@ -19,7 +19,7 @@ params: default: 502 render: | type: wallbe - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} meter: # only if a charge meter is connected to the controller power: true energy: true diff --git a/templates/definition/charger/wallbe-pre2019-meter.yaml b/templates/definition/charger/wallbe-pre2019-meter.yaml index 4f9694bc2..db7ddfaac 100644 --- a/templates/definition/charger/wallbe-pre2019-meter.yaml +++ b/templates/definition/charger/wallbe-pre2019-meter.yaml @@ -19,7 +19,7 @@ params: default: 502 render: | type: wallbe - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} legacy: true # set only for older Wallbe devices (pre ~2019, old controller firmware) meter: # only if a charge meter is connected to the controller power: true diff --git a/templates/definition/charger/wallbe-pre2019.yaml b/templates/definition/charger/wallbe-pre2019.yaml index 872731861..4004b3e68 100644 --- a/templates/definition/charger/wallbe-pre2019.yaml +++ b/templates/definition/charger/wallbe-pre2019.yaml @@ -19,5 +19,5 @@ params: default: 502 render: | type: wallbe - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} legacy: true # set only for older Wallbe devices (pre ~2019, old controller firmware) diff --git a/templates/definition/charger/wallbe.yaml b/templates/definition/charger/wallbe.yaml index 7888d8e88..5bd293daa 100644 --- a/templates/definition/charger/wallbe.yaml +++ b/templates/definition/charger/wallbe.yaml @@ -17,4 +17,4 @@ params: default: 502 render: | type: wallbe - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} diff --git a/templates/definition/charger/webasto-next.yaml b/templates/definition/charger/webasto-next.yaml index df7e64e9e..fc8fecbf4 100644 --- a/templates/definition/charger/webasto-next.yaml +++ b/templates/definition/charger/webasto-next.yaml @@ -18,4 +18,4 @@ params: default: 502 render: | type: webasto-next - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} diff --git a/templates/definition/charger/weidmüller.yaml b/templates/definition/charger/weidmüller.yaml index e2e9d84c4..64ebad857 100644 --- a/templates/definition/charger/weidmüller.yaml +++ b/templates/definition/charger/weidmüller.yaml @@ -10,4 +10,4 @@ params: - name: host render: | type: weidmüller - uri: {{ .host }}:502 + uri: {{ joinHostPort .host "502" }} diff --git a/templates/definition/meter/dsmr.yaml b/templates/definition/meter/dsmr.yaml index ff60c547b..d3803b656 100644 --- a/templates/definition/meter/dsmr.yaml +++ b/templates/definition/meter/dsmr.yaml @@ -18,7 +18,7 @@ params: type: string render: | type: dsmr - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} {{- if .energy }} energy: {{ .energy }} {{- end }} diff --git a/templates/definition/meter/e3dc-modbus.yaml b/templates/definition/meter/e3dc-modbus.yaml index dbf566017..189361cea 100644 --- a/templates/definition/meter/e3dc-modbus.yaml +++ b/templates/definition/meter/e3dc-modbus.yaml @@ -14,7 +14,7 @@ render: | {{- if eq .usage "grid" }} power: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: type: holding decode: int32s @@ -25,13 +25,13 @@ render: | source: calc add: - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: type: holding decode: int32s address: 40067 # Photovoltaikleistung in Watt - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: type: holding decode: int32s @@ -41,7 +41,7 @@ render: | {{- if eq .usage "battery" }} power: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: type: holding decode: int32s @@ -49,7 +49,7 @@ render: | scale: -1 # reverse direction soc: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 40082 # Batterie-SOC in % type: holding diff --git a/templates/definition/meter/e3dc-rscp.yaml b/templates/definition/meter/e3dc-rscp.yaml index 8163716cc..1c242eec2 100644 --- a/templates/definition/meter/e3dc-rscp.yaml +++ b/templates/definition/meter/e3dc-rscp.yaml @@ -67,7 +67,7 @@ params: render: | type: e3dc-rscp usage: {{ .usage }} - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} user: {{ .user }} password: {{ .password }} key: {{ .key }} diff --git a/templates/definition/meter/fronius-gen24.yaml b/templates/definition/meter/fronius-gen24.yaml index 6a97859c1..1bec978f0 100644 --- a/templates/definition/meter/fronius-gen24.yaml +++ b/templates/definition/meter/fronius-gen24.yaml @@ -40,7 +40,7 @@ render: | {{- if eq .usage "grid" }} power: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:W @@ -49,7 +49,7 @@ render: | - 213:W energy: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:TotWhImp @@ -59,7 +59,7 @@ render: | scale: 0.001 currents: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:AphA @@ -67,7 +67,7 @@ render: | - 203:AphA - 213:AphA - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:AphB @@ -75,7 +75,7 @@ render: | - 203:AphB - 213:AphB - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:AphC @@ -84,7 +84,7 @@ render: | - 213:AphC voltages: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:PhVphA @@ -92,7 +92,7 @@ render: | - 203:PhVphA - 213:PhVphA - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:PhVphB @@ -100,7 +100,7 @@ render: | - 203:PhVphB - 213:PhVphB - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:PhVphC @@ -109,7 +109,7 @@ render: | - 213:PhVphC powers: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:WphA @@ -117,7 +117,7 @@ render: | - 203:WphA - 213:WphA - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:WphB @@ -125,7 +125,7 @@ render: | - 203:WphB - 213:WphB - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:WphC @@ -138,23 +138,23 @@ render: | source: calc add: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:1:DCW # mppt 1 - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:2:DCW # mppt 2 energy: source: calc add: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:1:DCWH # mppt 1 scale: 0.001 - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:2:DCWH # mppt 2 scale: 0.001 @@ -165,23 +165,23 @@ render: | source: calc add: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:3:DCW # mppt 3 charge scale: -1 - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:4:DCW # mppt 4 discharge energy: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:4:DCWH # mppt 4 (discharge) scale: 0.001 soc: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:ChaState batterymode: # model 124 @@ -195,14 +195,14 @@ render: | value: 0 set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:StorCtl_Mod - source: const value: 100 # % set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:OutWRte - case: 2 # hold @@ -213,14 +213,14 @@ render: | value: 2 set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:StorCtl_Mod - source: const value: 0 # % set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:OutWRte - case: 3 # charge @@ -231,21 +231,21 @@ render: | value: 1 # off set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:ChaGriSet - source: const value: 2 set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:StorCtl_Mod - source: const value: {{ if .maxchargerate }}-{{ .maxchargerate }}{{ end }} # % set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:OutWRte {{- include "battery-params" . }} diff --git a/templates/definition/meter/fronius-vertoplus.yaml b/templates/definition/meter/fronius-vertoplus.yaml index 77cca6b3e..b85653940 100644 --- a/templates/definition/meter/fronius-vertoplus.yaml +++ b/templates/definition/meter/fronius-vertoplus.yaml @@ -27,7 +27,7 @@ render: | {{- if eq .usage "grid" }} power: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:W @@ -36,7 +36,7 @@ render: | - 213:W energy: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:TotWhImp @@ -46,7 +46,7 @@ render: | scale: 0.001 currents: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:AphA @@ -54,7 +54,7 @@ render: | - 203:AphA - 213:AphA - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:AphB @@ -62,7 +62,7 @@ render: | - 203:AphB - 213:AphB - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:AphC @@ -71,7 +71,7 @@ render: | - 213:AphC voltages: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:PhVphA @@ -79,7 +79,7 @@ render: | - 203:PhVphA - 213:PhVphA - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:PhVphB @@ -87,7 +87,7 @@ render: | - 203:PhVphB - 213:PhVphB - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:PhVphC @@ -96,7 +96,7 @@ render: | - 213:PhVphC powers: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:WphA @@ -104,7 +104,7 @@ render: | - 203:WphA - 213:WphA - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:WphB @@ -112,7 +112,7 @@ render: | - 203:WphB - 213:WphB - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:WphC @@ -125,32 +125,32 @@ render: | source: calc add: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:1:DCW # mppt 1 - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:2:DCW # mppt 2 - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:3:DCW # mppt 3 energy: source: calc add: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:1:DCWH # mppt 1 scale: 0.001 - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:2:DCWH # mppt 2 scale: 0.001 - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:3:DCWH # mppt 3 scale: 0.001 @@ -161,23 +161,23 @@ render: | source: calc add: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:4:DCW # mppt 4 charge scale: -1 - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:5:DCW # mppt 5 discharge energy: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 160:5:DCWH # mppt 5 (discharge) scale: 0.001 soc: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:ChaState batterymode: # model 124 @@ -191,14 +191,14 @@ render: | value: 0 set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:StorCtl_Mod - source: const value: 100 # % set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:OutWRte - case: 2 # hold @@ -209,14 +209,14 @@ render: | value: 2 set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:StorCtl_Mod - source: const value: 0 # % set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:OutWRte - case: 3 # charge @@ -227,21 +227,21 @@ render: | value: 1 # off set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:ChaGriSet - source: const value: 2 set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:StorCtl_Mod - source: const value: -{{ .maxchargerate }} # % set: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 value: 124:0:OutWRte {{- include "battery-params" . }} diff --git a/templates/definition/meter/hager-flow-modbus.yaml b/templates/definition/meter/hager-flow-modbus.yaml index 903613276..9b2989566 100644 --- a/templates/definition/meter/hager-flow-modbus.yaml +++ b/templates/definition/meter/hager-flow-modbus.yaml @@ -29,21 +29,21 @@ render: | currents: - source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 4099 # Netz Ampere L1 | Grid amps L1 type: holding decode: uint16 - source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 4100 # Netz Ampere L2 | Grid amps L2 type: holding decode: uint16 - source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 4101 # Netz Ampere L3 | Grid amps L3 type: holding @@ -51,7 +51,7 @@ render: | power: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: type: holding decode: int32 @@ -63,7 +63,7 @@ render: | add: - source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: type: holding decode: uint32 @@ -73,7 +73,7 @@ render: | power: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: type: holding decode: int32 @@ -82,7 +82,7 @@ render: | soc: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 4146 # Batterie-SOC in % type: holding diff --git a/templates/definition/meter/huawei-emma.yaml b/templates/definition/meter/huawei-emma.yaml index b4374ee93..9feef6c89 100644 --- a/templates/definition/meter/huawei-emma.yaml +++ b/templates/definition/meter/huawei-emma.yaml @@ -15,7 +15,7 @@ render: | power: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 31657 # Active power of built-in electric energy sensor type: holding @@ -23,7 +23,7 @@ render: | energy: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 31679 # Total negative active energy of built-in electric energy sensor type: holding @@ -32,7 +32,7 @@ render: | currents: - source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 31651 # Huawei phase A grid current type: holding @@ -40,7 +40,7 @@ render: | scale: 0.1 - source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 31653 # Huawei phase B grid current type: holding @@ -48,7 +48,7 @@ render: | scale: 0.1 - source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 31655 # Huawei phase C grid current type: holding @@ -59,7 +59,7 @@ render: | power: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 30354 # Active power type: holding @@ -67,7 +67,7 @@ render: | energy: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 30344 # E-Total type: holding @@ -78,7 +78,7 @@ render: | power: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 30360 type: holding @@ -87,7 +87,7 @@ render: | energy: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 30312 # Total discharge type: holding @@ -96,7 +96,7 @@ render: | soc: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 30368 type: holding diff --git a/templates/definition/meter/huawei-smartlogger.yaml b/templates/definition/meter/huawei-smartlogger.yaml index 40001ae51..e18e2f7d2 100644 --- a/templates/definition/meter/huawei-smartlogger.yaml +++ b/templates/definition/meter/huawei-smartlogger.yaml @@ -61,7 +61,7 @@ render: | power: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 40521 # Active power type: holding @@ -69,7 +69,7 @@ render: | energy: source: modbus id: 0 - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} register: address: 40560 # E-Total type: holding diff --git a/templates/definition/meter/rct-power.yaml b/templates/definition/meter/rct-power.yaml index dcf6405df..c53b05b1b 100644 --- a/templates/definition/meter/rct-power.yaml +++ b/templates/definition/meter/rct-power.yaml @@ -41,7 +41,7 @@ params: default: 30s render: | type: rct - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} usage: {{ .usage }} cache: {{ .cache }} {{- include "battery-params" . }} diff --git a/templates/definition/meter/sigenergy.yaml b/templates/definition/meter/sigenergy.yaml index bfa52d1eb..cfa5441f2 100644 --- a/templates/definition/meter/sigenergy.yaml +++ b/templates/definition/meter/sigenergy.yaml @@ -29,7 +29,7 @@ render: | {{- if eq .usage "grid" }} power: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 247 register: address: 30005 # [Grid sensor] Active power @@ -37,7 +37,7 @@ render: | decode: int32 energy: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} register: address: 30562 # Accumulated import energy @@ -46,7 +46,7 @@ render: | scale: 0.01 currents: - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} register: address: 31017 # Phase A current @@ -54,7 +54,7 @@ render: | decode: int32 scale: 0.01 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} register: address: 31019 # Phase B current @@ -62,7 +62,7 @@ render: | decode: int32 scale: 0.01 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} register: address: 31021 # Phase C current @@ -73,7 +73,7 @@ render: | {{- if eq .usage "pv" }} power: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 247 register: type: holding @@ -84,7 +84,7 @@ render: | {{- if eq .usage "battery" }} power: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 247 register: type: holding @@ -93,7 +93,7 @@ render: | scale: -1 energy: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} register: address: 30574 # Battery accumulated discharge energy @@ -102,7 +102,7 @@ render: | scale: 0.01 soc: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 247 register: address: 30014 # Energy storage system SOC @@ -114,7 +114,7 @@ render: | convert: float2int set: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 247 register: address: 40048 # Discharge Cut-Off SoC diff --git a/templates/definition/meter/solarlog.yaml b/templates/definition/meter/solarlog.yaml index cae9462f6..1093a0258 100644 --- a/templates/definition/meter/solarlog.yaml +++ b/templates/definition/meter/solarlog.yaml @@ -23,7 +23,7 @@ render: | source: calc add: - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 register: address: 3502 # Pac @@ -31,7 +31,7 @@ render: | decode: uint32s scale: -1 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 register: address: 3518 # Pac consumption @@ -41,7 +41,7 @@ render: | {{- if eq .usage "pv" }} power: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 register: address: 3502 # Pac @@ -49,7 +49,7 @@ render: | decode: uint32s energy: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 1 register: address: 3516 # total yield diff --git a/templates/definition/meter/sunspec-meter.yaml b/templates/definition/meter/sunspec-meter.yaml index 0cc7fac26..f3af86bb5 100644 --- a/templates/definition/meter/sunspec-meter.yaml +++ b/templates/definition/meter/sunspec-meter.yaml @@ -18,7 +18,7 @@ render: | {{- if or (eq .usage "grid") (eq .usage "charge") }} power: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:W @@ -29,7 +29,7 @@ render: | - 213:W energy: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:TotWhImp @@ -41,7 +41,7 @@ render: | scale: 0.001 currents: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:AphA @@ -51,7 +51,7 @@ render: | - 203:AphA - 213:AphA - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:AphB @@ -61,7 +61,7 @@ render: | - 203:AphB - 213:AphB - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:AphC @@ -72,7 +72,7 @@ render: | - 213:AphC voltages: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:PhVphA @@ -82,7 +82,7 @@ render: | - 203:PhVphA - 213:PhVphA - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:PhVphB @@ -92,7 +92,7 @@ render: | - 203:PhVphB - 213:PhVphB - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:PhVphC @@ -103,7 +103,7 @@ render: | - 213:PhVphC powers: - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:WphA @@ -113,7 +113,7 @@ render: | - 203:WphA - 213:WphA - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:WphB @@ -123,7 +123,7 @@ render: | - 203:WphB - 213:WphB - source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:WphC @@ -136,7 +136,7 @@ render: | {{- if eq .usage "pv" }} power: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:W @@ -147,7 +147,7 @@ render: | - 213:W energy: source: sunspec - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .id }} value: - 201:TotWhExp diff --git a/templates/definition/meter/varta.yaml b/templates/definition/meter/varta.yaml index 420cc2a6f..c010a49f7 100644 --- a/templates/definition/meter/varta.yaml +++ b/templates/definition/meter/varta.yaml @@ -35,7 +35,7 @@ render: | type: custom power: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} {{- if eq .usage "grid" }} id: 255 register: @@ -60,7 +60,7 @@ render: | scale: -1 soc: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 255 register: address: 1068 # SOC @@ -81,7 +81,7 @@ render: | value: -{{- .maxdischargepower }} # value must be negative set: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 255 register: address: 1074 # max discharge power @@ -95,7 +95,7 @@ render: | value: 0 set: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 255 register: address: 1074 # max discharge power diff --git a/templates/definition/meter/victron-energy.yaml b/templates/definition/meter/victron-energy.yaml index 5142acb4a..4234c1be0 100644 --- a/templates/definition/meter/victron-energy.yaml +++ b/templates/definition/meter/victron-energy.yaml @@ -32,21 +32,21 @@ render: | source: calc add: - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 820 # L1 grid power type: input decode: int16 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 821 # L2 grid power type: input decode: int16 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 822 # L3 grid power @@ -55,7 +55,7 @@ render: | {{- if .meterid }} currents: - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .meterid }} register: address: 2617 # L1 grid current @@ -63,7 +63,7 @@ render: | decode: int16 scale: 0.1 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .meterid }} register: address: 2619 # L2 grid current @@ -71,7 +71,7 @@ render: | decode: int16 scale: 0.1 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: {{ .meterid }} register: address: 2621 # L3 grid current @@ -85,49 +85,49 @@ render: | source: calc add: - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 808 # ACout pv power L1 type: input decode: uint16 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 809 # ACout pv power L2 type: input decode: uint16 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 810 # ACout pv power L3 type: input decode: uint16 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 811 # ACin pv power L1 type: input decode: uint16 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 812 # ACin pv power L2 type: input decode: uint16 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 813 # ACin pv power L3 type: input decode: uint16 - source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 850 # DC pv power @@ -138,7 +138,7 @@ render: | {{- if eq .usage "battery" }} power: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 842 # active DC power @@ -147,7 +147,7 @@ render: | scale: -1 soc: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 843 # Soc @@ -158,7 +158,7 @@ render: | convert: float2int set: source: modbus - uri: {{ .host }}:{{ .port }} + uri: {{ joinHostPort .host .port }} id: 100 # com.victronenergy.system register: address: 2901 # limit soc diff --git a/util/templates/includes/mqtt.tpl b/util/templates/includes/mqtt.tpl index 4200a544b..f4472655c 100644 --- a/util/templates/includes/mqtt.tpl +++ b/util/templates/includes/mqtt.tpl @@ -1,5 +1,5 @@ {{ define "mqtt" }} -broker: {{ .host }}:{{ .port }} +broker: {{ joinHostPort .host .port }} {{- if .user }} user: {{ .user }} {{- end }} diff --git a/util/templates/modbus.tpl b/util/templates/modbus.tpl index 5ce1a4eb2..b46136e26 100644 --- a/util/templates/modbus.tpl +++ b/util/templates/modbus.tpl @@ -7,15 +7,15 @@ baudrate: {{ .baudrate }} comset: {{ .comset }} {{- else if or (eq .modbus "rs485tcpip") .rs485tcpip }} # RS485 via TCP/IP (Modbus RTU) -uri: {{ .host }}:{{ .port }} +uri: {{ joinHostPort .host .port }} rtu: true {{- else if or (eq .modbus "tcpip") .tcpip }} # Modbus TCP -uri: {{ .host }}:{{ .port }} +uri: {{ joinHostPort .host .port }} rtu: false {{- else if or (eq .modbus "udp") .udp }} # Modbus UDP -uri: {{ .host }}:{{ if (ne .port "502") }}{{ .port }}{{ else }}8899{{ end }} +uri: {{ joinHostPort .host .port }} udp: true rtu: true {{- else }} diff --git a/util/templates/utils.go b/util/templates/utils.go index 8aa5a5fbe..429fdfc4b 100644 --- a/util/templates/utils.go +++ b/util/templates/utils.go @@ -3,6 +3,7 @@ package templates import ( "bytes" "fmt" + "net" "net/url" "strings" "text/template" @@ -70,6 +71,13 @@ func FuncMap(tmpl *template.Template) *template.Template { "timeRound": func(t time.Time, d time.Duration) time.Time { return t.Round(d) }, + "joinHostPort": func(host, port string) string { + res := net.JoinHostPort(host, port) + if strings.Contains(host, ":") { + return `"` + res + `"` + } + return res + }, "urlEncode": url.QueryEscape, "unquote": unquote, "quote": yamlQuote,