Working on multiple emulated_hue instances

I’ve been playing with Home Assistant over the last few weeks. I’m trying to integrate my home automation services with Alexa through HA’s emulated_hue.

I have a Centralite lighting control system with some 48 loads. That combined with HAI thermostats, HAI HiFi 2 zones, etc. - I’m running into the 49 device limit with the current implementation.

I’ve decided to hack emulated_hue to support a configuration like this:

emulated_hue:
  hue1:
    listen_port: 8300
    exposed_domains:
        - light
  hue2:
    listen_port: 8301
    exposed_domains:
        - climate
        - group
        - media_player
  hue3:
    listen_port: 8302
    off_maps_to_on_domains:
    exposed_domains:
        - script

Then in the setup function I have a loop to iterate through the hue configurations - similar to the Group and Script parsing.

    for object_id, conf in yaml_config.get(DOMAIN, {}).items():
        config = Config(conf)

Let me know if there some other way to solve this problem or if there are any plans to support a mechanism to overcome this 49 device issue.

Thanks.

3 Likes

This modification seems to be working. I have three instances of emulated_hue’s. This has allows all of the lights, media players, thermostats, etc. to be exposed to my Echo - a total of 90 Smart Home devices.

1 Like

This is great. Actually, I am planning to install multiple Echo Dots in my house. One for the living room, one for the bedroom, one for the office. With current setup, I have to say “Alexa, turn on living room lights” or “Alexa, turn on office lights”. What I want is, when I am in the living room and I wanted to turn on the lights, I just say “Alexa, turn on the lights” and when I am in the office, I would just say the same for the office lights. Right now, I can’t because I cannot assign “Lights” to both living room lights and office lights.

I am thinking of using separate Amazon accounts for each Dots and each accounts will contain their own list of devices and the list of devices is provided by the specific emulated_hue instance in HA.

Is it possible for Alexa to discover devices only from a specific port and not from others?

I created this hack to get around the limit of the number of devices.

But, you bring up a good question.

The Echo uses a multicast discovery mechanism to find devices.

One way to solve this issue of having different Echo discover different devices is by segregating the networks. You could create separate vlans. The Echos would each have to be connect to separate vlans and the HA server would have to have multiple IP address each on a different vlan. Then you would have to have switches that supported vlans to keep all of this traffic separate. Lastly you have have to have a router that also support vlans so the Echos go get out to the Internet. – All kind of complicated. I have a pretty complicated network at my house that could support alll of this - but would be a real pain to configure.

Or, a much simpler mechanism would be to modify the emulated_hue component’s UPNPResponderThread to respond to different Echos with different emulated_hue address.

Modifying the configuration from above you might have something like this:

emulated_hue:
  hue1:
    listen_port: 8300
    echo_ip: 192.168.1.21
    exposed_domains:
        - living_room_lights
  hue2:
    listen_port: 8301
    echo_ip: 192.168.1.22
    exposed_domains:
        - bedroom_lights
  hue3:
    listen_port: 8302
   echo_ip: 192.168.1.23
    exposed_domains
       - office_lights

Then in the upnp handler you would match the emulated_hue instance against the echo_ip address and only respond to queries for the exposed_domains for that instance.

I have not written any code to verify this. But, off the top of my head, it seems doable.

The next problem to solve would be the device names for the different rooms. You would need to look into reporting just ‘lights’ as a device or set of devices to Echo. I’m sure there is something simple that could be done to report the right device names.

1 Like

thanks for your suggestion. However, i have no experience in VLAN and I couldn’t find any features that mention VLAN in my router (Asus RT-AC68U). May I know what router are you using?

I think I know an easier way to accomplish what I want.

  1. Add all the devices (living room, office, etc) using the existing emulated hue bridge.
  2. Create separate Amazon account for each Echos.
  3. Let each Echos discover all the devices exposed by the bridge.
  4. Then go to Alexa app for each accounts and delete the devices not needed for each rooms.
  5. In the Alexa app, create a group with the desired name (e.g. Lights) and add the related devices into the group.

I haven’t try it out but I believe this doable.

2 Likes

I’m working on moving my changes to the latest emulated_hue code.

I believe that something like what I show in the config above will work.

I’m changing the name from ‘echo_ip’ to ‘target_ip’. What it does is only report the address for the emulated_hue to that particular ‘target_ip’ (meanin - echo or google home.

I’ll let you know how it comes along.

That sounds good.

Anyway, isn’t exposed domain suppose to be light, switch, group, script, etc… which doesn’t include the entity ID? Or do you plan to change the behaviour of emulated hue component to use entity_id in the config?

I’m thinking something like this (not positive about the syntax):

emulated_hue:
  hue1:
    type: alexa
    advertise_port: 8305
    listen_port: 8305
    target_ip: 192.168.1.21
    exposed_domains:
      - group
         remap:
           - entity_id:  light.livivng_room
             alias: lights
  hue2:
    type: alexa
    advertise_port: 8306
    listen_port: 8306
    target_ip: 192.168.1.22
    exposed_domains:
      - group
         remap:
           - entity_id:  light.bedroom
             alias: lights

This remap would indicate that when emulated_hue reported the group domain to the echo (192.168.1.21) as hue1 it replaces “light.livivng_room” with “lights”. Also, if there is a request from the echo to the port 8305 (hue1) for “lights” it will be remapped back to “light.living_room”.

This is just an idea.

I’m having trouble getting the new HA version updated. I’m going to revert to .36 to get back to a common starting point.

Let me know what you think about the remap/alias idea.

Actually - this might now work at all for separate echo’s with one account.

@masterkenobi, you might be right about trying different accounts.

I’m still playing with this idea.

I finally plugged in my second Echo. And I believe it is going to be a problem to get a split in discovered devices since they are all reported to the same account.

But, I do have the target_ip working. Here’s a sample config -

q_emulated_hue:
  hue1:
    type: alexa
    listen_port: 8301
    target_ip: 192.168.1.110
    exposed_domains:
      - script
  hue2:
    type: alexa
    target_ip: 192.168.1.110
    listen_port: 8302
    exposed_domains:
      - light
  hue3:
    type: alexa
    target_ip: 192.168.1.110
    listen_port: 8303
    exposed_domains:
      - climate
  hue4:
    type: alexa
    target_ip: 192.168.1.110
    listen_port: 8304
    exposed_domains:
      - fan
  hue5:
    type: alexa
    target_ip: 192.168.1.110
    listen_port: 8305
    exposed_domains:
      - group

This is five emulated hues with ports that range from 8301 to 8305. I modified the emulated_hue to iterate through the configuration and spawn five UPNPResponderThread’s. This also creates five HomeAssistantWSGI server instances with different service ports.

I had to add a random sleep to each thread so the responses aren’t lost before they get back to the Echo. I might look at refactoring this later.

I’m using the target_ip here to response to only one Echo. There can be ‘a lot’ of multicast traffic on my network with macs, routers, Plex servers, etc. - constantly looking for UPNP devices on the network. By specifying a target_ip the emulated_hue will only respond to requests from the IP. And since the Echo’s share an account - I only need to send responses to one of them.

Note - this configuration is really just to test the changes. I will probably only need two instances of emulated_hue’s. My light domain has 48 entities. So, it will be configured for one emulated_hue. The rest of the domains will go on the other emulated_hue.

Looks like I’ll be able to support the emulated_hue: True attribute for entities as well.

Instead of using True you can specific the specific emulated_hue instance you want the device to be reported from.

emulated_hue: hue1

1 Like

I have a simple single emulated_hue

emulated_hue:
  host_ip: 192.168.1.239
  type: alexa
  expose_by_default: true
  exposed_domains:
    - switch
    - script
    - light

and I have 138 discovered devices. Although the scene from HASS are not uploaded (not a single one).

Even if I put -scene

That’s interesting. I have tested several times exposing my devices. Last time I tried it was 76 device. I moved domains to one emulated_hue, clicked Alexa “Forget all devces…”, then “Discover Devices”. Web page spins for a while - then shows now devices were found.

I’ll be able to test some more combinations this weekend.

Is there something different you are doing to learn you devices?

Also - did you check your emulated_hue API URL:

http://<HA IP Address>:8300/api/pi/lights

like this never happened to me.

I am not sure what I did in the past, before adding “scene” to my configuration I did not know there was a 49 limitation.
I arrived also at 150+ devices , and I think there are (I can;'t be sure there are all, I never look deeply into it:

  • all my script (named dimmable light
  • all my switch (named dimmable light)
  • all my hue lights (named color light or hue light, never know the difference)
  • all my hue scene (named scene connected to hue)
  • all my hue rooms (named room xxxx connected via hue)
  • all my lights not hue (like yeelight, flux_led)

But I can’t give SCENE from HASS, last time I tried it messed up and lost lot of devices, but did not check which and what, because I reverted and took out SCENE.

I wonder if with your trick of multiple emulated hue will work

yes this

{“light.entrance”: {“modelid”: “HASS123”, “name”: “Entrance”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.entrance”}, “light.foyer_strip”: {“modelid”: “HASS123”, “name”: “Foyer strip”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.foyer_strip”}, “light.front_yard”: {“modelid”: “HASS123”, “name”: “Front yard”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.front_yard”}, “light.gateway_light_f0b429aa0aa8”: {“modelid”: “HASS123”, “name”: “Livingroom night light”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.gateway_light_f0b429aa0aa8”}, “light.hallway_left”: {“modelid”: “HASS123”, “name”: “Hallway left”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.hallway_left”}, “light.hallway_upstairs”: {“modelid”: “HASS123”, “name”: “Hallway upstairs”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.hallway_upstairs”}, “light.kitchen_one”: {“modelid”: “HASS123”, “name”: “Kitchen one”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.kitchen_one”}, “light.kitchen_three”: {“modelid”: “HASS123”, “name”: “Kitchen three”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.kitchen_three”}, “light.kitchen_two”: {“modelid”: “HASS123”, “name”: “Kitchen two”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.kitchen_two”}, “light.living_table_lamp”: {“modelid”: “HASS123”, “name”: “Living table lamp”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.living_table_lamp”}, “light.livingroom”: {“modelid”: “HASS123”, “name”: “Livingroom”, “state”: {“bri”: 254, “on”: true, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.livingroom”}, “light.master_bedroom”: {“modelid”: “HASS123”, “name”: “Master bedroom”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.master_bedroom”}, “light.tv_room”: {“modelid”: “HASS123”, “name”: “TV room”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “light.tv_room”}, “script.avr”: {“modelid”: “HASS123”, “name”: “AVR”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.avr”}, “script.avr_blu_ray”: {“modelid”: “HASS123”, “name”: “AVR on Blu Ray”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.avr_blu_ray”}, “script.avr_cast_audio”: {“modelid”: “HASS123”, “name”: “AVR on cast audio”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.avr_cast_audio”}, “script.avr_cast_tv”: {“modelid”: “HASS123”, “name”: “AVR on cast TV”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.avr_cast_tv”}, “script.avr_server”: {“modelid”: “HASS123”, “name”: “AVR on server”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.avr_server”}, “script.colorloop_garden”: {“modelid”: “HASS123”, “name”: “colorloop_garden”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.colorloop_garden”}, “script.colorloop_livingroom”: {“modelid”: “HASS123”, “name”: “colorloop_livingroom”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.colorloop_livingroom”}, “script.di_buonanotte”: {“modelid”: “HASS123”, “name”: “di_buonanotte”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.di_buonanotte”}, “script.fire_place”: {“modelid”: “HASS123”, “name”: “Fire place”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.fire_place”}, “script.forest_sounds”: {“modelid”: “HASS123”, “name”: “Forest sounds”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.forest_sounds”}, “script.its_time_for_lunch”: {“modelid”: “HASS123”, “name”: “It’s time for lunch”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.its_time_for_lunch”}, “script.projector”: {“modelid”: “HASS123”, “name”: “Projector”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.projector”}, “script.projector_power”: {“modelid”: “HASS123”, “name”: “Projector power”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.projector_power”}, “script.wave_sounds”: {“modelid”: “HASS123”, “name”: “Wave sounds”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “script.wave_sounds”}, “switch.amplifier”: {“modelid”: “HASS123”, “name”: “Amplifier”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.amplifier”}, “switch.asus_router”: {“modelid”: “HASS123”, “name”: “Asus router”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.asus_router”}, “switch.blu_ray”: {“modelid”: “HASS123”, “name”: “Blu ray”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.blu_ray”}, “switch.camera_flash_gt9192”: {“modelid”: “HASS123”, “name”: “GT9192 Camera Flash”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.camera_flash_gt9192”}, “switch.camera_flash_note3”: {“modelid”: “HASS123”, “name”: “Note3 Camera Flash”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.camera_flash_note3”}, “switch.camera_nv_gt9192”: {“modelid”: “HASS123”, “name”: “GT9192 NightVision”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.camera_nv_gt9192”}, “switch.camera_nv_note3”: {“modelid”: “HASS123”, “name”: “Note3 NightVision”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.camera_nv_note3”}, “switch.cast_power”: {“modelid”: “HASS123”, “name”: “Cast power”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.cast_power”}, “switch.christmas_tree_lights”: {“modelid”: “HASS123”, “name”: “Christmas tree lights”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.christmas_tree_lights”}, “switch.entrance_camera_presets_2_3”: {“modelid”: “HASS123”, “name”: “Off (door) - On (living) - Entrance cam”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.entrance_camera_presets_2_3”}, “switch.hdmi_cast”: {“modelid”: “HASS123”, “name”: “HDMI Cast”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.hdmi_cast”}, “switch.hdmi_tv”: {“modelid”: “HASS123”, “name”: “HDMI TV”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.hdmi_tv”}, “switch.marisol_heater”: {“modelid”: “HASS123”, “name”: “Marisol heater”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.marisol_heater”}, “switch.office_camera_presets_1_2”: {“modelid”: “HASS123”, “name”: “Off (inside) - On (outside) - Office cam”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.office_camera_presets_1_2”}, “switch.optoma”: {“modelid”: “HASS123”, “name”: “Optoma”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.optoma”}, “switch.plug_158d000128c617”: {“modelid”: “HASS123”, “name”: “Plug_158d000128c617”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.plug_158d000128c617”}, “switch.soundbar”: {“modelid”: “HASS123”, “name”: “Soundbar”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.soundbar”}, “switch.tv”: {“modelid”: “HASS123”, “name”: “TV”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.tv”}, “switch.unassigned11”: {“modelid”: “HASS123”, “name”: “unassigned11”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.unassigned11”}, “switch.walking_closet”: {“modelid”: “HASS123”, “name”: “Walking closet”, “state”: {“bri”: 0, “on”: false, “reachable”: true}, “swversion”: “123”, “type”: “Dimmable light”, “uniqueid”: “switch.walking_closet”}}

maybe in the past I did soemthing different, but can’t remember: most probably not … but I have since long time the emulated_hue command as posted above

Just to let you know - I counted the number of devices in this API output. There are only 48 devices listed.

Note: this is the URL that is queried by the Echo to get the list of devices. So, I’m not sure how your Alexa account gets updated with more than these 48 devices.

I’m still working on this emulated_hue idea. But, this is helpful info.

Sorry, don’t have any current info on why ‘scene’ might be an issue. I’ll have to look at the code I hacked on to see if anything is different around that domain.

How many scene entities do you have?

Ohh I never did …

I counted the Alexa devices in the Alexa up, and they are 138 …