Button to start operate smartplug for a defined time period

Newbie question here so please keep it simple :slight_smile:

I want to create a button in Lovelace Overview that will start a smartplug for a period of time, then turn off.

This will control my underfloor heating through a smart plug. I have created timers in configuration.yaml plus an automation (see photos). It would be nice to maybe have a slider to change the timer from 60mins to 180 mins.

image





OK. Don’t post screenshots of your automation. Post the automation in YAML format (just switch the Automation Editor’s mode from UI to YAML, then copy-paste what it displays).

For more information, refer to guideline 14 in the FAQ.

Apologies, being a newbie, did not know.

alias: automation.ufh.60
description: ‘’
trigger:

  • platform: state
    entity_id: switch.10012da59d
    to: ‘On’
    from: ‘Off’
    condition: []
    action:
  • service: timer.start
    data:
    duration: ‘0’
    target:
    entity_id: timer.ufh_timer_60
    mode: single

Also you need to format the pasted yaml correctly see point 11 here. You can edit your post to fix this.

Hay bro

format the code we all can see what is wrong.

alias: automation.ufh.60
description: ‘’
trigger:
  platform: state
  entity_id: switch.10012da59d
  to: ‘On’
  from: ‘Off’
condition: []
action:
  service: timer.start
  data:
  duration: ‘0’
  target:
  entity_id: timer.ufh_timer_60
  mode: single

see how it looks format right
those Quotes around are the wrong ones U must on a apple try " speech marks

you have started the timer by call the right drvice but I think the duration is a bit short
try
as we are dealing with a time we should format it to a time format “HH:MM:SS”

duration: "00:10:00"

your homework

That’s probably because the post was unformatted and not actually what they were using.

Also the trigger states need to be lower case.

  to: 'on'
  from: 'off'
1 Like

OK, thanks for your help. I have changed the yaml code to the following.

alias: automation.ufh.60
description: ‘’
trigger:

  • platform: state
    entity_id: switch.10012da59d
    to: ‘on’
    from: ‘off’
    condition: []
    action:
  • service: timer.start
    data:
    duration: ‘00:10:00’
    target:
    entity_id: timer.ufh_timer_60
    mode: single

Is there a way of starting the automation using a button on the Lovelace Dashboard?

Unless I am missing some requirements, I think that you could do this in a much “cleaner” way.

If you can get a temperature sensor into home assistant, you could use the generic thermostat component and then you would have temperature control.

If you can’t do that for some reason, and you want to have a button that turns something on for a certain period of time, I would just make a script that has three actions: turn on the switch, run a delay of the desired length (which could be stored in an “helper” input), and then turn off the switch. You could then put that script on an entity button on lovelace. If you want to automatically have this happen on some occasions, you could write an automation that just turns on the script when necessary.

An automation fires automatically based on some trigger, checks some conditions, and then runs an action. A script is just the action portion of an automation.

Dolores. It sounds like a script to run the command following an entity button press on lovelace. I will need to learn how to do this :slight_smile: