Emulated Hue stops working after a few hours

I am using the built in emulated_hue component with a google home.

After HASS (version 0.46.1) starts, emulated_hue works perfectly fine but eventually, after a few hours, google home eventually stops being able to control the emulated_hue components. Restarting HASS fixes it again.

There are no errors in home-assistant.log related to the hue component (I did have an error related to pychromecast failing to connect though).

2017-07-14 17:32:27 WARNING (Thread-31) [pychromecast.socket_client] Error communicating with socket, resetting connection
2017-07-14 17:32:27 ERROR (Thread-31) [pychromecast.socket_client] Failed to connect, retrying in 5.0s

I am running a tcpdump on port 80 (where I have the hue_emulator listening) and I don’t see any inbound traffic when the issue is occurring (traffic only starts coming in on port 80 after I restart HASS).

While the issue is occurring, I tried removing hue from google and re-adding it. Google home was unable to pair until after I restarted HASS. This makes me suspect that the issue relates to the uPNP server on HASS but I don’t know how it works and I can’t find a link to the new hue_emulation source (only the legacy source is linked from the overview page - https://home-assistant.io/components/emulated_hue/).

I have confirmed that the problem occurs after the server is no longer listening on udp port 1900. Rebooting the server, restores listening on udp port 1900.

pi@raspberrypi:~ $ sudo netstat -tulpn  | grep 1900
pi@raspberrypi:~ $ sudo systemctl restart home-assistant.service
pi@raspberrypi:~ $ sudo netstat -tulpn  | grep 1900
udp        0      0 239.255.255.250:1900    0.0.0.0:*                           3519/python3

btw. I found the default udp port in the hue component source here.

To work around the problem, I made a script that will restart HASS when it stops listening to udp requests

  1. Save the following at /home/pi/check_upnp.bash
while :
do
    words=`netstat -tulpn  | grep 1900 | wc -l`;
    if [ $words -eq 1 ]
    then
        true
    else
        echo `date` HASS upnp service not running restarting
        systemctl restart home-assistant.service
    fi
    sleep 20
done

  1. add the following to root’s crontab
* * * * * run-one bash /home/pi/check_upnp.bash >> /home/pi/check_upnp.log 2>>/home/pi/check_upnp.log &
``




You will need [run-one](https://raw.githubusercontent.com/dustinkirkland/run-one/master/run-one) in your /usr/bin/ directory and made executable

Nice work around. But why are you on version 46? I haven’t had this issue myself.

I am on that version because its the version that was available when I wrote this post.

I don’t see any changes to the emulated hue source that relate to this issue in newer versions.