Turn something on for a "specific" time

This has been mentioned/asked before, but with no real solution that I have found…
Want to be able to turn a device on for a “dynamic” period ie turn it on for 10 minutes/30minutes/2 hours etc, but need a popup (slider?) to set the time period. eg want to turn a plug on for 2 hours to charge a phone.
Additional would be good to actually set the device/light, as well!

Thanks.

I do something like this on my lawn sprinklers. I use a number helper entity in a grid card:

square: false
columns: 1
type: grid
cards:
  - type: entities
    entities:
      - entity: input_number.all_zones
        name: All lawn sprinklers
    title: All zones- Duration
    state_color: false
    show_header_toggle: true
  - type: button
    show_name: true
    show_icon: true
    tap_action:
      action: call-service
      service: automation.trigger
      service_data: {}
      target:
        entity_id: automation.all_sprinkler_zones
    entity: automation.all_zones
    show_state: false
    icon_height: 40px
    name: Set all zones

Pressing the button triggers an automation: “all_sprinkler_zones”:

- id: 'all_sprinkler_zones'
  alias: All Sprinkler Zones
  description: Sets all sprinkler zone durations to the value in 'input_number.all_zones'
  triggers:
  - id: "set_all_zones_button_pressed"
    trigger: state
    entity_id: input_button.all_zones_set
    from: 'off'
    to: 'on'
  conditions: []
  actions:
  - service: input_number.set_value
    data:
      value: '{{ states("input_number.all_zones")|int}}'
    target:
      entity_id:
      - input_number.irrigation_zone1_duration
      - input_number.irrigation_zone2_duration
      - input_number.irrigation_zone3_duration
      - input_number.irrigation_zone4_duration
      - input_number.irrigation_zone5_duration
      - input_number.irrigation_zone6_duration
      - input_number.irrigation_zone7_duration
      - input_number.irrigation_zone8_duration
      - input_number.irrigation_zone9_duration

There are surely more ways to do this, but this may get you started.

In the case of charging a phone or simulair.
You can use one of the cheap powerplugs (zigbee for example) that also reports power and let an automation switch it off when the power consumption is below x for say 1 minute.