Hue motion sensors + remotes: custom component

according to the author, it should still be usable.

several have reported successful migration.

If not, you can use (json)rest sensors. and template the desired values out.

  - platform: jsonrest
    resource: !secret hue_sensors_resource
    method: GET
    name: Philips Hue Sensors
    scan_interval: 1

  - platform: rest
    resource: http://ip/api/key/sensors/2
    value_template: '{{ value_json.config.battery}}'
    name: 'Battery Dimmer switch'
    unit_of_measurement: '%'
    scan_interval: 30

Hey,
I fixed the state command issue which you were having. Instead of using the command_line platform, I used the rest platform.
Here is my configuration if you are interested in this:

  - platform: rest
    resource: http://ip/api/key/sensors/sensor_name
    method: put
    name: "Hallway Sensor Switch"
    body_on: '{"config": {"on": true}}'
    body_off: '{"config": {"on": false}}'
    is_on_template: '{{ value_json.config.on }}'
    scan_interval: 1
1 Like

nice, will try that.
No such thing as coincidence, ive just changed my cl switches like this, and they work like a charm:

corridor_motion_sensor_switch:
  friendly_name: "Corridor motion sensor switch"
  command_on: >-
    curl -X PUT -d '{"on":true}' "http://ip/api/key/sensors/5/config"
  command_off: >-
    curl -X PUT -d '{"on":false}' "http://ip/api/key/sensors/5/config"
#     command_state: curl http://ip/api/key/sensors/5/
#     value_template: '{{value_json.config.on}}'
  value_template: >-
     "{{ is_state_attr('sensor.corridor_motion_sensor', 'on', true) }}"

main difference the value_template, which now is reading the on/off state of the with correctly (before it read on/off of the trigger…)

have several in a group which makes it super easy to switch the house in motion sensor mode (when away) or not (when dancing in the auditorium…:wink: )

would be really interested to hear which of the two would be preferable and why (resources , reliability, etc)
Cheers,
Marius

---- edit-----
@john1: yours are better… :wink:

its not that mine don’t switch, they do perfectly. Its the state picking up that yours do more reliably. If the sensors are switched elsewhere mine dont show the correct state, the template must be off somehow. Yours follow the correct state, also when switched off/on by other controls, like the Hue App.
So, changed setup, with a little customization:

switch.corridor_motion_sensor_switch:
  templates:
    icon: "if (state === 'on') return 'mdi:toggle-switch';
                            else return 'mdi:toggle-switch-off';"
  assumed_state: false
  group:
    group.philips_motion_sensor_switches:
      friendly_name: Corridor motion

09
Cheers,
Marius

1 Like

Great project! Finally some nice, responsive remotes!
I’m getting alot of updating errors in the log. Right now I’m just testing with one and tried http://IP/api/KEY/sensors/26, but no success.
Could it help if I only poll the remotes I want? If so, is it possible?

All of the sensors/remotes are polled in a single request. No more targeted polling would be more efficient

1 Like

Thanks. I modified my config, now it works like it should to, no problems with double button press and no false triggers.
Here is a code:

Template sensors for each Hue dimmer (maybe it’s possible to combine them into one, but I decided that 3 is acceptable).

platform: template
sensors:
  switch_room:
    value_template: >
      {% if states.sensor.roomswitch %}                   #sensor.roomswitch is entity_id of Hue dimmer from custom component
        {{ states.sensor.roomswitch.last_updated }}
      {% else %}
        n/a
      {% endif %}

  switch_kitchen:
    * * *            #same as roomswitch
  switch_hall:
    * * *

Automation for dimmer buttons (one for all three Dimmers).

alias: Hue dimmers
  trigger:
    platform: state
    entity_id:
      - sensor.switch_room            #
      - sensor.switch_kitchen         # template sensors, created above
      - sensor.switch_hall            #
  condition:
    - condition: state
      entity_id: input_boolean.children_lock     # a little hack against children's love to switch light :)
      state: 'off'
  action:
    - service: scene.turn_on
      data_template:
        entity_id: >
          {% set theRoom = trigger.entity_id.split("_")[1] %}   # get room name from template sensor (i.e room, or kitchen, or hall)
          {% set theSwitch = "sensor." + theRoom + "switch" %}  # forming name of corresponding Dimmer (i.e 'sensor.roomswitch' or 'sensor.hallswitch', etc)
          {% if is_state(theSwitch, "1_click") %}
            scene.{{ theRoom }}_bright
          {% elif is_state(theSwitch, "2_click") %}
            scene.{{ theRoom }}_dimmed
          {% elif is_state(theSwitch, "3_click") %}
            scene.{{ theRoom }}_night
          {% elif is_state(theSwitch, "4_click") %}
            scene.{{ theRoom }}_no_light
          {% endif %}

Hope my implementation will be useful for someone)

2 Likes

This might not be the appropriate place to ask, but how do I customise the state of various motion sensors?

The hue custom component motion sensors display as On or Off in the UI, but the Xiaomi motion sensors I have display as Clear or Detected. See below, the Downstairs and Sitting Room sensors are Hue.

Ideally I would like these to be consistent. ie Clear or Detected for all, or One or Off for all.

Additionally, the hue component sensors don’t highlight in yellow when motion is detected, do we have any control over that, is there a setting I can change somewhere? Thanks in advance

motionsensors

The issue here is that the motion sensors are implemented as vanilla sensors rather than binary_sensors. I actually use a template_binary to detect motion at home (in binary_sensors.yaml):

- platform: template
  sensors:
    motion_at_home:
      value_template: >-
        {%- if is_state("sensor.hall_motion_sensor", "on")
        or is_state("sensor.living_room_motion_sensor", "on")
        or is_state("sensor.bedroom_motion_sensor", "on")
            -%}
        True
        {%- else -%}
        False
        {%- endif %}

I hadn’t given this much thought, but IMO motion sensors should be implemented as binary sensors. Added to to-do list.

Hi, any progress since 0.66? The HUE refactor at 0.66 caused me to loose connection to a couple of Tasmota Sonoffs that were pretending to be HUE bridges. I changed them to pretend to be Wemo, but they are now limited to one output. I also lost effects from the faceplates of any bulbs that have effects but can still call the service with other methods. I ask as I saw in another thread, that you were thinking of helping with the platform and then the thread went private by the author of the platform.

Ah ok, I can see that the Xiaomi sensors are indeed listed as binary sensors, didn’t realise that was the difference.

It’s not a big deal but I appreciate you putting it on the todo list.

1 Like

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