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


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?


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
  - platform: state
    entity_id: switch.wemo_heater
    to: 'on'
    for: '00:30:00'
  - service: switch.turn_off
    entity_id: switch.wemo_heater

I will try it, thank you