Virtual momentary switch that resets its state?

I’m playing around with the new Emulated Hue Bridge in 0.27, and it is awesome! One little config entry, and my devices are exposed to Alexa for turning on/off.

I’d like to have a way to activate scenes using this method. Adding “scene” to the exposed_domains parameter doesn’t seem to do anything. (The docs don’t say explicitly it’s not supported, but it doesn’t seem to work.)

When I was doing this with SmartThings, I would setup virtual momentary switches that Alex saw as regular switches. I would create a virtual momentary switch called, for example, “Movie Mode”, create a rule in SmartThings tying it to the equivalent of a scene, and then I could tell Alexa to “Turn on movie mode”. The key was that since it was a momentary switch, it would immediately revert to the “off” position, allowing it to be called again and again. Perfect for scripts and scenes and the like.

I’d like to create virtual momentary switches in Home Assistant, but I’ve searched around and can’t figure out how. I have plenty of stateful virtual MQTT switches like this:

- platform: mqtt
  name: "Sleeping"
  state_topic: "nfc/sleeping"
  command_topic: "nfc/sleeping"
  qos: 1
  payload_on: "yes"
  payload_off: "no"
  retain: true

How can I do a momentary-style one?

Create a regular input_boolean, then in the automation where you respond to it, also add an action to set its state to off again.

1 Like

Ok, I should have thought of that. :slight_smile: Thanks

1 Like

From what I can tell, Scripts and Scenes are supported directly by the emulated hue, you just don’t put them under exposed_domains, as they are listed under off_maps_to_on_domains, as seen in their example:

emulated_hue:
  host_ip: 192.168.1.186
  listen_port: 8300
  off_maps_to_on_domains:
    - script
    - scene
  expose_by_default: true
  exposed_domains:
    - light

This way, the emulated hue should pick them up and they will be turned on with either an on or off call

As for the momentary switch option, aimc is correct… here is what I use for my Garage Door, which is a relay swtich:

alias: 'Toggle Garage Door Relay'
sequence:
  - service: switch.turn_on
    entity_id: switch.evolve_guest_controls_lfm20_fixture_module_switch_34
  - delay:
      seconds: 5
  - service: switch.turn_off
    entity_id: switch.evolve_guest_controls_lfm20_fixture_module_switch_34

Although this is a script, you can use the same in the action of an automation

alias: 'Movie Mode Momentary Switch'
trigger:
  platform: state
  entity_id: input_boolean.movie_mode
  state: 'on'
action:
  - delay:
      seconds: 5
  - service: input_boolean.turn_off
    entity_id: input_boolean.movie_mode

My scenes and scripts are definitely not being discovered by Alexa, and I’ve played around with all the different config options for the new emulated hue component. I can turn individual lights on and off, but other than lights and switches nothing else is being detected by Alexa.

I’m still messing with it but I think I’m going to file a bug. I’m seeing some errors in the log too that don’t make sense to me.

Was you able to figure this out?

I also have a few scenes I created in HA, and wanted Alex to run them on demand. It seems Alexa only sees the light switch and not scenes in the Hue bridge emulator.

Yes, it works for me now. The key for me was setting expose_by_default to false, because I have a lot of devices and Alexa/Echo won’t discover any of them if you have more than a certain amount (I think 49). It just kind of silently fails.

So after setting expose_by_default to false, and then going through and adding emulated_hue: true to individual devices/scenes that I specifically wanted Alexa to discover, it worked.

Thanks for this information. I was wondering why I couldn’t control certain things via Alexa and I guess my list was full. On the bright-side (after an hour of editing customize.yaml) now I can control my garage door with voice command!

jbardi, I’ve tried your automation as above, and a few variations, but the following error appears in the logs:

homeassistant.bootstrap: Invalid config for [automation]: [delay] is an invalid option for [automation]. Check: automation->action->0->delay.

Is there anything else required to make the action run script commands?

Thanks!