Hue motion sensors + remotes: custom component

How’s Yes python script, see hackster article, cheers

Good idea, @marthocoo and one that I have been thinking of as well. However, think I have to start understanding the exact interplay between the actual Dimmer, The Hue Hub, HA and it’s state machine - and then finally to see how to best use or manipulate that sytsem. I’m concerned that pushing pseudo state changes from the automations into the HA state machine will be overwritten anyways at the next poll. But, as I said, I’ll have to understand the exact interaction between the layers to really see what a good solution would be.
Morten

Now I think about it you are right, the state would be overwritten at the next poll.
I think a solution would be to create a dummy remote that’s only updated by automations linked to the real remotes.

Maybe one clarifying question:
If we imagine a situation in which the physical remote button 1 is pressed twice - say two seconds apart.
What do the different layers then see when the second press - press 2 - happens?

  1. Does the remote transmit press 2 at all?
  2. Does the Hue hub change anything at all?
  3. Is there then any way for the the polling mechanism in the Hue Component in HA to see at all that there was a second press?

If the answer to 3. is No then it seems to me that anything done in HA will never be able to react to “press number 2” on the same button (with no other buttons pressed in between).

Last_updated will change as per earlier comment.
Cheers

@robmarkcole this is AWESOME! Thanks for making this happen

1 Like

Hey this is great! thank you for the hard work!!

I see geo mentioned a few times, is it possible to use the hue geofencing for a device tracker? Been struggling no device trackers i have tried are reliable at all…

Completly forgot to include the main reason i was writing lol.

I have had hue for awhile and the current platform works perfect, I had some bootleg script to include the sensors that worked pretty well most the time. Ive copied the files hue.py into custom_components/ and custom_components/ sensor. The lights are still working great but I am getting this in the logs and I am not getting the hue motion sensors. If you could take a look and maybe point me in the right direction I would greatly appreciate it!!

2017-10-26 21:17:24 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform hue
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 170, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/sensor/hue.py", line 24, in setup_platform
    url = hass.data[DOMAIN] + '/sensors'
KeyError: 'hue'

my configuration.yaml

light:
  platform: hue
  host: 192.168.xx.xx

sensors:

- platform: hue

You also have to add:
hue:
to configuration.yaml (in addition to the hue platform under lights and sensors).

Thank you!!! Good to go now!

Hi Darbos, thanks for the support!
I’ve been using the geofence for device tracking and it works great for my iPhone. However since only 1 phone can be registered with the Hue app (I believe) it is only limited to tracking 1 device.

Btw I updated the Github repo to clarify the usage as a custom_component comprising of hub and sensors.
Cheers

1 Like

I am trying to set the temperature up but I am getting errors.
I do have the motion sensor setup and working

Any ideas about the error?

2017-10-27 08:50:23 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.template]: expected a dictionary for dictionary value @ data['sensors']['friendly_name']. Got 'Kitchen motion sensor'
expected a dictionary for dictionary value @ data['sensors']['kitchen_motion_sensor']. Got None
expected a dictionary for dictionary value @ data['sensors']['unit_of_measurement']. Got 'degrees'
expected a dictionary for dictionary value @ data['sensors']['value_template']. Got '{{ states.sensor.kitchen_motion_sensor.attributes.temperature }}'. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/ 

and this is my config

 - platform: template
    sensors:
      kitchen_motion_sensor:
      friendly_name: 'Kitchen motion sensor'
      unit_of_measurement: 'degrees'
      value_template: '{{ states.sensor.kitchen_motion_sensor.attributes.temperature }}'

Here’s what mine looks like, working well:

- platform: template
    sensors:
      living_room_temperature:
        friendly_name: Living Room Temperature
        value_template:  '{{states.sensor.hue_motion_sensor_motion_1.attributes.temperature}}'
        unit_of_measurement: "°C"

      living_room_light_level:
        friendly_name: Living Room Light Level
        value_template:  '{{states.sensor.hue_motion_sensor_motion_1.attributes.temperature}}'
        unit_of_measurement: "lux"

Where “sensor.hue_motion_sensor_motion_1” is the entity name of my motion sensor. I think you may be missing a level of indentation under each of your sensor names.

:man_facepalming: yaml requires correct spacing…

Thanks for the response.

You may want to change your light level to look at the attribute lux instead of temperature

Haha yeah thanks… fortunately for me it’s bad copying and pasting and my config is actually correct…

1 Like

Hi @robmarkcole, I followed your advice and created a new “synthetic” sensor type (called a multiway sensor) within your hue sensor framework. It looks at a number of real sensors and returns the state from the last updated physical sensor. And it works exactly as it is supposed to! So thanks.
You can see the first attempt here: https://github.com/mkelk/Hue-sensors-HASS/tree/multiway
I would be very interested in hearing whether you think that this could be included in your project - if so, I can create a pull request on it.
I’m new to Home Assistant and a lot of the ecosystem, so it might need some tightening up and polishing before it is ready - but take a look and let me know what you think of it.
Regards,
Morten

Hi Mort
Thanks for posting this, looking forward to trying it out! I’m about to head on holidays for a week so will be some time before I get back to you about it but by all means make a PR as this makes it easy to see your edits.
Btw the HA core team have said that in order for this to be included in HA it should use the phue library (to match the Hue lights component) so I may rewrite the whole component soon. If that’s a project of interest then let me know also :slight_smile:
Cheers!

Hi Robin,
I made the pull request so that you can look at it. There is no hurry, it’s running fine here at home, so I’m not in a rush :slight_smile: But I hope this could be useful.
I may be interested in the hue project. I’m not a Home Assistant or Python ninja, but it would be interesting to take part in it. Let me know when you embark on it.
Morten

1 Like

@Morten_Elk @robmarkcole I finally figured out a simple solution to the “double-press” problem, at least in my application. Basically, I created a template sensor for the last updated time, then triggered my automations off a state change of that sensor (ie any button press), with a condition to filter by state of the actual sensor. Perhaps an example will make it easier to illustrate what I’m talking about:

- id: nine
  alias: MB Dimmer - 2 click - lights on - full
  trigger:
    - platform: state
      entity_id: sensor.master_bedroom_dimmer_last_updated
  condition:
    - condition: state
      entity_id: sensor.master_bedroom_dimmer
      state: "2_click"
  action:
    - service: light.turn_on
      data:
        entity_id: light.master_bedroom_lights
        brightness_pct: 100

sensor.master_bedroom_dimmer_last_updated is my template sensor. sensor.master_bedroom_dimmer is the actual hue remote. The condition filters the automations by the button pressed on the remote so that it will only trigger the action if the button pressed is the one you want.

Maybe this will be useful to you!

1 Like