How do I create a virtual on off switch?

Hello, I just want to create a virtual on off switch that I can export to Google Home Assistant and give the voice command on or off to, which will then initiate an automation within Hass.io

I tried various ideas with binary_sensor…templates, generic switch platform but these all seem to need an actual hardware device and it seems like I can not be the first to have this idea.

I have the automation worked out, just need the yaml to create the switch which will be the trigger please.

3 Likes

try https://www.home-assistant.io/integrations/switch.template/

I did see this, it relies on existing hardware, I want it as a standalone entity. I might look at exporting automations to Home Assistant and use one automation’s on off state to trigger the other automation.

Found it. For anyone needing a solution, you could create a scene, possible a script ( more advanced) or use input boolean as I did

31 Likes

Thanks. This was helpful.

2 Likes

Thanks! This was very helpful

2 Likes

@Bacon-Ranch excellent suggestion to use Boolean Input, it made testing things lot easier!!

1 Like

Can you use this for Alexa? I want to execute a button in my HAI system but I can’t get it to work for some reason.

I’m trying to go the other way around, I want an automation that when a device state changes (device_tracker for instance) changes state, the input_boolean ‘switch’ is toggled. But it is n entity and not a device so I cant select it.

You would use a template for this…
Change state of binary_input when an entity attribute changes

1 Like

@heffneil were you ever able to figure this out? When I expose my helper toggle switch to Alexa it doesn’t come up as a switch.

No, I didn’t. Sorry, wish I could help. Good luck if you figure it out let us know!

expose the boolean as a switch. Keep in mind there are caveats that are annoying when doing this. Like, turning the switch on when the boolean is on will be suppressed because it’s already on.

cloud:
  alexa:
    entity_config:
      input_boolean.xyz:
        name: "Foo"
        display_categories: SWITCH

I don’t know if you can change the display_category from the UI. I would assume you can. If you’re using the smart home skill and not cloud, the configuration is similar

alexa:
  smart_home:
    entity_config:
      input_boolean.xyz:
        name: "Foo"
        display_categories: SWITCH
1 Like

I have a toggle for turning lights on/off, but want it to reflect the state of the light(s) event if I turn them on manually. Unless I misunderstand, this is similar to what you’re looking to do?

alias: (update lights toggle OFF)
description: "Update state of lights toggle"
trigger:
  - platform: state
    entity_id:
      - switch.10001bba45
    attribute: state
    from: "on"
    to: "off"
condition: []
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.lighting
mode: restart

Might be simpler ways to do this, but as a rookie I’m just happy to get it working … :slight_smile:

Thanks mate, you made my day! :star_struck:

Hi @petro, I tried using this How do I create a virtual on off switch? - #13 by petro
to expose a virtual switch to Alexa but it hasn’t worked for me.

I have created the input_boolean and have been able to add it to a dashboard.

I have successfully setup the local Alexa integration and Alexa has discovered many devices that it can now control.

I have added the input_boolean to the alexa config:

alexa:
  smart_home:
    locale: en-GB
    endpoint: https://api.eu.amazonalexa.com/v3/events
    client_id: amzn1.application-oa2-client.xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    client_secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    filter:
      include_entities:
        - light.chandelier
      include_entity_globs:
        - binary_sensor.*_motion
    entity_config:
      binary_sensor.hall_front_door:
        name: "Front door"
        display_categories: DOOR
      input_boolean.virtual_camera_motion:
        name: "Virtual camera motion"
        display_categories: SWITCH

I have saved the config and restarted HA then got Alexa to do a Discovery. This didn’t find anything. I tried Disabling the Skill, the re-enabling it and then doing the Discovery but still nothing.

Any ideas?

You’re only including a light and a few binary sensors

Sure, and that’s all I need for now - but I would also like the input_boolean to be available in Alexa for a Routine.

Presumably I don’t have to list it in the filter as well as entity_config?

You have to list it in both places

Apologies, I thought my Front Door had already worked. Many thanks for this, it has allowed a far speedier response to Blink camera motions.