Emulated Hue device discovery not working fix

I found numerous topics with the same problem i was facing…
My “emulated_hue” component was setup, but the alexa app did not find any device.

  1. Emulated Hue Not Working At ALL!
  2. Docker Emulated Hue UPNP not working
  3. Emulated Hue entities not showing

My understanding was that i had a working http entpoint (port 80 for me) that lists my ligths. but the ssdp/upnp service (port 1900) used by alexa to find this entpoint was not accessible.
As far as i can tell there is no option expose additional ports on a hassi/hassos installation.

What i did find is the old code from Bruce Locke used before it was integrated into ha. With this i was able to start the ssdp/upnp service locally (not on my pi running ha). This allows alexa to discover my ha and setup the lights. It only needs to run for the setup of new devices and more ore less only tells alexa the ip address of my ha.

  1. Place the following code in something.py file
#!/usr/bin/env python3

#
# https://github.com/blocke/ha-local-echo
# Released under MIT license - Copyright 2016 - Bruce A. Locke <[email protected]>
#

import requests
import threading
import socket
import time
import datetime
import re
import sys
import zlib

# Config
HA_BASE_URL = "http://127.0.0.1:8123"
HA_API_KEY = None
LISTEN_IP = "192.168.10.250"
HTTP_LISTEN_PORT = 8000

#
# UPNP Responder Thread Object
#
class UPNPResponderThread(threading.Thread):

    UPNP_RESPONSE = """HTTP/1.1 200 OK
CACHE-CONTROL: max-age=60
EXT:
LOCATION: http://192.168.5.2:80/description.xml
SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/0.1
ST: urn:schemas-upnp-org:device:basic:1
USN: uuid:Socket-1_0-221438K0100073::urn:schemas-upnp-org:device:basic:1

""".format().replace("\n", "\r\n").encode('utf-8')

    stop_thread = False

    def run(self):

        # Listen for UDP port 1900 packets sent to SSDP multicast address
        print("UPNP Responder Thread started...")
        ssdpmc_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        # Required for receiving multicast
        ssdpmc_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        ssdpmc_socket.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_IF, socket.inet_aton(LISTEN_IP))
        ssdpmc_socket.setsockopt(socket.SOL_IP, socket.IP_ADD_MEMBERSHIP, socket.inet_aton("239.255.255.250") + socket.inet_aton(LISTEN_IP))

        ssdpmc_socket.bind(("239.255.255.250", 1900))

        while True:
            try:
                data, addr = ssdpmc_socket.recvfrom(1024)
            except socket.error as e:
                if stop_thread == True:
                    print("UPNP Reponder Thread closing socket and shutting down...")
                    ssdpmc_socket.close()
                    return
                print ("UPNP Responder socket.error exception occured: {0}".format(e.__str__))

            # SSDP M-SEARCH method received - respond to it unicast with our info
            if "M-SEARCH" in data.decode('utf-8'):
                print("UPNP Responder sending response to {0}:{1}".format(addr[0], addr[1]))
                ssdpout_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                ssdpout_socket.sendto(self.UPNP_RESPONSE, addr)
                ssdpout_socket.close()

    def stop(self):
        # Request for thread to stop
        self.stop_thread = True

# Global Variables
upnp_responder = UPNPResponderThread()
time.sleep( 5000000 ) // dont know any python and need the service to run for some time 
  1. Replace the ip from LOCATION: http://192.168.5.2:80/description.xml with your ha installation.

  2. Start the code with python something.py

  3. Use the alexa app to sereach for devices :smiley:

Hope this helps someone and if i missed something please let me know.

Seems like this needs to be added into the component… People have been looking for this fix for quite some time. I’ll look into this.

1 Like

The code does not work. Need to change the comment at the end.Also whoever uses this might want to change the sleep time, that is way too long :slight_smile: Also when the script runs, it does not help with the issue for me.

My emulated_hue was working fine yesterday with Alexa but suddenly today morning all the devices were unreachable and Alexa is unable to find any of them.

Edit: For my problem with emulated_hue, I was missing listen_port: 80 from my config so Alexa could not find devices from default port of “8300” se when I added the listen_port: 80 to emulated_hue config it started working.

What firmware is on your echos?

Echo is on645582720 and HA latest 0.98.1

I don’t see that firmware listen on amazons website.

I’m starting to wonder if the Amazon page is up to date. https://www.amazon.com/gp/help/customer/display.html?nodeId=201602210

It’s newest, you can found identical webpage if you google “Echo 645582720”. Page is hosted on Amazon IP.

I’m guessing that this firmware is really new since now there is all sorts of problems with emulated_hue. Alexa is always tellin me that my computer is malfunctioning but still everything turns on and off like I want to. Computer is switch in HA, I also have other stuff on HA that are scripts and those work still fine and Alexa responds “OK” when turning them on.

I also have echo dot (first gen I believe) and it has the same problems. Everything works but with error message. Actually I noticed that in the app there are now error message “Device does not support requested values” so Amazon has changed something in the newest firmwares. The Echo dot firmware is 644580520 and it is EU model (Germany) and my Echo gen 2 is US model.

Edit:
It is also mentioned in this link that the Amazon page is not up to date and echos (2nd gen) version is the one I mentioned. Page is in german but used google translate :slight_smile:

1 Like

Hmm, seems like we’ll need to make some changes to emulated hue then. I don’t have the firmware update yet. I’ll try to hold off on it for now.

1 Like

For me, everything is fine. It is annoying when Alexa complains about device but everything works so I’m not in hurry. For those that are unable to discover devices I recommend adding the listen_port: 80 to emulated_hue, that helped me in discovering. Tried changing to other port and it failed.

that’s good to know for discovery. It was never needed in the past. I’ll pass the info on to another thread.

Just throwing this out there… may or may not be pertinent to some of the issues people are having… there was a change in 0.98 in the emulated_hue component to tell hue if the light supported brightness or not… for me it made a template light not available to Alexa… when looking at api/pi/lights it listed the template light as “HASS321” for the model or whatever (part of the changes here … that was the only light that was NOT “HASS123” … adding “set_level:” to the template light suddenly changed it to “HASS123” and it was showing up in alexa again.
So my thought was, because I only have a few different types of bulbs, maybe whatever type of bulbs/light components people are using are by default being listed as “HASS321” which apparently Alexa doesn’t like…
I guess it’s more of a question of my behalf… does anyone have any lights listed in api/pi/lights that show has “HASS321” that Alexa actual discovers? For me it seems those devices never show up but the ones listed as “HASS123” work fine.

Hi All,
My config is pretty simple but exposes multiple switches and scenes also, Alexa will identify some but then instantly mark as unresponsive and not work. Upgraded to 98.5 incase that would help but no luck and the above script not helping either. Can anyone confirm if it does work over port 80 only now?

Its not ideal for me to test as using port 80 for a website from same Pi s my HA installation which is why using the default 8300 previously.

emulated_hue:
  host_ip: 192.168.1.12
  listen_port: 8300
  off_maps_to_on_domains:
    - script
  expose_by_default: false
  exposed_domains:
    - switch
    - script
    - scene

Thanks

I finally got alexa to descover devices. Using port 80 for the listen port. Problem i have now is i can turn lights on but then in the alexa app it says the light is off and also has a error message. Device doesnt support requested value.

The potential fix for this issue hasn’t been merged yet.

https://github.com/home-assistant/home-assistant/pull/26541

3 Likes