Dynamically adjust EVSE power based on grid fossil fuel percentage

Hi, I have the Chargepoint and Electricity Maps integration setup. Now I want to link the two together so that the Chargers rate tries to avoid times of high fossil fuel. I think a decent approach will be to look at the last week of electricity_maps_grid_fossil_fuel_percentage and do something to set cph50_charging_amperage_limit based on it. The possible range for cph50_charging_amperage_limit is 8 - 32 on my system, so when electricity_maps_grid_fossil_fuel_percentage is at the highest of the week, it should set it to 8 and when it is at the lowest of the week it should set it to 32. Any value in the middle should set it to something in the middle.

Any ideas how I would actually implement that? I’m still pretty new to templates, but feel like those will be involved.