Lovelace timer to turn off device

Hi all. I have a tab in HA to control my electric underfloor heating via Shelly1PM relays. This works well but relies on a simple on/off button. I would like to create another button for a boost option or timer that can be selected and will turn the device on for a set period eg 1, 2, 4 hours etc. It would be nice for the button to show the time remaining, then at the end of the period it turns off the device.

Does anyone have an example they can show? I have never used booleans or Node Red before so require some simple guidance :slight_smile:

Have you thought about using input helpers? I would recommend an input number and a timer.

Create an input_number and timer in Configuration β†’ Automations and Scenes β†’ Helpers and add helpers lower right.

You can start the timer and turn on the heater

  alias: Floor Heat Timer Activation
  description: Activate the timer for floor heat
  trigger:
  - platform: state
    entity_id: switch.floor_heat
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: timer.start
    data:
      duration: {{ states('input_number.heat_duration_seconds') | int }}
    target:
      entity_id: timer.floor_heat
  mode: single

then

  alias: Floor Heat Turn Off
  description: Turn off floor heat
  trigger:
  - platform: state
    entity_id: timer.floor_heat
    to: idle
  - platform: homeassistant
    event: start
  condition: []
  action:
  - service: switch.turn_off
    target:
      entity_id: switch.floor_heat

The timer will fail and go to idle on a restart. This is why I have triggered on homeassistant start to also shut off floor heat. If you need to survive a restart, it can be done but more complicated automations.

1 Like

AllHailJ

Many thanks for this although its like you are speaking a foreign language to me. Are you able to provide a more simplistic guide?

I have done the following;

  1. Created an input number in Helpers - input_number.ufh_duration This has min value 30 and max 180

What are the next steps? An example of the UFH switches is switch.ufh_kitchen

So your timer will be in minutes. Do you know how to get the timer into lovelace so you can set? I will assume you do at this point and proceed. The first automation is to turn on a timer so you have visual on how long there is left until it turns off

  1. create a timer in helpers.

  2. Go to automations and create an automation
    2a In trigger select state as the trigger (by pressing the down arrow next to device)
    2b Choose your entity (the shelly 1pm that controls the underfloor heat) switch.floor_heat in my example
    2c Set from: off to: on
    2d Bypass the conditions - you don’t need any
    2e Go to Actions and select call service. Select timer.start as service and pick the timer you just created.
    2f Paste this with quotes "{{ states('input_number.ufh_duration') * 60 | int }}" into the duration field.
    2g Save your automation.

The second automation is to turn off the floor heat when the duration is done

3 Create the second automation.
3a Create a state trigger as in 2.
3b Select time as entity and set to: idle (meaning the timer has turned off)
3c Create a second trigger. Triggers always OR. timer idle or homeassistant start go do actions
3d Select homeassistant from the drop down. It should have the start already checked below.
3e Bypass the conditions.
3f On actions create call service.
3g On the service, type switch and you should see switch.turn_on, turn_off, and toggle show in a pop up. Select turn off
3h On the entity select the shelly 1 pm.

The logic is:

  1. When you turn on the underfloor heat
    1a. This turns on the timer
  2. When the timer expires or the system restarts for whatever reason
    2a. turn off the underfloor heat.

Hope this makes sense now.

1 Like