Asking for help: Turn off Heater after a set time period

Hi,

I am not sure how to go about this, with either a script or an automation.

I have a fan heater plugged into a Wemo Switch that I can turn on via HA or Google Home.

However yesterday somehow it turned on and stayed on for hours (probably Google Home misuderstanding a command again).
So what I would like to do is If the Wemo Switch is turned on for it to turn off after a period of time (say 30 mins).

Could anyone help me with designing this automation please?

Thanks

Turns off switch.wemo_heater after it’s been on for 30 minutes. Replace the entity’s name with whatever you named your Wemo switch.

- alias: heater example
  trigger:
  - platform: state
    entity_id: switch.wemo_heater
    to: 'on'
    for: '00:30:00'
  action:
  - service: switch.turn_off
    entity_id: switch.wemo_heater

I will try it, thank you