-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Examples needed for Solarbank 2 schedule structure #108
Comments
Can anybody export some owner account examples with various schedules defined, using all days or just specific day intervals. |
see here for new schedule example. Requires set and get_device_parm endpoints with dev_parrm = 6 |
When I query device_parm with param_type 6 against SB1 site_id I get following:
This could be the minimum required structure to send when no SB2 type schedule is defined on the site, but typically the minimum structure should only contain the settable paramters. Not sure if the default home load can be set for SB2? For SB1 this is fix 200 W when no interval defined. |
@thomluther As promised, here the Rust structs that I use for deserialization/serialization of the SB2 schedules. As mentioned in the other thread, the UI make sure that those structures make sense and are not overlapping. I haven't tested how the endpoint reacts if you send non-sense schedules.
|
Here are 2 example responses with the same SB2 schedule: Manual user mode: mode_type = 3 @Lenoirio When you got some time, can you please try whether you can switch the user mode just by passing back the schedule structure with changed mode_type setting? |
The api cache and solarbank monitor now support the new SB2 schedule query and display.
This needs further testing for correctness:
|
"So same weekday must not occur in two different index numbers." "Is the Sched. Preset reflecting the correct output according to the defined schedule and weekday" Regarding the AI/manual switch, I'll test that later. I can only check what the UI shows tough because I have no Anker-smartmeter installed (yet). |
Thanks for confirming this
The Sched preset is what the Api extracts from the schedule depending on actual time. It is what will be used to update the number entity in the HA integration which allows to modify the system output preset.
OK that is interesting. I thought you have one. So maybe mode 1 is not the standard Automatic mode, because you cannot use that mode without Smartmeter. It would always default back to the schedule when no smart meter installed. |
@thomluther I did the test with AI / manual I could easily set it to 3 again with the next request and everything is still working. |
@Lenoirio If that is not the case, at least any helper method to change the mode for the given site ID should only apply it when the site has also a smartmeter device listed, otherwise a change will be applied that is not going to work and Api user has no clue about this issue... |
@thomluther I just repeated the test to answer if I can read-back mode=1. Yes it reads it back. Unfortunatley I didn't read-back the first time I tried (when the UI gave me the error-message). But the set_schedule_param call returned Ok in both tries. |
@Lenoirio OK thanks for checking. So definitely no separate mode code when there is no smartmeter connection.... |
The AI option is greyed if no SmartMeter is installed. Btw: in the meantime I also got a system-msg. (error in SmartMeter-setup) for my second try. So if someone activates AI by API it will lead to a notification sooner or later. |
Ok thx. So I will plan to prevent this switch also in HA with the entity (and later also with the schedule services once that would be implemented) |
@stephan-l @nicolinuxfr I also need some basic validations of how the request payload must look like for the SB2 schedule to be applied as valid schedule. The basic code to apply a new schedule is following where myapi is the authenticated api client. It tries to set the new schedule, which will also re_query the device schedule and update the api devices cache, so the print will show the resulting schedule structure. For proper application of the structure, you will also need to check it in the App.
For scheduleSB2 please test following minimal structures and let me know which of them works (verified in the App), or which kind of weird effects you might see. The request response might be valid and successfull, and even the subsequent query may show correct schedule structure applied, but it may not be always the case (is sometimes a problem for SB1 when a single range interval was applied) 1. Minimal without read-only fields or rate planIf there is a rate plan set, will this delete all schedule settings and can be used to reset all to default?
2. Minimal with subset of rate plan fields.Will index number and week days automatically be set?
3. Minimal with complete rate plan item but no blend plan.Day range is also incomplete, will that be applied as a full day range like for SB1 schedules? Will the remaining weekdays kept off the applied schedule?
4. Complete plan but changed read only fields for default and max setting.Will the default or max changes have any effect (change the max output setting or the default home load for undefined intervals?
|
I tried to export, but got this error (I just pulled the project) :
|
Ah right change the double quotes to single quotes in line 71:
plan.get("default_home_load",'----') |
So first, an export with no schedule defined in the app : For the rest, I'm sorry but I'm always confused on how to create the files. I tried, but get an error each time. Here's what I tried : import logging, json
import asyncio
from aiohttp import ClientSession
from api import api
import common
_LOGGER: logging.Logger = logging.getLogger(__name__)
# _LOGGER.setLevel(logging.DEBUG) # enable for detailed Api output
async def main() -> None:
"""Create the aiohttp session and run the example."""
async with ClientSession() as websession:
"""put your code here, example"""
myapi = api.AnkerSolixApi(
common.user(), common.password(), common.country(), websession, _LOGGER
)
await myapi.update_sites()
await myapi.update_site_details()
await myapi.update_device_details()
await myapi.update_device_energy()
scheduleSB2 = {
"mode_type": 3,
"custom_rate_plan": None,
"blend_plan": None,
}
siteId="REDACTED"
deviceSn="REDACTED"
print(json.dumps((await myapi.set_device_parm(siteId=siteId, paramData=scheduleSB2, paramType="6", deviceSn=deviceSn)), indent=2))
print(json.dumps(myapi.devices,indent=2))
print(f"Api Requests: {myapi.request_count}")
# run async main
if __name__ == "__main__":
try:
asyncio.run(main())
except Exception as err:
print(f"{type(err)}: {err}") |
Thx for the export, that prooves that the min custom_rate_plan is an empty list, in contrast to the blend_plan which is null !?!
So the custom_rate_plan object for SB2 seems to be similar to the ranges object for SB1 schedule responses. @nicolinuxfr , in regards to your pyhton errors, your example works in my runtime (I use VSC with the HA core dev build).
You can also comment the following lines that just fill the api cache structures to save requests when testing this routine:
The set_device_parm helper method does not need it since you have to pass the site ID and device SN. You may have to run following for your pipenv if you use it, since the aiofiles I had to add later and its not included into the pipfile.lock yet, that is used to sync your venv with the required packages.
Running the above will install the package aiofiles and add it to the default packages section in the Pipfile.lock. |
I'm always using this command to launch the files, it works great to export the system : I don't really know Python (obviously…), just enough to know I have to be very careful in order to not mess everything on this computer where Home Assistant (among other things) is also running. 😅 Anyway, even with the aiofiles command, I still have the same error, sorry about that. |
@stephan-l, @chiefymuc, @philippreissing, @lumeenous, is someone of you able to try various schedule formats against the SB2 as described above ? |
My device is currently sleeping, and I have the system configured to aischedule, so I have not set a manual schedule, ever. My setup is a Solarbank 2 Pro and the Smart Meter with 2x 445W IBC panels |
@andsk8 , one export of this kind after creating a schedule and while the device is online during the day would help to have an actual example config for the latest Api. However, it does not help so much with the Schedule test cases above. |
@thomluther I tested the above scenarios. All with these commands as described: print(json.dumps((await myapi.set_device_parm(siteId=siteId, paramData=scheduleSB2, paramType="6", deviceSn=deviceSn)), indent=2))
print(json.dumps(myapi.devices,indent=2)) serial number replaced with 1. Minimal without read-only fields or rate plan Output: true
{
"<devicesn>": {
"device_sn": "<devicesn>",
"schedule": {
"mode_type": 3,
"custom_rate_plan": null,
"blend_plan": null,
"default_home_load": 200,
"max_load": 800,
"min_load": 0,
"step": 10
},
"preset_system_output_power": 200,
"preset_allow_export": true,
"preset_charge_priority": 80,
"preset_power_mode": null,
"preset_device_output_power": null
}
} Result in the app: All schedules deleted. 2. Minimal with subset of rate plan fields.
3. Minimal with complete rate plan item but no blend plan. true
{
"<devicesn>": {
"device_sn": "<devicesn>",
"schedule": {
"mode_type": 3,
"custom_rate_plan": [
{
"index": 0,
"week": [
0,
6
],
"ranges": [
{
"start_time": "12:00",
"end_time": "18:00",
"power": 110
}
]
}
],
"blend_plan": null,
"default_home_load": 200,
"max_load": 800,
"min_load": 0,
"step": 10
},
"preset_system_output_power": 200,
"preset_allow_export": true,
"preset_charge_priority": 80,
"preset_power_mode": null,
"preset_device_output_power": null
}
} 4. Complete plan but changed read only fields for default and max setting. true
{
"<devicesn>": {
"device_sn": "<devicesn>",
"schedule": {
"mode_type": 3,
"custom_rate_plan": [
{
"index": 0,
"week": [
0,
6
],
"ranges": [
{
"start_time": "00:00",
"end_time": "07:45",
"power": 100
},
{
"start_time": "17:05",
"end_time": "21:20",
"power": 200
}
]
}
],
"blend_plan": null,
"default_home_load": 200,
"max_load": 800,
"min_load": 0,
"step": 10
},
"preset_system_output_power": 200,
"preset_allow_export": true,
"preset_charge_priority": 80,
"preset_power_mode": null,
"preset_device_output_power": null
}
}
Result in the app: I hope this helps! |
@philippreissing Thank you very much for the testing. One thing that puzzles me are the SB1 preset fields returned by the Api devices cache, They should not be contained in the cache for an SB2 device.
Did you use the latest Api version in main branch for your testing? |
@thomluther sorry for the delay. here two exports. 1st: setting the Power usage scneario to Custom mode, and not setting any schedule, so defaulting to 200W as the app mentions. Legend is: "You have not added a solar consumption plan. Your home will be set a 200W output for appliance power consumption" 2nd: Setting an Energy Plan to repeat every day and with a schedule of 800W delievered from 12:00 to 15:00 Let me know if you need different settings. |
@thomluther : I tested with revision 1955faf (1955faf). Should that already include the changes? |
@philippreissing I found the reason for this. Its because the update_sites poller was never run before, so the Solarbank PN and generation was not classified yet. That explains why the SB1 preset fields are generated from the schedule... |
Full schedule modification is now supported with release 2.1.0 |
The Schedule structure for Solarbank 2 should be pretty different to Solarbank 1 since it supports weekdays and less settings per interval.
Examples are needed how the new structures look like and how it can be changed via an API Endpoint.
A new helper method has to be developped to simplify Solarbank 2 schedule modifications. This should NOT be merged with Solarbank 1 helper method, since that is already extremely complex to cover all cases.
Schedule modification with Solarbank 2 are not that important, since power automation can be done in AI mode via the smartmeter.
The text was updated successfully, but these errors were encountered: