batpred
batpred copied to clipboard
Provide (API) mechanism to externally inform Predbat of 'special rate' pricing events
Is your feature request related to a problem? Please describe. Predbat has the ability to do price over-rides by entering the date, start time, end time and load multiplier in apps.yaml.
With Octopus Power up events and Free electricity events, these happen often and I want a simple way to be able to inform Predbat of these without having to manually edit apps.yaml each time.
Describe alternatives you've considered I have a solution for this that works perfectly with predbat running in appdaemon, but I've just discovered that it doesn't (and probably can never) work with the predbat add-on.
My (appdaemon) solution is as follows:
- set of helper entities for date, start and end time
- a shell script that appends the correctly formatted date, start and end time to apps.yaml
- a shell_command in configuration.yaml that invokes the above shell script with the helper entity states being passed as parameters
This works perfectly with predbat running in appdaemon as it can write to my /config/appdaemon/apps/batpred/apps/apps.yaml file
However when I modify the script to write to /addon_configs/6adb4f0d_predbat/apps.yaml it fails as the shell command runs in the homeassistant container context and it doesn't have access to /addon_configs folder tree.
I can't identify any way round this as homeassistant can't directly access the add-on file system structure. Hence this FR
Describe the solution you'd like A mechanism from within Predbat that I can invoke to instruct it to take in an import price over-ride - would need to be able to pass the start date, time, end time and load multiplier. A service API if possible would be great, or some sort of configuration in apps.yaml to point to the external over-ride data.
e.g. in apps.yaml, something like this: user_rates_import_override: - date: input_datetime.octopus_powerup_date start: input_datetime.octopus_powerup_start_time end: input_datetime.octopus_powerup_end_time rate: 0 load_scaling: input_number.octopus_powerup_load_scaling
Can define these helper entities in HA, configure apps.yaml to point to them, and then have a 'trigger' toggle in predbat that reads from these helper entities and writes the override to apps.yaml.
The reason I suggest writing the override to apps.yaml and not just using these helpers directly is we are on occasion getting multiple events, e.g. this weekend there was a powerup event and a free electricity event on Saturday and then another powerup event on Sunday. The ability to queue and instruct predbat of these one by one rather than having to wait for one to finish before the next can be instructed would be useful PI A clear and concise description of what you want to happen.
Powerups are already taken care of in Predbat with negative prices in the plan. I believe the "free for everything over your normal usage" periods are not flagged in the octopus api, so can you comment where you are getting them from?
Powerups are already taken care of in Predbat with negative prices in the plan. I believe the "free for everything over your normal usage" periods are not flagged in the octopus api, so can you comment where you are getting them from?
No, the problem is that powerups are NOT automatically taken care of in Predbat, I think you might be thinking of Agile plunge pricing when the published agile rate goes negative.
Powerups are where the electricity is zero price for a set period no matter how much you use and so is slightly different from the "free for everything over your normal usage".
Neither of these price rate overrides are made available to Predbat via the Octopus API's or BottlecapDave's Octopus Integration. The only way to get predbat to plan for these events are to put a manual price rate override in apps.yaml so I'm seeking a mechanism to do this more easily than having to manually edit the file each time.
I'm getting the date and times of these activities via https://github.com/8none1/octopus_powerups which gets them into HA. With the appdaemon add-on I could then write these directly to apps.yaml, but for the predbat addon it runs in its own protected space and HA doesn't have access to write to the predbat addon apps.yaml
What about having a power up selector like the force charge one that sets the zero rate?
Yes that could work as well and would be reasonably easy to "drive" from a triggering automation to repeatedly select, pause, select, etc the time periods.
Only potential limitation is the time window length on those drop-down selectors, I think 16, 18 hours? Would need to be a bit longer, maybe not the whole weekend (for a Friday notification) but would want to have the ability to set 24-30 hours ahead
Sounds a good idea to add an override for zero rates. I can also see a benefit for setting more in advance, my only concern would be the amount of scrolling (on a phone screen).for say 30 hrs (that's 60.slots to pick through). I think the current list of times is long enough to navigate. However power ups and free energy is likely to be less frequent, so maybe there is a compromise/different solution for that
I tend to also additionally set the other override options (for other reasons) using the select:select service from external automations..Not sure if duplicate times e.g. two 01:00:00 in a list would break this
The reason the list is shorter is not only the size of the list but also to avoid having to include the day in the list, it just auto-clears when the time wraps. I could however accept a day when its used as a service it won't matter its not on the list in this case.
I generally use the select.select service to ensure something predictable happens everyday. For example, set my afternoon cheap slots to always charge - in case I put.a random high load on in the period. Adding a day requirement I guess would make this more complicated to automate
If it's possible for there to be a shorter dropdown list for use via the UI and the ability to optionally pass date (or day) in when select is called via an API call (for longer term setup's) then this seems the best of both worlds
Okay I have an idea, let me give it a try...
I'm testing out an idea, not yet documented as I don't know if I want to keep it as-is yet. Please can you try an update to main.
There is a new selector called 'select.predbat_manual_api' which works a bit like the manual override ones but this can have new values added using the select API in Home Assistant. The only function the selector itself serves is to store override commands, you can clear from the selector but you have to set them using a service call.
The idea is that it overrides settings in apps.yaml, well only ones that have been enabled for that purpose.
Below is an example of setting a rate override, you can clear all overrides by calling 'off' or this specific one only by calling the same thing again but in square brackets []
For the rates you can use 'rates_export_override' or 'rates_import_override' with all the same options as apps.yaml but in a URL type format
rates_export_override?start=17:00:00&end=19:00:00&rate=0
If you override a single value item with something like:
inverter_limit=4000
Only the settings below plus rates_import_override and rates_export_override are currently enabled but its possible to add other things.
If the setting is indexed e.g. per inverter then you have to add 'index' if it applies to just one e.g.
inverter_limit?value=4000&index=0
# These settings can be overridden by the API
CONFIG_API_OVERRIDE = {
"inverter_limit" : True,
"export_limit" : True,
"inverter_battery_rate_min" : True,
"inverter_reserve_max" : True,
"battery_rate_max" : True,
"car_charging_soc" : True,
"car_charging_limit": True,
"car_charging_battery_size": True,
"days_previous": True,
"days_previous_weight": True,
"battery_scaling": True,
"forecast_hours": True,
"import_export_scaling": True
}
Mm, very interesting solution, far more extensible and general purpose than I had considered.
I like it. I'll give it a go
I've installed the main version and can see the new select control entity.
trying it for the first time with a select value of
select.predbat_manual_api = rates_import_override?date=07/10/24&start=17:00:00&end=19:00:00&rate=0
Not intentional but I mis-formatted the date, Predbat trapped this and logged it in the logfile and set predbat.status:
Warn: Bad date 07/10/24 provided in energy rates
Able to clear the bad manual API control from the dropdown OK
Tried a second time with
rates_import_override?date=2024-10-07&start=17:00:00&end=19:00:00&rate=0
This was accepted and I could see in the logfile the existing rate overrindes in apps.yaml and the manual one I input:
2024-10-06 21:08:43.299847 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-26', 'start': '09:00:00', 'end': '11:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 09:00:00 to 10-06 11:00:00 @ 0.0 date 2024-09-26 00:00:00 increment False
2024-10-06 21:08:43.301874 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-10-01', 'start': '04:00:00', 'end': '07:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 04:00:00 to 10-06 07:00:00 @ 0.0 date 2024-10-01 00:00:00 increment False
2024-10-06 21:08:43.303812 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-10-03', 'start': '11:00:00', 'end': '14:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 11:00:00 to 10-06 14:00:00 @ 0.0 date 2024-10-03 00:00:00 increment False
2024-10-06 21:08:43.305990 INFO pred_bat: Adding rate rates_import_override: {'index': None, 'date': '2024-10-07', 'start': '17:00:00', 'end': '19:00:00', 'rate': '0'} => 10-06 17:00:00 to 10-06 19:00:00 @ 0.0 date 2024-10-07 00:00:00 increment False
(index being different for the manual one)
And it worked !
r/e the list of controls you can override in apps.yaml:
inverter_limit and export_limit I would think unlikely to ever override as these are predbat emulating what's already programmed in the inverter
inverter_battery_rate_min, inverter_reserve_max and battery_rate_max likewise I think unlikely to ever change these once set
however inverter_limit_charge and inverter_limit_discharge I think would be useful to add as this would give dynamic control in HA as to what rate predbat instructs the inverter to operate at
car_charging entries, useful for people with more than one car
days_previous & weight, yes can see this would be useful
battery_scaling, can't see the need for this, its a set once for your battery and its done
forecast_hours, yes could occasionally be useful to change
import_export_scaling, another one I think is a set once and forget
My only other questions are about how/how long these overrides persist, do they survive a restart of Predbat (I assume they will), a restart of HA? Some guidance needed in the documentation about not using these for long term changes to the predbat config as its very easy to zap the overrides from the UI, best to only use for temporary changes
So now I've broken Predbat and its not proving easy to get it back ...
Experimenting with setting the manual_api programatically from a dashboard, I added a new button that was intended to construct the import rate override from some existing input_datetime helpers and pass all that to Predbat.
My dashboard card and button code:
type: entities
entities:
- entity: input_datetime.octopus_power_up_date
- entity: input_datetime.octopus_power_up_start_time
- entity: input_datetime.octopus_power_up_end_time
- type: button
name: Send Power Up event to Predbat
icon: mdi:script-text-play-outline
action_name: Execute
tap_action:
action: call-service
service: select.select_option
target:
entity_id:
- select.predbat_manual_api
data:
option: >-
rates_import_override?date={{
states('input_datetime.octopus_power_up_date')| as_timestamp |
timestamp_custom('%Y-%m-%d') }}2024-10-07&start={{
states('input_datetime.octopus_power_up_start_time') }}&end={{
states('input_datetime.octopus_power_up_end_time') }}&rate=0
Unfortunately this passes the entire string, not processed as YAML through as a select option to Predbat:
2024-10-06 23:00:05.201827 INFO pred_bat: select_event: manual_api, select.predbat_manual_api = rates_import_override?date={{ states('input_datetime.octopus_power_up_date')| as_timestamp | timestamp_custom('%Y-%m-%d') }}2024-10-07&start={{ states('input_datetime.octopus_power_up_start_time') }}&end={{ states('input_datetime.octopus_power_up_end_time') }}&rate=0
Which then crashes:
2024-10-06 23:08:08.187857 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-10-03', 'start': '11:00:00', 'end': '14:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 11:00:00 to 10-06 14:00:00 @ 0.0 date 2024-10-03 00:00:00 increment False
2024-10-06 23:08:08.189870 INFO pred_bat: Warn: can not resolve start value { states('input_datetime.octopus_power_up_start_time') }
2024-10-06 23:08:08.248603 INFO pred_bat: Info: record_status Warn: can not resolve start value { states('input_datetime.octopus_power_up_start_time') }
2024-10-06 23:08:08.250606 INFO pred_bat: Warn: can not resolve end value { states('input_datetime.octopus_power_up_end_time') }
2024-10-06 23:08:08.302948 INFO pred_bat: Info: record_status Warn: can not resolve end value { states('input_datetime.octopus_power_up_end_time') }
2024-10-06 23:08:08.305717 INFO pred_bat: Warn: can not resolve date value { states('input_datetime.octopus_power_up_date')| as_timestamp | timestamp_custom('%Y-%m-%d') }2024-10-07
2024-10-06 23:08:08.347884 INFO pred_bat: Info: record_status Warn: can not resolve date value { states('input_datetime.octopus_power_up_date')| as_timestamp | timestamp_custom('%Y-%m-%d') }2024-10-07
2024-10-06 23:08:08.349897 INFO pred_bat: Error: Exception raised strptime() argument 1 must be str, not None
2024-10-06 23:08:08.355139 INFO pred_bat: Error: Traceback (most recent call last):
File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 11378, in update_time_loop
self.update_pred(scheduled=False)
File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 10177, in update_pred
self.fetch_sensor_data()
File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 9440, in fetch_sensor_data
self.rate_import = self.basic_rates(self.get_arg("rates_import_override", [], indirect=False), "rates_import_override", self.rate_import, self.rate_import_replicated)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 3159, in basic_rates
date = datetime.strptime(date_str, "%Y-%m-%d")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: strptime() argument 1 must be str, not None
2024-10-06 23:08:08.389981 INFO pred_bat: Info: record_status Error: Exception raised strptime() argument 1 must be str, not None
Tried manually selecting [Off] option in select.predbat_manual_api but because of the crash the webhook isn't working
Tried restarting Appdaemon add-on, Predbat crashes same error
Tried calling the select.select action with the valid rates_import_override option string, but it just appends the valid option to the select and crashes with the invalid option:
2024-10-06 23:18:26.814560 INFO pred_bat: Basic rate API override items for rates_import_override are [{'index': None, 'date': "{{ states('input_datetime.octopus_power_up_date')| as_timestamp | timestamp_custom('%Y-%m-%d') }}2024-10-07", 'start': "{{ states('input_datetime.octopus_power_up_start_time') }}", 'end': "{{ states('input_datetime.octopus_power_up_end_time') }}", 'rate': '0'}, {'index': None, 'date': '2024-10-07', 'start': '17:00:00', 'end': '19:00:00', 'rate': '0'}]
Stopped Appdaemon, changes select.predbat_manual_api to Off, restarted Appdaemon, again crashes
From the developer tools, called the select.select_option action with a value of Off to force the manual api to clear itself, and its recognised as being the selected value, but because the other invalid value is still in the select list, this tries to be parsed and Predbat again crashes:
2024-10-06 23:23:41.028020 INFO pred_bat: select_event: manual_api, select.predbat_manual_api = Off
2024-10-06 23:23:43.367961 INFO pred_bat: Refreshing Predbat configuration
2024-10-06 23:23:46.657926 INFO pred_bat: Saved current settings to /addon_configs/a0d7b954_appdaemon/predbat_config.json
2024-10-06 23:23:46.659554 INFO pred_bat: --------------- PredBat - update at 2024-10-06 23:20:00+01:00 with clock skew 0 minutes, minutes now 1400
2024-10-06 23:23:46.662665 INFO pred_bat: Saved current settings to /addon_configs/a0d7b954_appdaemon/predbat_config.json
2024-10-06 23:23:46.663900 INFO pred_bat: Using cached GITHub data for https://api.github.com/repos/springfall2008/batpred/releases age 1.2 minutes
2024-10-06 23:23:46.665767 INFO pred_bat: Predbat /homeassistant/appdaemon/apps/batpred/predbat.py version v8.4.12 currently running, latest version is v8.4.11 latest beta v8.4.11
2024-10-06 23:23:46.666935 INFO pred_bat: Autoupdate: Currently on unknown version v8.4.12 (?)
2024-10-06 23:23:46.770095 INFO pred_bat: Configuration: forecast_hours 48 num_cars 0 debug enable is False calculate_plan_every 10
2024-10-06 23:23:46.771555 INFO pred_bat: Predbat mode is set to Control charge & discharge
2024-10-06 23:23:47.408036 INFO pred_bat: Found 12960 load_today datapoints going back 4 days
2024-10-06 23:23:47.900832 INFO pred_bat: Car charging hold False threshold 4.0
2024-10-06 23:23:47.907711 INFO pred_bat: Current data so far today: load 20.9 kWh import 24.8 kWh export 12.8 kWh pv 13.3 kWh
2024-10-06 23:23:47.910013 INFO pred_bat: Fetching futurerate data from https://www.nordpoolgroup.com/api/marketdata/page/325?currency=GBP
2024-10-06 23:23:47.911892 INFO pred_bat: Return cached futurerate data for https://www.nordpoolgroup.com/api/marketdata/page/325?currency=GBP age 1.2 minutes
2024-10-06 23:23:47.913797 INFO pred_bat: Future rates - peak rate is 960 - 1140 minutes premium import 14 export 6
2024-10-06 23:23:47.938303 INFO pred_bat: Loaded 192 datapoints of futurerate analysis
2024-10-06 23:23:48.031504 INFO pred_bat: Predicted future rates: ['10-06 23:00:00 => 18.75 / 7.71', '10-07 00:00:00 => 16.88 / 6.94', '10-07 01:00:00 => 17.2 / 7.07', '10-07 02:00:00 => 15.99 / 6.57', '10-07 03:00:00 => 15.46 / 6.36', '10-07 04:00:00 => 15.08 / 6.2', '10-07 05:00:00 => 16.84 / 6.93', '10-07 06:00:00 => 22.23 / 9.14', '10-07 07:00:00 => 22.36 / 9.2', '10-07 08:00:00 => 23.0 / 9.46', '10-07 09:00:00 => 21.62 / 8.89', '10-07 10:00:00 => 20.8 / 8.55', '10-07 11:00:00 => 19.87 / 8.17', '10-07 12:00:00 => 20.01 / 8.23', '10-07 13:00:00 => 20.04 / 8.24', '10-07 14:00:00 => 20.35 / 8.37', '10-07 15:00:00 => 21.58 / 8.87', '10-07 16:00:00 => 36.3 / 14.88', '10-07 17:00:00 => 46.03 / 18.88', '10-07 18:00:00 => 49.35 / 20.25', '10-07 19:00:00 => 29.8 / 12.25', '10-07 20:00:00 => 22.19 / 9.13', '10-07 21:00:00 => 21.87 / 8.99', '10-07 22:00:00 => 20.55 / 8.45']
2024-10-06 23:23:48.057019 INFO pred_bat: Standing charge is set to 0.0 p
2024-10-06 23:23:48.080758 INFO pred_bat: Basic rate API override items for rates_import_override are [{'index': None, 'date': "{{ states('input_datetime.octopus_power_up_date')| as_timestamp | timestamp_custom('%Y-%m-%d') }}2024-10-07", 'start': "{{ states('input_datetime.octopus_power_up_start_time') }}", 'end': "{{ states('input_datetime.octopus_power_up_end_time') }}", 'rate': '0'}, {'index': None, 'date': '2024-10-07', 'start': '17:00:00', 'end': '19:00:00', 'rate': '0'}]
2024-10-06 23:23:48.090617 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-08-08', 'start': '13:00:00', 'end': '15:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 13:00:00 to 10-06 15:30:00 @ 0.0 date 2024-08-08 00:00:00 increment False
2024-10-06 23:23:48.097592 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-08-15', 'start': '13:00:00', 'end': '15:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 13:00:00 to 10-06 15:30:00 @ 0.0 date 2024-08-15 00:00:00 increment False
2024-10-06 23:23:48.101754 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-08-16', 'start': '13:00:00', 'end': '15:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 13:00:00 to 10-06 15:30:00 @ 0.0 date 2024-08-16 00:00:00 increment False
2024-10-06 23:23:48.104352 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-08-28', 'start': '12:00:00', 'end': '14:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 12:00:00 to 10-06 14:30:00 @ 0.0 date 2024-08-28 00:00:00 increment False
2024-10-06 23:23:48.107532 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-08-30', 'start': '12:00:00', 'end': '14:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 12:00:00 to 10-06 14:30:00 @ 0.0 date 2024-08-30 00:00:00 increment False
2024-10-06 23:23:48.110501 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-08-31', 'start': '13:00:00', 'end': '14:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 13:00:00 to 10-06 14:00:00 @ 0.0 date 2024-08-31 00:00:00 increment False
2024-10-06 23:23:48.113293 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-08-31', 'start': '19:00:00', 'end': '21:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 19:00:00 to 10-06 21:00:00 @ 0.0 date 2024-08-31 00:00:00 increment False
2024-10-06 23:23:48.116279 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-01', 'start': '06:00:00', 'end': '08:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 06:00:00 to 10-06 08:00:00 @ 0.0 date 2024-09-01 00:00:00 increment False
2024-10-06 23:23:48.119915 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-06', 'start': '12:00:00', 'end': '14:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 12:00:00 to 10-06 14:30:00 @ 0.0 date 2024-09-06 00:00:00 increment False
2024-10-06 23:23:48.122565 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-10', 'start': '13:00:00', 'end': '14:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 13:00:00 to 10-06 14:00:00 @ 0.0 date 2024-09-10 00:00:00 increment False
2024-10-06 23:23:48.129561 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-11', 'start': '10:00:00', 'end': '12:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 10:00:00 to 10-06 12:30:00 @ 0.0 date 2024-09-11 00:00:00 increment False
2024-10-06 23:23:48.136468 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-13', 'start': '04:00:00', 'end': '06:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 04:00:00 to 10-06 06:00:00 @ 0.0 date 2024-09-13 00:00:00 increment False
2024-10-06 23:23:48.140658 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-14', 'start': '11:00:00', 'end': '13:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 11:00:00 to 10-06 13:30:00 @ 0.0 date 2024-09-14 00:00:00 increment False
2024-10-06 23:23:48.143345 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-15', 'start': '10:00:00', 'end': '12:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 10:00:00 to 10-06 12:00:00 @ 0.0 date 2024-09-15 00:00:00 increment False
2024-10-06 23:23:48.146450 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-17', 'start': '10:00:00', 'end': '12:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 10:00:00 to 10-06 12:30:00 @ 0.0 date 2024-09-17 00:00:00 increment False
2024-10-06 23:23:48.149174 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-18', 'start': '13:30:00', 'end': '15:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 13:30:00 to 10-06 15:30:00 @ 0.0 date 2024-09-18 00:00:00 increment False
2024-10-06 23:23:48.152426 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-20', 'start': '12:00:00', 'end': '14:30:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 12:00:00 to 10-06 14:30:00 @ 0.0 date 2024-09-20 00:00:00 increment False
2024-10-06 23:23:48.155331 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-24', 'start': '15:00:00', 'end': '17:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 15:00:00 to 10-06 17:00:00 @ 0.0 date 2024-09-24 00:00:00 increment False
2024-10-06 23:23:48.159540 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-09-26', 'start': '09:00:00', 'end': '11:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 09:00:00 to 10-06 11:00:00 @ 0.0 date 2024-09-26 00:00:00 increment False
2024-10-06 23:23:48.161939 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-10-01', 'start': '04:00:00', 'end': '07:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 04:00:00 to 10-06 07:00:00 @ 0.0 date 2024-10-01 00:00:00 increment False
2024-10-06 23:23:48.164506 INFO pred_bat: Adding rate rates_import_override: {'date': '2024-10-03', 'start': '11:00:00', 'end': '14:00:00', 'rate': 0, 'load_scaling': 1.0} => 10-06 11:00:00 to 10-06 14:00:00 @ 0.0 date 2024-10-03 00:00:00 increment False
2024-10-06 23:23:48.166994 INFO pred_bat: Warn: can not resolve start value { states('input_datetime.octopus_power_up_start_time') }
2024-10-06 23:23:48.222943 INFO pred_bat: Info: record_status Warn: can not resolve start value { states('input_datetime.octopus_power_up_start_time') }
2024-10-06 23:23:48.226475 INFO pred_bat: Warn: can not resolve end value { states('input_datetime.octopus_power_up_end_time') }
2024-10-06 23:23:48.258553 INFO pred_bat: Info: record_status Warn: can not resolve end value { states('input_datetime.octopus_power_up_end_time') }
2024-10-06 23:23:48.262271 INFO pred_bat: Warn: can not resolve date value { states('input_datetime.octopus_power_up_date')| as_timestamp | timestamp_custom('%Y-%m-%d') }2024-10-07
2024-10-06 23:23:48.297383 INFO pred_bat: Info: record_status Warn: can not resolve date value { states('input_datetime.octopus_power_up_date')| as_timestamp | timestamp_custom('%Y-%m-%d') }2024-10-07
2024-10-06 23:23:48.299854 INFO pred_bat: Error: Exception raised strptime() argument 1 must be str, not None
2024-10-06 23:23:48.311716 INFO pred_bat: Error: Traceback (most recent call last):
File "/homeassistant/appdaemon/apps/batpred/predbat.py", line 11378, in update_time_loop
self.update_pred(scheduled=False)
Tried the select.predbat_update and was able to downgrade back to 8.4.11 which got Predbat working again.
Phew
Love the idea of this, its very powerful and once I work out how to integrate it to my existing dashboard, it'll be great BUT need to think more about the error trapping and how to 'get out' of an invalid option such as I created just now.
Am a bit fearful of what will happen when I next swap back to main as the select still has all those invalid values in it and I don't know how to clear it
(I am hoping that writing a script to do the formatting and call the select.select will work, this article suggests it will https://community.home-assistant.io/t/yaml-help-using-value-from-helper-to-select-option-in-list/506007/2)
Okay, this is a bug in the rates code it should have caught the error, I've fixed this on 'main' so when you update it shouldn't crash.
I've now added documentation here: https://github.com/springfall2008/batpred/blob/main/docs/manual-api.md
Let me know if it works now.
Progress, and after a few false starts, it now works !
I upgraded to the latest main version and good news is that the bad date in the select is trapped now and Predbat didn't crash:
But in my testing I had some dummy values in the manual API dropdown which Predbat then executed and decided to do a force charge right in the peak period when import rates were spiking at 50p ! Had to keep repeatedly turning off the inverter charge schedules before I eventually managed to kill the manual API with an 'off' option. I found selecting off from the dropdown didn't work in this instance, instead I had to set the value to off via a select.select action in developer tools.
And perfect timing, we have a power-up event tomorrow.
I moved the embedded button code into a script that I could execute from the dashboard, and it didn't work. Predbat didn't crash but it ignored my import rate.
Found the problem was that in the script I was setting the option to "import_rates....... rate=0" - i.e. a set of double quotes around it which was what was being ignored by Predbat.
Removed these and it works. See 20:06 onwards and the extra import rate being added at 20:07:00 appdaemon.log
Here's my script as a sample if you'd like to add it to the documentation:
alias: Send Powerup event to Predbat manual API
sequence:
- action: select.select_option
data:
option: >-
rates_import_override?date={{
states('input_datetime.octopus_power_up_date')| as_timestamp |
timestamp_custom('%Y-%m-%d') }}&start={{
states('input_datetime.octopus_power_up_start_time') }}&end={{
states('input_datetime.octopus_power_up_end_time') }}&rate=0
target:
entity_id: select.predbat_manual_api
mode: single
description: ""
The template code has to be in a script, it doesn't work directly in a dashboard.
Documentation looks good. Maybe just put the list of supported overrides in alphabetical order as its a bit random at the moment.
Thanks a lot, this looks very useful, gives me what I wanted and should be extensible for lots of other niche automation use cases (like dynamic setting of the charge/discharge rate).
The new API is working perfectly, am able to automate Octopus power up events in Predbat from my dashboard.
Brilliant addition, thank you