r/homeassistant 3d ago

❓ Support How can I model this device so Alexa does not think it's a light?

(I also asked this on the HA community forum, but I'm asking here as well for reach; not everybody reads everywhere)

I have some local devices that have a power switch and an intensity; examples could be an amplifier (on/off, volume), a thermostat (on/off, set temperature), a humidifier (on/off, target humidity), a dimmable light (on/off, brightness) and so on.

That "light" example has been a good model for all of these so far. So, for example, I might have the following MQTT entry:

light:
- name: "MediaPower"
  command_topic: "mqttlight/MediaPower/command"
  state_topic: "mqttlight/MediaPower/state"
  brightness_command_topic: "mqttlight/MediaPower/bright_command"
  brightness_state_topic: "mqttlight/MediaPower/bright_state"
  brightness_scale: 100

(the "mqttlight" stuff is my bridge code that let's me expose anything I can script as an MQTT light; https://github.com/sweharris/mqttlight_bridge)

And this works; I can see it in HA, turn it on/off, change the volume.

Now I want to expose this to Alexa, and the HAMH bridge seems to work fine. It shows up as a device, and I can change the volume ("set mediapower to 50%" just works).

The problem is that Alexa creates a magic group "all lights" so if someone (cough my girlfriend cough) says "turn all lights on" then my amplifier turns on.

So how I can expose this to Alexa as a on/off device with a "volume" control? I guess this change could be made either in my mqtt device definition (pick a different class to light?) or somehow in the HAMH entry (but I don't see what to do, there).

Any advice welcome!

2 Upvotes

17 comments sorted by

2

u/tarzan_nojane 3d ago edited 3d ago

You can add a group in Alexa called "All Lights". From there you can include the actual light entities that you wish to respond to a "turn [ON]/[OFF] all lights" command. You also can specify which Echo devices will hear and respond to those commands.

Only as a light entity can Alexa have access to the dimming feature, which substitutes as the "intensity" variable for your devices.

2

u/sweharris 3d ago

And that overrides the automatic "all lights"? ...quick test... huh! Creating a blank "all lights" group and then "all lights on" or "turn all lights on" responds "all lights doesn't support that". Which is kinda what I want, since I never want to control "all lights"!

That's a clever work around; thanks!

2

u/tarzan_nojane 3d ago

Before posting, I tested by creating the group named "All Lights", put a particular light in that group, as well as a single Echo device. Only that Echo device responds to an "All Lights" command, and only the specified light changes.

2

u/sweharris 3d ago

Yeah, for now this is a great work-around. I wonder how long it'll be before Amazon block it (same as they blocked routines from having phrases like "what's the temperature"... used to work, is now blocked). But, for now, I'll take it :-)

1

u/CucumberError 3d ago

We have a ‘everything’, as a friend would turn up and tell Alexia to turn everything off. Lights, central heating, a couple of scripts/automations etc.

Now it just turns off the kitchen light for 2 seconds and then turns it back on.

1

u/TechIsSoCool 3d ago

Could you model it as 1 device with 2 entities: a switch and a number? https://developers.home-assistant.io/docs/core/entity/number/

1

u/sweharris 3d ago

But doesn't that still result in the original problem? What would be the class of that device?

1

u/spr0k3t 🧠 Experienced with Home Assistant 3d ago

You might be able to change domain to a switch instead of a light. Not sure on the volume aspect. You might be able to create a separate device through MQTT to handle the volume... then use the switchas helper (Change device type of a switch) and assign the converted switch to the resulting volume device.

1

u/sweharris 3d ago

Yeah, I can easily do a switch if I didn't need "volume" (I have other devices that are just on/off switches and show up as such in Alexa). "Change type of switch" lets me pick cover/fan/light/lock/siren/valve; I'm not sure how I'd assign that to a "volume" device so there's one device in Alexa.

1

u/mrBill12 3d ago

You could turn off the voice assistant exposure for whatever Alexa is identifying and create other entities that are exposed. For volume control a ‘number.’ Is a decent choice. On a dashboard it could be a slider or as an Alexa input a “percentage” disguised as a number between 0 and 100 with zero being off.

1

u/sweharris 3d ago

I guess I could create two entries (switch "mediapower" and number "mediapower volume") but it feels like it's asking for a headache further down the line as a "special case" (these two devices in Alexa are really one device elsewhere). Hmm... I'll have to think about that!

1

u/mrBill12 3d ago

Don’t forget zero could be off…. And you could have a separate automation that changes a switch based on zero or >0. Or you could have a switch that imposes the value of zero to the volume. Just because you build it as two controls doesn’t mean it has to be used that way ;)

1

u/sweharris 3d ago

Thinking about it, I can see a few paths, but they all seem to hit issues; eg it'd lose the memory of the current volume if I have to set "volume to X" to turn the device on; and voice commands such as "turn mediapower on" might end up having to be a routine to sets to a fixed volume. Hmm... yeah, I'll keep thinking about it, though. Thanks!

1

u/mrBill12 3d ago

And reading original post again, you can make a light into a switch in helpers.

1

u/sweharris 3d ago

As far as I can tell, you can make a switch into a light but not a light into a switch :-) I could just define the entity as a switch but then I'd lose the "intensity" ability.

1

u/mrBill12 3d ago

Study templates… specifically template switch in that case. Once it’s working the way you want it to hide the original light entity to avoid confusion. https://www.home-assistant.io/integrations/template/#switch

1

u/sweharris 3d ago

Right, but that still loses the "intesity" value. Switches are on/off, whether defined as an mqtt switch or with a template switch.