From 263b3df5038cc1d545fdc31bbb996efcc222cfc8 Mon Sep 17 00:00:00 2001 From: fboundy Date: Wed, 13 Sep 2023 17:07:33 +0100 Subject: [PATCH] Times and Control Switch --- .gitignore | 1 + inputs.yaml | 3 ++ scripts.yaml | 32 +++++++++++++ solis-template.yaml | 30 ++++++++++++ solis.yaml | 114 ++++++++++++++++++++++++++++++++++++++++++++ umodbus_test.py | 40 ++++++++-------- 6 files changed, 200 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index c641d03..e8d5f6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ deleted_from_storgae.txt umodbus_scan.py ha_solis_modbus.code-workspace +.vscode/settings.json diff --git a/inputs.yaml b/inputs.yaml index 48a9147..9c228c9 100644 --- a/inputs.yaml +++ b/inputs.yaml @@ -29,6 +29,9 @@ input_boolean: solis_storage_mode_spontaneous: name: Solis Storage Mode - Spontaneous + solis_storage_mode_feed_in_priority: + name: Solis Storage Mode - Feed-In Priority + input_datetime: economy_7_start: name: Economy 7 Start diff --git a/scripts.yaml b/scripts.yaml index 844ec6a..fc79f57 100644 --- a/scripts.yaml +++ b/scripts.yaml @@ -1,6 +1,22 @@ set_solis_storage_toggles: alias: Set Solis Storage Toggles sequence: + - if: + - condition: template + value_template: + "{{states('sensor.solis_energy_storage_control_switch') | + int | bitwise_and(64) == 64}}" + then: + - service: input_boolean.turn_on + data: {} + target: + entity_id: + - input_boolean.solis_storage_mode_feed_in_priority + else: + - service: input_boolean.turn_off + data: {} + target: + entity_id: input_boolean.solis_storage_mode_feed_in_priority - if: - condition: template value_template: @@ -97,6 +113,22 @@ set_solis_storage_toggles: - input_boolean.solis_storage_mode_spontaneous mode: single icon: mdi:toggle-switch-off-outline +solis_set_time: + alias: Solis Set Time + sequence: + - service: script.solis_write_holding_register + data: + register_addr: 43003 + register_value: '{{now().hour}}' + - service: script.solis_write_holding_register + data: + register_addr: 43004 + register_value: '{{now().minute}}' + - service: script.solis_write_holding_register + data: + register_addr: 43005 + register_value: '{{now().second}}' + mode: single solis_set_energy_storage_mode: alias: Solis Set Energy Storage Mode fields: diff --git a/solis-template.yaml b/solis-template.yaml index b7af9f7..d7f4a98 100644 --- a/solis-template.yaml +++ b/solis-template.yaml @@ -1,5 +1,34 @@ template: - sensor: + - name: Solis Date Time (Read Only) + unique_id: solis_date_time_ro + device_class: timestamp + state: >- + {% set y = states('sensor.solis_year_ro')%} + {% set m = states('sensor.solis_month_ro')%} + {% set d = states('sensor.solis_day_ro')%} + {% set h = states('sensor.solis_hour_ro')%} + {% set t = states('sensor.solis_minute_ro')%} + + {% set dt = y + "-" + m + "-" + d + " " + h + ":" + t %} + + {{as_local(strptime(dt, "%y-%m-%d %H:%M"))}} + + - name: Solis Date Time (Read/Write) + unique_id: solis_date_time_rw + device_class: timestamp + state: >- + {% set y = states('sensor.solis_year_rw')%} + {% set m = states('sensor.solis_month_rw')%} + {% set d = states('sensor.solis_day_rw')%} + {% set h = states('sensor.solis_hour_rw')%} + {% set t = states('sensor.solis_minute_rw')%} + {% set s = states('sensor.solis_second_rw')%} + + {% set dt = y + "-" + m + "-" + d + " " + h + ":" + t + ":" + s %} + + {{as_local(strptime(dt, "%y-%m-%d %H:%M:%S"))}} + - name: "Solis Grid Active Power (Negative)" unique_id: "Solis Grid Active Power (Negative)" unit_of_measurement: W @@ -53,6 +82,7 @@ template: + 8 * (states('input_boolean.solis_storage_mode_wake_up') == 'on') | int + 16 * (states('input_boolean.solis_storage_mode_backup') == 'on') | int + 32 * (states('input_boolean.solis_storage_mode_grid_charge') == 'on') | int + + 64 * (states('input_boolean.solis_solis_storage_mode_feed_in_priority') == 'on') | int }} - name: "Solis Eco7 Time Remaining" diff --git a/solis.yaml b/solis.yaml index ac59388..dbeed58 100644 --- a/solis.yaml +++ b/solis.yaml @@ -5,6 +5,120 @@ # port: 8899 # for DLS-L sticks sensors: + - name: Solis Year RO + slave: 1 + address: 33022 + count: 1 + scale: 1 + input_type: input + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + - name: Solis Month RO + slave: 1 + address: 33023 + count: 1 + scale: 1 + input_type: input + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + - name: Solis Day RO + slave: 1 + address: 33024 + count: 1 + scale: 1 + input_type: input + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + - name: Solis Hour RO + slave: 1 + address: 33025 + count: 1 + scale: 1 + input_type: input + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + - name: Solis Minute RO + slave: 1 + address: 33026 + count: 1 + scale: 1 + input_type: input + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + + - name: Solis Year RW + slave: 1 + address: 43000 + count: 1 + scale: 1 + input_type: holding + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + - name: Solis Month RW + slave: 1 + address: 43001 + count: 1 + scale: 1 + input_type: holding + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + - name: Solis Day RW + slave: 1 + address: 43002 + count: 1 + scale: 1 + input_type: holding + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + - name: Solis Hour RW + slave: 1 + address: 43003 + count: 1 + scale: 1 + input_type: holding + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + - name: Solis Minute RW + slave: 1 + address: 43004 + count: 1 + scale: 1 + input_type: holding + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + - name: Solis Second RW + slave: 1 + address: 43005 + count: 1 + scale: 1 + input_type: holding + data_type: uint16 + lazy_error_count: 5 + scan_interval: 60 + state_class: measurement + + + # Temperature - name: Solis Temperature slave: 1 address: 33093 diff --git a/umodbus_test.py b/umodbus_test.py index f62e983..061bfa2 100644 --- a/umodbus_test.py +++ b/umodbus_test.py @@ -1,4 +1,4 @@ -#%% +# %% # This script will test umodbus comms to a Solis Hybrid Inverter with a DLS-L LAN Data Logger # # It requires the umodbus module @@ -11,24 +11,24 @@ # configuration CFG = { - 'Waveshare': { - 'IP': "192.168.4.40", - 'PORT': 502, + "Waveshare": { + "IP": "192.168.4.40", + "PORT": 502, + }, + "S2-WL": { + "IP": "192.168.4.237", + "PORT": 502, + }, + "DLS-L": { + "IP": "192.168.4.79", + "PORT": 8899, }, - - 'S2-WL': { - 'IP': "192.168.4.237", - 'PORT': 502, - }, - - 'DLS-L': { - 'IP': "192.168.4.79", - 'PORT': 8899, - } - } # Update with your inverter IP -devices = ['S2-WL', 'Waveshare', ] +devices = [ + # 'S2-WL', + "Waveshare", +] payloads = [ { @@ -66,9 +66,9 @@ sock = {} for device in devices: sock[device] = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock[device].connect((CFG[device]['IP'], CFG[device]['PORT'])) + sock[device].connect((CFG[device]["IP"], CFG[device]["PORT"])) print(f"Device: {device}") - print('-' * 32 + '\n') + print("-" * 32 + "\n") for payload in payloads: message = tcp.read_input_registers(slave_id=1, starting_address=payload["addrs"], quantity=payload["len"]) response = tcp.send_message(message, sock[device]) @@ -76,6 +76,6 @@ print(f"{(payload['desc']+':'):25s}{val:5.1f} {payload['uom']}") print("\n\n") - sock[device].close() - + sock[device].close() + # %%