Hue motion sensors + remotes: custom component

If anyone is feeling particularly enterprising and would like to help me out with some experimenting and testing, the hue-sensors branch of my home-assistant fork on GitHub now contains an async implementation of Hue sensors and binary sensors in Home Assistant based on my work on aiohue.

The implementation currently supports all Hue sensors and binary sensors (including CLIP sensors/binary sensors and the Daylight binary sensor) and implements remotes (the Hue Tap and Hue Dimmer) as sensors that reset their state. I suspect when I raise this as a PR the feedback will be to implement the remotes as events, but I’ve seen components do it both ways and I kind of like the visibility and ease of use that a sensor provides to the user after playing around with it while coding this.

Here’s some steps to try it out, though unless you’re comfortable with and understand what’s going on in the following commands, I wouldn’t really suggest trying it. You’ll need to stop your existing running HASS instance if one is running.

cd /into/empty/directory
git clone https://github.com/marthoc/home-assistant
python3 -m venv home-assistant
cd home-assistant
git checkout hue-sensors
source bin/activate
script/setup.py
hass -c /empty/directory/so/as/not/to/muck/up/your/existing/config

Then, you’ll need to navigate to the HASS GUI and configure your Hue bridge under Configuration - Integrations. All lights, sensors, binary sensors, and remotes should get automatically pulled in to HASS.

@robmarkcole Sorry for leapfrogging you on this but it looks like you’ve got other projects on the go and I had the aiohue library in my head already from working on it. Happy for you to try it out and provide feedback/suggestions for improvement before I raise this as a PR!

2 Likes

Thanks for taking this one forward, my plate is very full! Btw what are the CLIP sensors?

CLIP sensors are virtual devices that you can create and update using Hue API calls (CLIP = connected light internet protocol). They can be used in rules on the Hue bridge (created via the API) and maybe for other purposes too?

To be honest, I’m not sure what you’d use them extensively for, but they have at least been helpful in coding the sensor and binary sensor platforms as they allowed me to populate my bridge with various different kinds of sensors to use as examples.

I suppose they could be used to expose other brand sensors to the Hue app?

or for changing the response of the motion sensors, by creating a virtual one:

https://nickyb2.tweakblogs.net/blog/14037/home-assistant-philips-hue-motion-sensor

I’ve used a template sensor to create a virtual sensor in the past, don’t see the benefit of using the Hue virtual sensor…?

no, you’re right. my thoughts too.
i’ve deleted those, and simply created a template or binary sensor with delay, or wait template…no digging in the hue api necessary
my post was only to demonstrate the clip sensor…

I’ve used a virtual sensor so I can set a timer of 15 minutes on them.

If all of the virtual sensors go off that means it’s been at least 15 minutes since anybody triggered any motion sensor and that typically means (during the day) that the house is empty and I can trigger empty house automation.

I think they’re probably only useful in a few circumstances and not really that useful if you’re doing your automation in HA anyway, but at least there’s the option.

I’ll may create a config parameter allow_clip_sensors that is by default set False so users will have to make the intentional choice to expose them to HA, though if you are using them then you probably have a good reason for doing it.

1 Like

Hi Guys,
I am pulling my hair out with this, can someone give some advice to a newbie?

I have managed to get my motion sensors to show, but i cannot seem to create a template correctly to show the other values, such as temperature or lux.
I have followed the guide, but I must be missing something vital. Do I need to create a template.yaml?

All i want to do currently is view temps from my various sensors and record that data. I would then like to work on some automation’s to turn on fans etc if too hot.

I currently see all my motion sensors but no temp or lux values (Config is Valid).
I would have added more pictures but newbies can only add one :frowning:

This is my Groups.yaml:

default_view:
view: no
entities:
- group.Hue

Hue:
entities:
- sensor.kitchen_motion_sensor
- sensor.kitchen_temperature
- sensor.kitchen_light_level
- sensor.hallway_motion_sensor
- sensor.landing_motion_sensor
- sensor.office_motion_sensor
- sensor.garage_motion_sensor

Here is my Configuration.yaml:

Any help would be greatly appreciated.

Thanks,

Scup

maybe your sensor.sensor isnt correct?

depending on the name you gave the ‘mother’ sensor of course, but this should do it:

control_room_motion_sensor_battery:
  friendly_name: 'Control room battery'
  unit_of_measurement: '%'
  value_template: >
    {{ states.sensor.control_room_motion_sensor.attributes.battery }}
  device_class: battery

or

control_room_motion_sensor_temperature:
  friendly_name: 'Control room temperature'
  value_template: >
    {{states.sensor.control_room_motion_sensor.attributes.temperature}}
  unit_of_measurement: °C
  device_class: temperature

where the ‘mother’ sensors have a name as follows:

sensor.[name]_motion_sensor

Where do I place this code?
Within the confirugation.yaml or a seperate .yaml file?
I can get the code to display in the template tester, but it will not show in my groups page.

up to you really. where you define your sensors.

sensor:
- platform: template
  sensors:
    corridor_motion_sensor_battery:
      friendly_name: 'Corridor battery'
      unit_of_measurement: '%'
      value_template: >
        {{ states.sensor.corridor_motion_sensor.attributes.battery }}
      device_class: battery

i have all sensors in a dedicated sensor folder, and have this in configuration.yaml:

sensor: !include_dir_merge_list sensors

as we speak i am rebuilding the sensors to not use the CC any longer (dev-s pointed out to me today they really dont support this, and use at own risk…) but that is besides the point here… :wink:

Thanks,
I think I am slowly getting there now. Still cant get the sensors to show, but i have direction.

Thank you :slight_smile:

HI @robmarkcole,

because one of my automations based on the state of a motion sensor was behaving unexpectedly I just discovered that while having the attribute on: true, the state of the sensor is Off…

If I look in the Hue app, the sensor is indeed on, and the switches I have made work as they should. In fact this goes for all motion sensors I have, they have the correct attributes, but the state doesnt comply. All other aspects work just fine. Its just that the logic based on the state seen by Hassio makes it impossible to act upon now.

What could be off here:

this only happend after I dl the latest version of your CC, I was 2 iterations behind, so thought it wise to update…Did anything change in the CC to explain for this misbehavior somehow?

Hi, a couple of PR were submitted by other users, you can see the changes in the commit history.
I recommend sticking with the version that worked for you. I’m no longer updating the CC as an official component will be coming soon.
Cheers

1 Like

ok thanks, will check my backup…

as it happens, the Hue app and Hub software were updated too… maybe related? will see what the official component brings, hope it will soon cause Hue integration seems to have some loose ends lately.
thx!

wait…
my bad, what was I thinking. The sensor is state: off, when no motion is detected, not when it is switched Off…
sorry for the post and bother

1 Like

I’ve extracted the custom_components under my ~/.homeassistant/ directory, and updated the configuration.yaml as indicated in the README.md.

When HomeAssistant starts up, the following error is logged:

2018-07-05 14:52:46 ERROR (MainThread) [homeassistant.setup] Error during setup of component sensor
Traceback (most recent call last):
  File "/Users/dustin/anaconda3/envs/hass/lib/python3.7/site-packages/homeassistant/setup.py", line 146, in _async_setup_component
    component.setup, hass, processed_config)  # type: ignore
AttributeError: module 'custom_components.sensor' has no attribute 'setup'

This prevents the entire sensor component class from loading, deactivating my other sensors. I had to remove the directory to get HA to start up and show my other sensors again.

My Hue hub is autodiscovered, and HA shows all my Hue lights just fine.

I tried both the most recent tagged release (v0.6) and the current (as of this date) master branch.

Any advice?

Have you got any other custom components running successfully? Which HA version number?

I don’t have any other custom components installed.

HA version: 0.72.1

In the meantime, I’m using the earlier method of creating rest platform sensors for presence, lux and temp.