Turn on wallplug and lett is turn off after x minutes

Hello all,

I have a working automation, when pushing a button on my wallmote the lamp turning on however I would like it to turn off after x minutes. I tried a lot but cannot find the solution.

Thnx,

André

- alias: Lamp bij de televisie
  hide_entity: true
  initial_state: true
  trigger:
    platform: event
    event_type: zwave.scene_activated
    event_data:
      entity_id: zwave.aeotec_zw130_wallmote_quad_3
      scene_id: 3
      scene_data: 0
  action:
    service: homeassistant.toggle
    data_template:
      entity_id:
        - switch.fibaro_system_fgwpef_wall_plug_gen5_switch

For five minutes it’s simply…

  action:
    - service: homeassistant.toggle
      entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch
    - delay: '00:05:00'
     - service: homeassistant.toggle
      entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch

it works:

  action:
    - service: homeassistant.toggle
      entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch
    - delay: '00:01:00'
    - service: homeassistant.toggle
      entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch 

Thank you very much,

André

Strange behaviour,

The above automation works with 10 seconds '00:00:10' and with 10 minutes '00:10:00' however NOT with 3 hours '03:00:00'

Anyone an idea how this is possible?

Thanks,

André

What exactly do you mean by it doesn’t work? Is it possible you’re trying to trigger the automation again while it’s still running? (E.g., with the delay set to 3 hours, are you pushing the button again on your wallmote before the 3 hours has expired?)

I’d suggest putting the actions into a script, and using the automation to run the script. And, specifically, like this:

script:
  toggle_my_switch:
    sequence:
      - service: switch.toggle
        entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch
      - delay: '00:01:00'
      - service: switch.toggle
        entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch

automation:
  - alias: Lamp bij de televisie
    hide_entity: true
    initial_state: true
    trigger:
      platform: event
      event_type: zwave.scene_activated
      event_data:
        entity_id: zwave.aeotec_zw130_wallmote_quad_3
        scene_id: 3
        scene_data: 0
    action:
      - service: script.turn_off
        entity_id: script.toggle_my_switch
      - service: script.toggle_my_switch

The idea is, if you push the button again before the script is done (i.e., it’s still sitting in the delay), the automation will first make sure the script is stopped. Then it can be sure to be able to start it (from the beginning. Note that a running script can’t be started/restarted. It has to be stopped first. I believe the same applies to the actions of an automation.)

Also note that you should probably use the switch.toggle service instead of the homeassistant.toggle service, since you know the entity is a switch. Generally you only need to use a homeassistant.xxx service when you want to run that service with a heterogeneous set of entities. (In your case homeassistant.toggle will just turn around and call switch.toggle, so you might as well call switch.toggle directly, which is slightly more efficient.)

1 Like

Good day pnbruckner,

I mean that it isn’t operating when I setup to turn it off after 3 hours. Your suggestion works perfect, I never worked with a script so it was a challenge but both of your suggestion works fine.

Thank you very much for your help.

André

1 Like

Simple way directly setup switch delay from the HASSIO user interface.
#1 Create a Dummy switch examlple input_boolean.master_bathroom_fan_2min


#2 Use that switch in automation and react for that switch changing state from off to on


I think there is still some possible glitch and in some cases you have to switch to Yaml and edit it and (Last picture) and sometimes it works in webGUI.
This method works really well for me.