Creating a 3 position switch: On/Off/Auto

Can anyone help me work out how to control whether an automation runs or not?
I’ve got a Tapo socket that is switched on by an automation that detects whether there is excess PV (ie ON when exporting power to grid), and otherwise OFF. I sometimes need to override this, wanting it either ON or OFF irrespective of the power export status. Changing the automation sounds easy, but I can’t work out how to create a switch with three states unless it is provided by an external integration.
I strikes me this must be a common need but I can’t find any discussion on this forum. I suspect therefore I’m just being dense. Does anyone care to educate me? Thanks.

Hi,
I would suggest to enable/disable the automation instead of integrating the on/off/auto state into the automation.
A button entity that calls the
automation.turn_on / automation.turn_off / automation.toggle
services should be enough.

  • To switch to off state, disable the automation and switch off the socket
  • To switch to on state, disable the automation and switch on the socket
  • To switch to auto state, enable the automation (and optionally, init the socket to whatever you want).

Above is my suggestion too. My use case is different. I have electric heat in a room which I want to turn on/off and have an automation that automatically turns off the heat at night (but only when I am not watching TV in the room). So it is just two switches: one for the heat, one for the automation. That way I can turn of the automation if I have guests staying in the room overnight. A single switch would save a little space. I use the Multiple Entity Row card to get the switches next to each other https://github.com/benct/lovelace-multiple-entity-row . I use that alot in my lovelace!

You could probably use an “Input Select” to create a drop down for the 3 modes: https://www.home-assistant.io/integrations/input_select or spend the time to make a custom card with that functionality.

how do you do this? do you already have something (input_boolean, etc) to turn it on/off/auto in HA?

IOW, how do you override this socket right now?

Thanks to jaaem & code_talker I’ve put together the following rather inelegant solution. I’m now wishing I’d followed their advice to do it with a switch that de-activates the automation instead.
My Lovelace card is:

type: horizontal-stack
cards:
  - entities:
      - entity: input_select.garage_switch
        card_mod:
          style: |
            :host {
             --card-mod-icon: none;
              }
    type: entities
  - type: glance
    entities:
      - entity: sensor.garage_current_power
        name: Power
      - entity: sensor.myenergi_ithaca_power_grid
        name: Grid
      - entity: switch.garage
        name: Socket

(The format of the input_select switch still isn’t right so suggestions welcome on how to eliminate the space taken up by the blank icon)
I ended up with 4 automations, which someone cleverer than I am could simplify!

alias: Garage skt on with PV
description: Switch Tapo (garage) socket on when PV being exported
trigger:
  - platform: numeric_state
    entity_id: sensor.myenergi_ithaca_power_grid
    for:
      hours: 0
      minutes: 1
      seconds: 0
    below: -250
  - platform: state
    entity_id:
      - input_select.garage_switch
    to: Auto
condition:
  - condition: state
    entity_id: input_select.garage_switch
    state: Auto
  - condition: numeric_state
    entity_id: sensor.myenergi_ithaca_power_grid
    below: -250
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.garage
mode: single

The -250W is chosen as this is more than the load that this socket takes when the automation is running.

alias: Garage skt OFF no PV
description: "Switch Tapo (garage) socket off when no PV "
trigger:
  - platform: numeric_state
    entity_id: sensor.myenergi_ithaca_power_grid
    above: 0
  - platform: state
    entity_id:
      - input_select.garage_switch
    to: Auto
condition:
  - condition: state
    entity_id: input_select.garage_switch
    state: Auto
  - condition: numeric_state
    entity_id: sensor.myenergi_ithaca_power_grid
    above: 0
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.garage
mode: single

then I need automations to make the manual over-ride switch to work:

alias: Garage socket ON
description: Manual switch ON
trigger:
  - platform: state
    entity_id:
      - input_select.garage_switch
    to: "On"
condition: []
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.garage
mode: single
alias: Garage socket OFF
description: Manual switch OFF
trigger:
  - platform: state
    entity_id:
      - input_select.garage_switch
    to: "Off"
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.garage
mode: single

It all works, but I’m not proud of the cludginess!

I found how to eliminate the icon’s space:

        card_mod:
          style: |
            :host {
             --mdc-icon-size: 0px;
            :state-badge {
             -- flex-basis: 0px;
             }