Software switch to control smart plug on a timed basis

So far, I’ve been using automation to control smart plugs but now have a use case to turn on an unswitched power outlet for a predetermined number of minutes using the HA app.

I’ve read through a lot of documentation and can do this by configuring and running an automation but not a way to create a switch icon on a dashboard for my wife that she can click on. Surely there must be one.

An example would be great.

Thanks

You can use the default button card and select automation.trigger as tap action.

Or you can create an input boolean to control the outlet and put that on the dashboard.

As other folks said, you can use automations to link a switch or input_boolean to the operation of the power outlet. The switch/input_boolean is what you’d show in your dashboard.
In addition, once you link the switch/input_boolean, you could use a variation of these are two automations I use along with a switch that turns on and off my outside tap (used for watering our gardens).

- alias: 'timing-Outside Tap off after 2 hours'
  trigger:
    platform: state
    entity_id: switch.outside_tap
    to: 'on'
    for: '02:00:00'
  condition:
    condition: state
    entity_id: switch.outside_water_valve_lock
    state: 'off'
  action:
    - service: switch.turn_off
      entity_id: switch.outside_tap
- alias: 'timing-Outside Tap lock off when Tap shut off'
  trigger:
    platform: state
    entity_id: switch.outside_tap
    to: 'off'
  action:
    - service: switch.turn_off
      entity_id: switch.outside_water_valve_lock
- alias: 'timing-Outside Tap on when Tap lock turned on'
  trigger:
    platform: state
    entity_id: switch.outside_water_valve_lock
    to: 'on'
  action:
    - service: switch.turn_on
      entity_id: switch.outside_tap

I’m going to try all these suggestions.

@finity Can one create an input Boolean through the GUI or does it have to be done in the YAML file?

Thanks, guys.

Yes UI, they are called “helpers” under configuration

Awesome! Created and used an input Boolean :slight_smile:

1 Like

So I created the Helper called recirculator_one_shot but this automation doesn’t seem to be triggered when I turn it on in a dashboard card. Can someone spot the bug?

The automation runs properly when clicking on Run Action so it seems to be the trigger

- id: '1633484613772'
  alias: Run Recirculator
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.recirculator_one_shot
    from: 'Off'
    to: 'On'
    for:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  condition: []
  action:
  - service: switch.turn_on
    target:
      device_id: b214e11401e711eb9899657fa58f2d1f
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
    target:
      device_id: b214e11401e711eb9899657fa58f2d1f
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.recirculator_one_shot
  mode: single

You need to change the states. most states are always lower case but you can check the actual states in the dev tools → states page. Case is important.

trigger:
  - platform: state
    entity_id: input_boolean.recirculator_one_shot
    from: 'off'
    to: 'on'
    for:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0

@finity

Case sensitivity! That fixed it.

Thanks

1 Like