Automatically turn off plug after manual turn on

Having trouble figuring out how to set this up, but I figure it should be possible.

Here’s what I’m trying to do: Small space heater in the bathroom on a WiFi plug, want to be able to turn it on by pressing the button on the WiFi switch (for people that use it and don’t have access to the app, etc) and then turn off after 30 minutes.

Is there a way to set up an automation that monitors for a change in state, and then starts a timer, or something of that nature, to make this possible?

You could start a timer when the state goes from off to on, then the timer finish event would trigger the heater to turn off. You could also just turn the heater off when it has been on for 30 minutes.

:roll_eyes:
configuration.yaml ?
make + model of WiFi plug
Is the plug recognised on your LAN?
Its IP address
Does it need cloud/hub
blah
blah

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371/3

a lot of people might not bother answering you, because they might feel you are not helping yourself ?

I left those details out because I figured them irrelevant. Everything works properly, I was just looking for help figuring out the right way to set up this automation.

Do you mean like this?
If switch turns on -> wait 30 min -> turn off ?

alias: test
description: ''
trigger:
  - platform: state
    entity_id: switch.on_off_plug_in_unit_2
    from: 'off'
    to: 'on'
condition: []
action:
  - delay: '00:30:00'
  - service: switch.turn_off
    data: {}
    entity_id: switch.on_off_plug_in_unit_2
mode: single

Or i misunderstood you ?

1 Like

Or:

alias: test
description: ''
trigger:
  - platform: state
    entity_id: switch.on_off_plug_in_unit_2
    from: 'off'
    to: 'on'
    for: “00:30:00“
condition: []
action:
  - service: switch.turn_off
    data: {}
    entity_id: switch.on_off_plug_in_unit_2
mode: single
1 Like

Yes, but using the “for” attribute in the trigger condition gives you timer like benefit without the need to create a timer (which needs to be monitored and resetted etc.)

1 Like

This is our daughter’s room which sometimes has some additional playing with the button so having a timer I can directly control has more predictability for me.

Two different use cases …

As well as being different use cases, the for: key can be templated for granular control.

Timers are very rarely the best option for homeassistant automations, and tend to add unnecessary complexity to the majority of use cases.