Custom pricing strategies
By default the scheduler will simply just rank the prices and assign them to the appropriate actions, but you might hit a case where you need something more complex than that, such as if you have a system where constraints are important or if you wanted to introduce another parameter to the scheduling, such as carbon intensity.
What are these?
Custom pricing strategies are python classes that you define and pass into the method for the appropriate tariff, in these you can write your own functionality that acts on the prices, this is using a Strategy pattern which injects in the config in runtime so that you can use the values you addtionally passed in.
Example: creating a custom pricing strategy for Octopus Agile
Here I'm going to set up a custom pricing strategy which makes sure:
- I don't ever spend more than 10p/kWh
- I only ever switch on my device if carbon intensity is below 100 units
Additionally I'm going to set up some custom actions which:
- Send a text message to my phone telling me that my smart plug is being switched on (done via AWS SNS)
- Send a HTTP RPC request to my shelly on the same WIFI network to start and stop when this conditions are met
Note
It's important to note that in this example, that the custom pricing strategy CustomPricingStrategy inherits from PricingStrategy, this is necessary otherwise you will hit a validation error to ensure it meets the contract and works with the rest of the code.