How to run emulated hue from a docker container?

I am running Home Assistant inside a docker container (not using host mode) and I am unable to get the hue emulation to work. My current docker compose config for Home Assistant:

homeassistant:
    container_name: homeassistant
    restart: unless-stopped
    image: homeassistant/raspberrypi4-homeassistant
    volumes:
      - ${DATADIR}/homeassistant/config:/config
      - /etc/localtime:/etc/localtime:ro
      - /dev/serial/by-id/:/dev/serial/by-id/
    ports:
      - 8123:8123
      - 80:80
    cap_add:
      - NET_BIND_SERVICE
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - TZ=${TZ}

and the hue config:

# hue emulation
emulated_hue:
  listen_port: 80
  host_ip: 192.168.2.4 # which is the IP of the pi running docker
  expose_by_default: true
  exposed_domains:
    - light

This is resulting in the following error at startup:

Error during setup of component emulated_hue
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/setup.py”, line 215, in _async_setup_component
result = await task
File “/usr/src/homeassistant/homeassistant/components/emulated_hue/init.py”, line 131, in async_setup
listen = create_upnp_datagram_endpoint(
File “/usr/src/homeassistant/homeassistant/components/emulated_hue/upnp.py”, line 73, in create_upnp_datagram_endpoint
ssdp_socket.setsockopt(
OSError: [Errno 99] Address not available

Does anyone know what is causing this or how to fix it? Do I need to also add advertise_ip to the config or add some UPNP ports?

try

  host_ip: 127.0.0.1
  advertise_ip: 192.168.2.4

Thanks, that seems to help in a way. It starts without an error now. Nothing is found by Alexa though and http://192.168.2.4/description.xml can not be found in the browser. Current config

emulated_hue:
  listen_port: 80
  host_ip: 127.0.0.1
  advertise_ip: 192.168.2.4
  expose_by_default: true
  exposed_domains:
    - light

Do I need to update any port settings too?

It may be that inside the container there are still port/permission issues, try listening on 8300 and changing the docker forwarding from 80 to 8300

Very good idea, I also tried that. Not sure what I am doing wrong though. Added

ports:
      - 8123:8123
      - 80:8300

and used the settings above with listen_port: 8300 but I am still not able to see the description.xml file. Is there a way to enable debug logs just for the emulation? Would like to know if there is an error there or in my general port/ip setup

Did you ever get this working? I’m looking into this myself and running into similar issues. Just looking for clues.

No unfortunately not. I had to switch to host mode

Would you be willing to provide a simple HOW TO as I cannot even verify that emulated_hue integration has been loaded.

1 Like

In what sense? did you somehow manage to connect the home assistant devices on alexa? if so, could you show me the way?

What worked for me was setting a static ip for home-assistant in docker-compose.yml and using that same ip in the emulated hue config.

192.168.2.4 = docker host ip
192.168.10.6 = static ip for docker container

Example hue config:

  host_ip: 192.168.10.6 
  listen_port: 80
  advertise_ip: 192.168.2.4
  upnp_bind_multicast: false
  expose_by_default: false
  entities:
    light.living_room:
      name: Emulated Living Room Lamp
      hidden: false

Example docker-compose.yml

    image:  homeassistant/home-assistant:latest
    container_name: homeassistant
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
    volumes:
      - /home/user/docker/homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
    ports:
      - 8123:8123 #access home assistant
      - 1900:1900/udp #SSDP Discovery and uPNP
      - 5353:5353/udp #mDNS
      - 5683:5683/udp #Shelly
      - 80:80 #Emulated Hue
    restart: unless-stopped
    networks:
      homenet:
        ipv4_address: 192.168.10.6