Help with binary template sensor

I’m trying to create a template sensor to track my pool heater usage. The problem I have is the two states are heat and off. There is no heating state so if i have the pool set to heat, but it isn’t heating because its already at the desired heat temperature, it will still report as heat. This is a gist of what I want to accomplish.

If pool heat = heat
Pool temp < Pool heat set point
then template sensor = on

If pool heat = heat & pool temp> pool heat set point
or pool heat = off
then template sensor = off

more details below

if pentair/heater/pool/mode/state (climate.pool_heat) (data.state) = “heat”

& pentair/pooltemp/state (climate.pool_heat) (data.attributes.current_temperature) < pentair/heater/pool/setpoint/state (climate.pool_heat) (data.attributes.temperature)

turn on switch

if pentair/heater/pool/mode/state (climate.pool_heat) (data.state) = heat
& pentair/pooltemp/state (climate.pool_heat) (data.attributes.current_temperature) > pentair/heater/pool/setpoint/state (climate.pool_heat) (data.attributes.temperature)


pentair/heater/pool/mode/state (climate.pool_heat) (data.state) = off