trigger:
- platform: state
entity_id: switch.pool_pump
to: 'on'
for:
hours: "{{ states('input_number.pool_pump_duration_hours')|int }}"
action:
- service: switch.turn_off
target:
entity_id: switch.pool_pump
You would of course have to create the input number. Also change the number 1 in float(1) to the default run time (in hours) you want if the temperature sensor is unavailable.
Another way to do this would be to start a timer after turning the pump on and setting its duration to the temperature times 1800 to give the duration in seconds.
The off automation would then trigger on the timer finishing event.
This is probably a better way to do it as timers do survive restarts. Don’t forget to create the timer.