Hue motion sensors + remotes: custom component

guess you could customize like this:

 templates:
    rgb_color: "if (state === 'on') return [251, 210, 41]; else return [54, 95, 140];"

ive asked the people at MDI for a motion-sensor-off icon, which is now in the making.
If and when, you could probably also change the icon:

icon: "if (state === 'on') return 'mdi:motion-on';
                            else return 'mdi:motion-off';"

for now use mdi: run-fast and mdi:human-male/female … :wink: (might have to take out the line in the CC for the icon) is this possible @robmarkcole ? or maybe add the possibility for the on/off in the CC itself?

0435

cheers,
Marius

I believe you can use the customise tool to achieve whatever look and feel you like :+1:

sure! so cool.
thought the Red alert color was more suitable…

  templates:
    rgb_color: "if (state === 'on') return [192, 39, 30]; else return [54, 95, 140];"

03

This is a great suggestion thanks, I’ve tried it in my customize.yaml but it doesn’t seem to work. Have I the formatting wrong? Any ideas?
sensor

whats your code? if you post the code, we can help.

This is what I added to my customize.yaml - I borrowed another line for stateDisplay from the discussion here but it doesn’t appear to matter if I exclude that line or not

sensor.sitting_room_motion_sensor:
  templates:
    rgb_color: "if (state === 'on') return [251, 210, 41]; else return [54, 95, 140];"
    _stateDisplay: "if (state === 'on') return 'Detected'; else return 'Clear';"

this is my full customization for the hue motion sensors

sensor.corridor_motion_sensor:
  show_last_changed: true
  templates:
    rgb_color: "if (state === 'on') return [192, 39, 30]; else return [54, 95, 140];"
    icon: "if (state === 'on') return 'mdi:run-fast';
                            else return 'mdi:exit-to-app';"
    _stateDisplay: if (state === 'on') return 'Alert'; else return 'Clear';

should do the trick…but check the difference in the more-info below. Other customizations do work as expected?

04

1 Like

That’s very odd but anything i try here doesn’t work, it appears as per my screenshot above. Templates don’t work in my customize.yaml even though other customizations do.

Is there possibly an error somewhere else in customize.yaml that could be causing this? An errant parentheses or something? I’m using hassio latest public release. Any custom components or anything that I need to install?

just to be sure: you do have customize setup in your configuration.yaml?

homeassistant:
  name: HeadQuarters
  latitude: !secret latitude
  longitude: !secret longitude
  elevation: !secret elevation
  unit_system: metric
  time_zone: !secret time_zone
  customize: !include_dir_merge_named customize # customize.yaml
  customize_glob: !include customize_glob.yaml

@robmarkcole

HI Robin,

Does this:

8-04-11 13:01:22 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: <html>
<head><title>500 Internal Server Error</title></head>
<body bgcolor="white">
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx</center>
</body>
</html>
, template: {{ value_json.state.presence }}) 

8-04-11 13:06:11 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: <html>
<head><title>500 Internal Server Error</title></head>
<body bgcolor="white">
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx</center>
</body>
</html>
, template: {{ value_json.config.on }})

in any way seem possibly related to the hue.py CC? Ie checked in my config files for the value_json.state.presence and on, and the only place it seems related to is your CC…

Please have a look?

Cheers,
Marius

Appears to be related to config. No ideas beyond that I’m afraid

HI @john1

do you recognize these errors in the log. Ive looked everywhere in my config, but can only imagine them to come from the rest switches…

File "/usr/lib/python3.6/site-packages/homeassistant/components/switch/rest.py", line 167, in async_update
    yield from self.get_device_state(self.hass)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/switch/rest.py", line 178, in get_device_state
    text = yield from req.text()
  File "/usr/lib/python3.6/site-packages/async_timeout/__init__.py", line 35, in __exit__
    self._do_exit(exc_type)
  File "/usr/lib/python3.6/site-packages/async_timeout/__init__.py", line 80, in _do_exit
    raise asyncio.TimeoutError
concurrent.futures._base.TimeoutError
2018-04-11 23:57:18 ERROR (MainThread) [homeassistant.components.switch.rest] Error while fetch data.
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/switch/rest.py", line 178, in get_device_state
    text = yield from req.text()
  File "/usr/lib/python3.6/site-packages/aiohttp/client_reqrep.py", line 829, in text
    await self.read()
  File "/usr/lib/python3.6/site-packages/aiohttp/client_reqrep.py", line 798, in read
    self._content = await self.content.read()
  File "/usr/lib/python3.6/site-packages/aiohttp/streams.py", line 312, in read
    block = await self.readany()
  File "/usr/lib/python3.6/site-packages/aiohttp/streams.py", line 328, in readany
    await self._wait('readany')
  File "/usr/lib/python3.6/site-packages/aiohttp/streams.py", line 250, in _wait
    await waiter
  File "/usr/lib/python3.6/asyncio/futures.py", line 332, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 237, in result
    raise CancelledError
concurrent.futures._base.CancelledError

might be related to the rest switches, see @john1’s post. They work fine, but seem to cause log-stress…:wink:

1 Like

Here’s how I’ve customised mine to show the ‘movement’ and ‘no movement’ states, in case anyone wants to try it. Looks pretty cute when it switches between states :slightly_smiling_face:




And the code:

office_motion:
  friendly_name: "Movement"
  value_template: "{% if is_state('sensor.office_motion_sensor', 'on') %}Detected{% else %}None Detected{% endif %}"
  icon_template: "{% if is_state('sensor.office_motion_sensor', 'on') %}mdi:human-handsup{% else %}mdi:human-male{% endif %}"

BTW, what's the status of the motion sensors in Home Assistant at the moment? I've been holding off updating HA, as didn't they remove support for Hue sensors?
3 Likes

Finally figured this out, turns out you need the Custom UI elements addition for your Home Assistant setup: https://github.com/andrey-git/home-assistant-custom-ui

Once I configured this correctly (by adding a customize_glob entry to my configuration.yaml) the templates started working.

This is off the topic of the thread but this seems like something that should be added already to hassio at least if it seems to be so commonly used?

Anyway I’m happy campers now with my consistent motion sensors

OK I’ve tested the CC on HA 0.68.0.dev0 and works fine. If the Hue hub component is stable over the next release I will look at turning the sensors into an official component.
Cheers

4 Likes

Went through the whole thread and didn’t see this, soooo how can I show temp in Fahrenheit?

Use a template sensor to break out the temperature attribute and convert to Farenheit

1 Like

@robmarkcole
I was testing and comparing automation using the hue motion sensor (open light when motion) with HomeKit and HA (your component).
Is it normal that Home kit automation is WAY FASTER to open the light on motion than doing it from HA? (maybe because the way it communicate with the sensor or something)
HK is less than a second and with HA, it can be 2 seconds…
Just wondering is this is something to live with or something I can optimize…

thanks

For F. sake please! that would be so awesome - Especialy the motion sensors for triggering automations and the remotes.
I’m to worried to change the working setup, its not broke, jet…