Skip to content

Commit eb2e576

Browse files
committed
added run_unendless configuration option
1 parent b8d7986 commit eb2e576

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
# SolisCloud to PVOutput, Domoticz and/or MQTT Broker (e.g. HomeAssistant, ioBroker)
1616
Simple Python3 script to copy latest (normally once per 5 minutes) SolisCloud portal inverter update to PVOutput portal, Domoticz, and/or MQTT Broker (e.g. HomeAssistant, ioBroker).
17+
Python 3.6 or higher is required.
1718

1819
The soliscloud_to_pvoutput.py script will get the station id via the configured soliscloud_station_index (default the first station) with the secrets of SolisCloud (see next section). Thereafter it will get the inverter id and serial number via the configured soliscloud_inverter_index (default the first inverter). Then in an endless loop the inverter details are fetched and the following information is used:
1920
* timestamp
@@ -28,12 +29,12 @@ The soliscloud_to_pvoutput.py script will get the station id via the configured
2829
This information is used to compute the new information to be send to PVOutput and/or Domoticz, when the timestamp is changed.
2930

3031
Notes
31-
* only between 5 and 23 hour data is fetched from SolisCloud and copied to PVOutput and/or Domoticz
32-
* the script will exit outside 5 and 23
33-
* Each new day the "watthour today" starts with 0
34-
* Because the resolution of the SolisCloud watthour is in 100 Watt, a higher resolution is computed with current Watt
32+
* the script will exit outside 5 and 23, unless you have configured "run_unendless = True" in soliscloud_to_pvoutput.cfg
33+
* each new day the "watthour today" starts with 0
34+
* because the resolution of the SolisCloud watthour is in 100 Watt, a higher resolution is computed with current Watt
3535
* if you have more than 1 station [you need to configure each inverter in different directories](#configuration-with-multiple-inverters-in-one-soliscloud-station)
36-
* If you have more than 4 strings or a 3 phase inverter, you need to adapt the script (sorry, not supported yet)
36+
* if you have more than 4 strings or a 3 phase inverter, you need to adapt the script (sorry, not supported yet)
37+
* there is a dependency to package paho_mqtt, you need to install this e.g. by command "python3 -m pip install paho_mqtt==1.6.1"
3738

3839
## SolisCloud
3940
[SolisCloud](https://www.soliscloud.com/) is the next generation Portal for Solis branded PV systems from Ginlong.
@@ -83,6 +84,7 @@ soliscloud_station_index = 0
8384
soliscloud_inverter_index = 0
8485
pvoutput_api_key = 0f2dd8190d00369ec893b059034dde1123456789
8586
pvoutput_system_id = 12345
87+
run_unendless = False
8688
8789
[PVOutput]
8890
send_to_pvoutput = True
@@ -155,8 +157,10 @@ soliscloud_to_pvoutput.py scripts runs on my Raspberry pi with Raspbian GNU/Linu
155157
Steps:
156158
* create a directory solis in your home directory
157159
* copy solis.sh, soliscloud_to_pvoutput.py, soliscloud_to_pvoutput.cfg and logging_config.ini in this solis directory
160+
* make sure there are no Windows CRLF in the copied files, e.g. make sure by running dos2unix on the copied files
161+
* if "python --version" refers to 2.x, then you need to change solis.sh to use python3 instead of python
158162
* change inside soliscloud_to_pvoutput.cfg the API secrets
159-
* chmod +x solis.sh
163+
* chmod +r+x solis.sh
160164
* add the following line in your crontab -e:
161165

162166
```

soliscloud_to_pvoutput.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ soliscloud_station_index = 0
66
soliscloud_inverter_index = 0
77
pvoutput_api_key = 0f2dd8190d00369ec893b059034dde1123456789
88
pvoutput_system_id = 12345
9+
run_unendless = False
910

1011
[PVOutput]
1112
send_to_pvoutput = True

soliscloud_to_pvoutput.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def get_bool(dictionary: dict, key: str, default: bool = True) -> bool:
6666
SOLISCLOUD_INVERTER_INDEX = int(get(api_secrets, "soliscloud_inverter_index", "0"))
6767
PVOUTPUT_API_KEY = get(api_secrets, "pvoutput_api_key")
6868
PVOUTPUT_SYSTEM_ID = get(api_secrets, "pvoutput_system_id")
69+
RUN_UNENDLESS = get_bool(api_secrets, "run_unendless", False)
6970

7071
SOLISCLOUD_INVERTER_SN = "SN" # to be filled later by program
7172

@@ -142,9 +143,6 @@ def get_bool(dictionary: dict, key: str, default: bool = True) -> bool:
142143
PVOUTPUT_ADD_URL = "http://pvoutput.org/service/r2/addbatchstatus.jsp"
143144

144145

145-
TODAY = datetime.now().strftime("%Y%m%d") # format yyyymmdd
146-
147-
148146
# == post ====================================================================
149147
def execute_request(url: str, data: str, headers: dict) -> str:
150148
"""execute request and handle errors"""
@@ -378,13 +376,20 @@ def do_work():
378376
time.sleep(60)
379377
timestamp_previous = "0"
380378
energy_generation = 0
379+
today_yyymmdd = datetime.now().strftime("%Y%m%d") # format yyyymmdd
381380
while True:
382381
time.sleep(60) # wait 1 minute before checking again
383382
datetime_now = datetime.now()
384-
# only check between 5 and 23 hours
385-
if datetime_now.hour < 5 or datetime_now.hour > 22:
386-
logging.info("Outside solar generation hours (5..23)")
387-
sys.exit("Exiting program to start fresh tomorrow")
383+
if RUN_UNENDLESS:
384+
if datetime_now.hour == 0 and datetime_now.minute < 4: # reset needed
385+
timestamp_previous = "0"
386+
energy_generation = 0
387+
today_yyymmdd = datetime_now.strftime("%Y%m%d") # format yyyymmdd
388+
else:
389+
# only check between 5 and 23 hours
390+
if datetime_now.hour < 5 or datetime_now.hour > 22:
391+
logging.info("Outside solar generation hours (5..23)")
392+
sys.exit("Exiting program to start fresh tomorrow")
388393

389394
content = get_solis_cloud_data(INVERTER_DETAIL, inverter_detail_body)
390395
inverter_detail = json.loads(content)["data"]
@@ -444,7 +449,7 @@ def do_work():
444449

445450
current_time = datetime_current.strftime("%H:%M")
446451
if logging.DEBUG >= logging.root.level:
447-
debug_string = f"date={TODAY}, time={current_time}, energy_generation={energy_generation}, solar_power={solar_power}, battery_power={battery_power}, battery_soc={battery_soc}, grid_power={grid_power}, family_load={family_load}, home_consumption={home_consumption}, inverter_temperature={inverter_temperature}, dc_voltage={dc_voltage}, ac_voltage={ac_voltage}" # noqa
452+
debug_string = f"date={today_yyymmdd}, time={current_time}, energy_generation={energy_generation}, solar_power={solar_power}, battery_power={battery_power}, battery_soc={battery_soc}, grid_power={grid_power}, family_load={family_load}, home_consumption={home_consumption}, inverter_temperature={inverter_temperature}, dc_voltage={dc_voltage}, ac_voltage={ac_voltage}" # noqa
448453
logging.debug(debug_string)
449454

450455
if SEND_TO_PVOUTPUT:
@@ -475,7 +480,7 @@ def do_work():
475480
# Temperature No decimal celsius 23.4
476481
# Voltage No decimal volts 240.7
477482

478-
pvoutput_string = f"data={TODAY},{current_time},{energy_generation},{solar_power},{energy_consumption},{power_consumption},{temperature},{voltage}" # noqa
483+
pvoutput_string = f"data={today_yyymmdd},{current_time},{energy_generation},{solar_power},{energy_consumption},{power_consumption},{temperature},{voltage}" # noqa
479484
send_pvoutput_data(pvoutput_string)
480485

481486
if SEND_TO_DOMOTICZ:
@@ -495,7 +500,7 @@ def do_work():
495500
send_to_domoticz(DOMOTICZ_HOMECONSUMPTION_ID, str(home_consumption))
496501

497502
if SEND_TO_MQTT:
498-
send_to_mqtt(MQTT_LAST_UPDATE_ID, f"{TODAY} {current_time}")
503+
send_to_mqtt(MQTT_LAST_UPDATE_ID, f"{today_yyymmdd} {current_time}")
499504
send_to_mqtt(
500505
MQTT_POWER_GENERATED_ID,
501506
str(solar_power) + ";" + str(energy_generation),

0 commit comments

Comments
 (0)