Hue motion sensors + remotes: custom component

It’s because I’m now using PlatformNotFound, which is adding exponential backoff there.

Please try both variants (with and w/o IP address). Logs would be highly appreciated.

You don’t need this in the configuration.yaml. It should work fine in most cases with only:

device_tracker:
  - platform: hue
sensor:
  - platform: hue

thanks, i will try that

After a restart i got these messages in the log:

2019-01-03 21:02:08 ERROR (MainThread) [homeassistant.components.hue] Error connecting to the Hue bridge at xxx.xxx.xxx.xxx
2019-01-03 21:02:08 ERROR (MainThread) [homeassistant.components.hue] Error connecting to the Hue bridge at xxx.xxx.xxx.xxx. Retrying in 2 seconds
2019-01-03 21:02:09 WARNING (MainThread) [homeassistant.components.sensor] Platform hue not ready yet. Retrying in 30 seconds.
2019-01-03 21:02:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Gang Wohnzimmer temperature, the state is unknown.
2019-01-03 21:02:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Gang Wohnzimmer light level, the state is unknown.
2019-01-03 21:02:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Kinderzimmer temperature, the state is unknown.
2019-01-03 21:02:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Kinderzimmer light level, the state is unknown.
2019-01-03 21:02:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Gang Klo temperature, the state is unknown.
2019-01-03 21:02:31 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Gang Klo light level, the state is unknown.

But the sensors (e. g. temperature) seems fine!

Edit:
After a second restart all my lights were gone! Only the sensors remained.
After a third restart no errors were displayed in the log and the lights were back. Also the sensors have no issues anymore. So it seems to work now!

1 Like

First 3 lines indicates that the Hass Hue component has failed to connect to the bridge, so the sensors component has backed off for 30 seconds. This is expected behaviour. I’ll might add the retry tho.

Looks like you have the same network issue @Mariusthvdb has. Do you use Hassio, RPi, and Wi-FI?

I can say Im rather happy here. the errors:

2019-01-03 21:35:53 ERROR (MainThread) [homeassistant.components.hue] Error connecting to the Hue bridge at 192.168.1.212
2019-01-03 21:35:54 ERROR (MainThread) [homeassistant.components.hue] Error connecting to the Hue bridge at 192.168.1.212. Retrying in 2 seconds

which have been perstering my HA setup ever since Hue went asyncio in april/may 2018 , and been the cause for the Hue lights going Unavailable all the time (see: Philips Hue changed to unavailable - #30 by Mariusthvdb, All my hue lights randomly becoming unavailable - #6 by Mariusthvdb, Philips Hue changed to unavailable · Issue #16689 · home-assistant/core · GitHub to name a few)

have disappeared completely following suggestions by @yottatsa testing his new async version of @robmarkcole 's CC for the Hue sensors!

Added to that, there’s no more lag after startup in initializing the sensors, And Lights, and they don’t randomly and frequently show unavailable any more. I have been testing and resetting HA for almost 9 months now, and this must be the biggest leap forward.

I know the HA founder doesn’t want an upped timeout in the Hue components, stating if that’s needed, something else is going on in the setup that needs fixing, not the Hue component. I respect that, but no other solution has been suggested…

this is what I did:

by dl ing the files from the Ha repository, adjusting these timeouts, and loading the files in the custom component folder.

The new component also took care of these messages:

19

all gone.

Summarizing:

no more hue sensor took longer errors
no more error connecting to the Hue bridge error
no more flapping hue lights
immediate initialization of the lights and sensors
big speedup in startup HA.

not sure yet, but my processor use has gone down significantly also

Couldn’t be happier for the moment…

4 Likes

Just a quick question about breaking this CC to separate sensors for motion, lux and temperature.

I used to have manually configured REST sensors for motion, temperature and lux, but found like others that the motion was unreliable and also sometimes took 3 or 4 seconds to detect motion, by which time i was in the room and sitting down :frowning:

Since using this CC, response has been excellent, more or less instant. I put this down to the one connection to the bridge as I just template the main component for the other sensors. Would making them separate sensors bring back the issue again?

I’m not a programmer, so I may have got the wrong end of the stick :slight_smile:

Whether there are one or many sensors is just the way we present the data to home assistant, it makes no difference to performance

1 Like

Ah I get it. Basically the CC will do the templating for us.

Thanks for the component - it has transformed the response of my 4 motion sensors and keeps the wife happy as she doesn’t wave her arms around like an idiot when she walks into the room now :slight_smile:

Happy wife, happy life…!

2 Likes

I have a RPi 2, Hass.io and LAN Connection.
The RPi is connected to a Switch in the basment and my hue hub (Second Generation) is connected to a Router in the first floor.
I have the same issues, as some described, that some lights went unavailable for some Time in Home Assistant, and came back later, but they were available in the Hue App all the Time!

I tried this today and I got more errors than ever. For example, I did not have the specific error saying “…took longer than the scheduled update interval 0:00:05…” before adding the custom components, but now the log is full of them.

Weird!

just to be sure:
I use the CC by @yottatsa , not sure if that’s the same this moment as @robmarkcole 's GitHub version.

added to that, I do set the Brigde Ip address manually as suggested by @yottatsa, which makes my setup for this component as follows:

device_tracker:
  - platform: hue
sensor:
  - platform: hue
hue:
  bridges:
    - host: !secret hue_ip

not quite like that I am afraid, at least not quite yet.
The CC will automatically create the sensors for your sensors, with all the available attributes. But if you want these attributes as separate sensors, and for at least some attributes that is rather likely, you need to template them out .

I hope that we soon will have an option to set a configuration flag to have the CC do that for us, (hope @robmarkcole and @yottatsa read along :wink: ) and would like to suggest to be able to set a flag for all the attributes individually.

something like:

sensor:
  - platform: hue
    create_template:
      temperature: true
      lx: true
      light_level: true
      on: true
      dark: false
      daylight: false
      on: true

and then have the component make sensors for these templates out of the main sensor:

sensor.main_motion_sensor should become a binary_sensor.main_motion_sensor

with template sensors:

sensor.main_motion_sensor  #(is on or off, which is not the motion sensor sensing motion/clear, but the setting of it being switched on)
sensor.main_motion_sensor_temperature
sensor.main_motion_sensor_lx
sensor.main_motion_sensor_lightlevel

etc
etc

1 step further would be to have an automatic creation for a switch to switch these sensors on/off.

I have these for all my motion sensors and they work perfectly, and use them all the time in my scenes and automations.

  control_room_motion_sensor_switch:
    friendly_name: 'Control room motion sensor switch'
    command_on: >
      curl -X PUT -d '{"on":true}' "http://bridge_ip/api/key/sensors/7/config/"
    command_off: >
      curl -X PUT -d '{"on":false}' "http://bridge_ip/api/key/sensors/7/config/"
    command_state: curl http://bridge_ip/api/key/sensors/7/
    value_template: >
      {{value_json.config.on}}

somehow I think that must be doable in the CC … #fingers crossed

3 Likes

Hey. What is the lux value refresh time set to? Mine just stays at 1.0 even with the light on.

My version of the CC is ahead of @robmarkcole’s by 1-2 days. Right now @robmarkcole’s latest is safe enough.

Basically I’m choosing between this and having the same names it has for the HomeKit. See #48 as well.

Bridges are polled every 1 second or so. However, the Motion sensor itself only updates the light level to the Bridge only either once in a 5 minutes, or when the motion is detected https://youtu.be/i_GywKcwmKQ

1 Like

Thanks - i have monitored things today. The lux value from the rest sensor used to shoot up to 10000+ but this one is lower so i needed to just adjust my automations but all is working well. Absolutely love having the hue dimmers in there, basically wireless buttons for different rooms. Need to put some sticks on them to make the physical switches more obvious.

Please note that the Bridge is using lightlevel, which is not lux. If it’s over 10000, it’s should be converted, as the CC does.

lightlevel = 10000 * log10(lux) + 1
lux = round(float(10 ** ((lightlevel - 1) / 10000)), 2)