A Option to add a virtual switch/sensor entity

So basically there are other ways to do this, but I think it could be implemented into the ui some how and would add for greater experience.

I am currently using a virtual switch/sensor I created in smarthings to do this, but it came about when I saw how many people were having issues getting ring camera and other devices to live view on some tablets or tv or streamers.

Basically this virtual switch would be both a switch and a open/close sensor and the reason it has to be both is to simplify things as apple and google and amazon love having there routines, automations triggered by sensors.

So if virtual switch is turned on it triggers the virtual sensor to open and vice versa.

Obviously everytime the end user creates a virtual switch/sensor (shall we call it a switchsor for short) it gets its own unique id and entities.

so I have this routine setup just for ring door bell.

alias: Ring live view
description: ''
trigger:
  - type: occupied
    platform: device
    device_id: a61a6c3a9ed091a0b508ac6578a23c58
    entity_id: binary_sensor.front_door_ding
    domain: binary_sensor
condition: []
action:
  - type: turn_on
    device_id: 9ef95f23e76484de9eaf5813d6ca798c
    entity_id: switch.ring_switch
    domain: switch
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 9ef95f23e76484de9eaf5813d6ca798c
    entity_id: switch.ring_switch
    domain: switch
  - service: fullykiosk.load_start_url
    data:
      entity_id: media_player.fire_tablet_media_player
mode: single

ring switch is my virtual switch, but this then triggers the other entity created by this which is the virtual sensor which amazons smart stuff actually detect, then in alexa app I have setup a routine that when the sensor changes to open to have the command alexa show front door and select the tablet as device to say it on.

this then loads up the live view on the tablet and the automation above closes it after 2 mins.

But this switch is not specific to this I created another that, is used to make Alexa tell my non HA compatible but Alexa compatible robot hoover to start (again the switch is controlled by HA)

there are so many useful ways to use this type of double layered (both switch and sensor) virtual switch. which will open a lot of smart products to be used with home assistant that are not integrated yet but are in amazon, google and apple.

Are you talking about an input_boolean?
That is what I have understood the equivalent to a virtual switch in Smart things. But I have never used Smart things, so I’m not sure.

2 Likes

its almost the same, but with the input boolean for this I had issues and the only advice to fix it was to add stuff on aws, what I am thinking is making it simpler (and easier for us old people :P) for someone just to add a virtual device that is both via a intergration. as the smart things just works no hassle (probably because I had them already made from previous test of smarthings).

There is a community option in HACS named virtual components that seems to do this. You define the entities in the text files.

1 Like

I don’t know what aws is and you still have not explained what the difference is.
Perhaps it’s just me that does not understand the difference but unless you explain the difference or what you actually want then I don’t think you are going to get many votes on this.

Oh… and don’t forget to vote your own request.

No good for google as this can’t trigger off of a switch and or sensor anyway.

Switches work, I’m quite sure I can switch switches with Google Home.
As long as it’s exposed to Google then it works.

You are correct, I have lots of switches and booleans exposed and they can of course be triggered by google, but I was referring to the OP’s use case and they are referring to using an exposed (sensor) entity as an automated trigger within google, however google routines cannot be trigger from any change in any exposed entity.

Hopefully that makes more sense :+1:t2:

yes google switch would need to be one that does the switch and changes status of home and away for it it to work. but the point is.

say open the addon/intergration, click add virtual switch, then select the type of sensor you want it to control… (amazon open and closed)(google home and away) what ever you decided to name that switch is the name of the senor it controls too so lets this was a feature…

you open up home assistant go to devices add (then select virtual switch, a box pops up asking you what type of sensor you want this to control (open/close, home/away) give it a name and its added as two entities one for switch and one for sensor under the same name, the switch controls the state of the sensor.

this will the trigger routines in both eco systems.

1 Like

a good example is the ring one and by having to add some code to aws (amazon web services which is not very user friendly without guides) it errors a lot done the boolean way. With the virtual switch and routine it works all the time flawlessly and someone rings the doorbell live view of ring pops up on my tablet.

using the same virtual switch a routine also opens up my driveway camera as a preview (pip on TV fire fire tv) and a seperate one starts pip on the upstairs tv (android one). without me having to ask alexa or google to show them.

My robot vac works with alexa and google but not home assistant so a virtual switch that controls which ever eco system I have tied to allows me to control it via a automation (alexa in this case)

my point of this is due to HA moving towards being more user friendly I was thinking this would be a easier way.

1 Like

This was the point to my first post, I completely understand your usage case but the only thing you can do with this that is any use in the google eco system is to basically incorrectly toggle google home and away setting to achieve anything and this would not be a use case that most people would want and or use as incorrectly toggling or using the google home / away setting would likely have an adverse affect on other google routines.

example my google routine is more morning related but only plays the music if the wife is out already (so I am thinking another person (is really a device) surely that would work too…

And I assume that this morning routine is triggered by a time trigger or switching an alarm off for example.

My point is that in google routines you cannot Trigger a google routine of off any exposed state. I have multiple sensors and switches exposed from home assistant to google and not one of them can be used by google routines as a trigger for any routine within google. So your proposed use case is not relevant to google.

I know this is an old post, but I’m trying to do the same thing, and wanted to find out if you ever found a solution on HA.

What I want is the equivalent to bjpeirrons Simulated Alexa Switch, device class.

This creates a virtual device that has two entities, one a switch (on/off), one a sensor (open/closed)

The key is that the switch and sensor are virtually tied, so that if the switch is on, the sensor reads open, and when the switch is off, the sensor reads closed.

The use cases are primarily for Alexa, but no reason it couldn’t be made compatible with Google Home, and provide a switch which Alexa can turn off or on, and a sensor that can be used to trigger routines.

Example use:

Any device that can’t be directly integrated into HA, but does have Alexa compatibility.

  1. I have a Wyze door sensor, when the sensor is opened, I trigger a routine to turn on the virtual switch, and when the sensor is closed, I trigger a routine to turn off the virtual switch.

This automatically changes the state of the virtual devices sensor (switch on → sensor open, switch off → sensor closed).

This would allow the two way control/communication between Alexa and HA, allowing HA to “see” the state of the Wyze door sensor.

  1. I can use the virtual device to trigger Alexa routines. By exposing the door sensor entity of the virtual device, I can then use the new Alexa sensor as a trigger for any routine. By setting the switch on, the door sensor entity would open, and any Alexa routine using the virtual sensor would be triggered.

The key part is to have the ability to create these virtual switch/sensor devices, and have the state of the switch and sensor be synchronized automatically, no automations needed.

Hopefully, in the interim, you have discovered the way to do this! It’s really the last part of my transition from SmartThings to HA, and I’d like to get it done!

Your request is probably unrelated to this feature request thread, which by the way is somewhat resolved by the input boolean helpers these days.

You might want to look into input boolean, helpers, and template:
Input Boolean - Home Assistant (home-assistant.io)
Integrations #helper - Home Assistant (home-assistant.io)
Template - Home Assistant (home-assistant.io)

Thanks for that pointer, I think this is exactly what I was searching for to deal with using motion to turn on and then turn off a light, but only if the light was not already turned on: this has problems if using the current light on state to determine if the automated light on should run when multiple motion detections are triggered in a rwo, but the light was originally off.

yes this was muted, just create a input toggle button, expose to your flavour google or alexa and then set routine to toggle it. job done