Octopus Energy Integration - Setting Target Hours from Sensor

Hi,

I’m new to HA and love the Octopus Energy integration. I’ve created a sensor to work out the number of 30 minute charging periods to charge my ev to a certain threshold. What I’d like to do is set the target_hours in code to this value.

e.g.
action: call-service
service: octopus_energy.update_target_config
data:
target_hours: sensor.ev_charging_periods_required /2
target:
entity_id: binary_sensor.octopus_energy_target_ev_target_rate_sensor

Is this possible?

Many thanks.