Hue motion sensors + remotes: custom component

Thanks for posting, glad this works. Probably I will need to rewrite the component as an actual remote, so that an event is fired on each press.
Cheers

1 Like

I created a template sensor for the last updated time…

@marthocoo Could you share the code for the template sensor? I’m not familiar with those and could use the code example. (Trying to get my Hue setup working the way you’ve described.)

@r.fletcher No problem! Add this to configuration.yaml:

sensor:
  - platform: template
    sensors:
      master_bedroom_dimmer_last_updated:
        friendly_name: Master Bedroom Dimmer Last Updated
        value_template: '{{ states.sensor.master_bedroom_dimmer.attributes.last_updated }}'

I just realized, however, that I also needed to edit sensor/hue.py under the def update(self): method to add an underscore between last and updated in the attribute name or else I couldn’t get it to work properly. Sorry @robmarkcole I should have created a PR for that - the other attribute names have underscores instead of spaces so I just added underscores for last updated as well.

Edit: created the PR, if only to draw your attention to what I’m talking about.

1 Like

@robmarkcole I’ve been doing some poking around some other platforms that support multi button remotes while doing some work on the zha platform (which ultimately will also support the Hue remotes directly over zigbee) and e.g. the Wink repo sets up remotes like this as binary sensors that trigger when any button is pressed and have an attribute that stores the specific button that was pressed. I assume without looking closely that the binary sensor resets after a short time. This way, an automation can be triggered by the binary sensor state going on and can be filtered by the button attribute. Just food for thought as you move forward on this platform! Thanks for the great work so far!

1 Like

Thanks for the advice, I will look into the options. However since the current implementation works ok rewriting is a low priority, but definitely I want to see these remotes added to HA officially :smiley:

You could also add:
Trigger:
Platform: state
Entity_id: sensor.dimmer

and add the required button in condition without the need of setting up another sensor.

@Caladera That doesn’t solve the “double-press” problem though, since if you have pressed 1_click, then press 1_click again, the state hasn’t changed, so the automation wouldn’t trigger. The last updated template sensor was necessary to trigger the automation since it changes with each key press.

1 Like

Just saying that this component is awesome! Finally found affordable(less than 20€) and reliable switch with 4 buttons to do whatever I want. Good job @robmarkcole

1 Like

Managed to get the motion sensor and remotes visible in HA. But how do you get it to show the temperature as a sensor?

Temperature is an attribute, so use a Template sensor. Cheers

Thanks @robmarkcole :slight_smile:

Think I need a little more help with that feature of using templates and their advantages though. Do you have a guide for that also?

This is a great component, utilizing the extra options that one already have.

1 Like

I’m on holiday without access to my config but recommend modifying the example in the docs

I can’t figure this out. Added your example into my sensors.yaml file like this:

# Hue sensors
  - platform: template
      bryggers_temperature:
        friendly_name: Bryggers Temperatur
        value_template:  '{{states.sensor.bryggers_motion_sensor.attributes.temperature}}'
        unit_of_measurement: "°C"

Get error like this:

2017-11-19 10:38:59 ERROR (SyncWorker_0) [homeassistant.util.yaml] mapping values are not allowed here
  in "/config/sensor.yaml", line 68, column 27
2017-11-19 10:38:59 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: mapping values are not allowed here
  in "/config/sensor.yaml", line 68, column 27

Yes I have created a sensor.yaml file and included in my configuration.yaml. Everything else works.

It does try it out. If you do not define a “to:” in the trigger and instead put the button press in the condition it fires on each press.

@snjoetw In reply to your earlier question “now that hue sensors show up in HomeKit, is there new API to do push instead of poll?”, I found a solution that will indeed detect Hue switch push notifications:

I think this problem is more general. As far as I know it is not possible to fire the same state twice.

I made a template sensor from the last_updated attribute of the zithoek_dimmer. In automation the trigger is fired by a change in the last_updated state and is conditioned on the state itself to toggle my light.

  trigger:
    - platform: state
      entity_id: sensor.zithoek_last_updated, sensor.zithoek_dimmer
  condition:
    condition: state
    entity_id: sensor.zithoek_dimmer
    state: '1_click'
  action:
    - service: light.toggle
      entity_id: light.sta_lamp

Great, I ended up going with exactly the same approach, should have read your post before.
Thanks

think it should be…

# Hue sensors
  - platform: template
    sensors:
      bryggers_temperature:
        friendly_name: Bryggers Temperatur
        value_template:  '{{states.sensor.bryggers_motion_sensor.attributes.temperature}}'
        unit_of_measurement: "°C"

Hiya,

I keep getting an error when setting up the Hue platform. I have copied (samba) the contents of custom_components into the config folder of hassio. Also I have added the sensor like described in the Readme. Last but not least I have the phue.conf in the config folder.

2017-11-20 20:54:28 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform hue
Traceback (most recent call last):
File “/usr/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 352, in wait_for
return fut.result()
File “/usr/lib/python3.6/asyncio/futures.py”, line 244, in result
raise self._exception
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/sensor/hue.py”, line 27, in setup_platform
data.update()
File “/usr/lib/python3.6/site-packages/homeassistant/util/init.py”, line 306, in wrapper
result = method(*args, **kwargs)
File “/config/custom_components/sensor/hue.py”, line 51, in update
self.data = self.parse_hue_api_response(response.json())
File “/config/deps/lib/python3.6/site-packages/hue_sensors.py”, line 52, in parse_hue_api_response
data_dict[_key] = parse_sml(sensor)
File “/config/deps/lib/python3.6/site-packages/hue_sensors.py”, line 81, in parse_sml
hue_state = response[‘state’][‘presence’]
KeyError: ‘presence’

What to do?

\kcdc80

Interesting error, the api must be returning data in a format I’ve not accounted for. Can you create an issue on github and post your anonymised data returned by the api?