Tutorial adding HUE Motion sensor (Lux,Temp and Motion)

After many months of use, you recommend it?

HI all, got a method to add the Hue dimmer switch (http://www2.meethue.com/en-us/productdetail/philips-hue-dimmer-switch) to HASS, with the idea being to use it to trigger scripts. Identical method to the motion sensors:

## Hue remote
- platform: rest
  resource: http://192.168.0.0/api/Your_Key/sensors/sensor_number
  name: Hue-dimmer-switch-1
  value_template: '{{ value_json.state.buttonevent }}'
  scan_interval: 1

Automations:

#### Hue dimmer switch
- alias: Hue dimmer 1 automations
  trigger:
    platform: state
    entity_id: sensor.huedimmerswitch1
    to: '4002'
  action:
    service: notify.ios_robins_iphone
    data_template:
      title: "Hue notification"
      message: Button 4 pressed

The only prob with this approach is that if the button is pressed a second time, this will not be registered. Need to add logic to detect if there is another press by interrogating the last updated time:

1 Like

I have 2 dimmer. Can you please tell me the steps to add them in HASS?

Hi @anon35356645 the top post by @PuckStar describes the steps, then modify the rest sensor as described in my post. Since you have 2 dimmers you will need to determine the correct sensor_number.
I might summarise the process as a Hackster post in a bit

It’s indeed possible to trigger other events based on the dimmer buttons however keep in mind that when you for instance click the off button to turn off the lights, and the next day the lights turned on again via an automation (so not using the On button), the status will not change. It was and stays 4002.
So when you then press again the Off button, HASS will not notice a change and won’t trigger anything!

I didn’t find a way to work around that yet.

I think the solution is to have a sensor for the ‘lastupdated’, then if that changes query the button state.

I do something similar for detecting changes of my external IP (Detect if IP changes?), however currently have hard coded the current IP. Is there a nice way to keep local variables in HASS? I suppose I could create a template sensor and write the current value to it, then over-write when new value is detected.

UPDATE: use Event state_changed

OK so the remote is mostly working… :slight_smile: Sometimes values come in as 4002, other times as 4000, so will need to just parse the first int in the string

- platform: rest
  resource: http://192.168.0.2/api/key/sensors/2
  name: dimmer1_state
  value_template: '{{ value_json.state.buttonevent }}'
  scan_interval: 1

- platform: rest
  resource: http://192.168.0.2/api/key/sensors/2
  name: dimmer1_updated
  value_template: '{{ value_json.state.lastupdated }}'
  scan_interval: 1

#### Hue dimmer switch
- alias: Hue dimmer 1 automations
  trigger:
    platform: state
    entity_id: sensor.dimmer1_updated
  action:
    service: notify.ios_robins_iphone
    data_template:
      title: "Hue notification"
      message: >
        {% if is_state("sensor.dimmer1_state", "1002") %}
        'Button 1 pressed'
        {% elif is_state("sensor.dimmer1_state", "2002") %}
        'Button 2 pressed'
        {% elif is_state("sensor.dimmer1_state", "3002") %}
        'Button 3 pressed'
        {% elif is_state("sensor.dimmer1_state", "4002") %}
        'Button 4 pressed'
        {% else %}
        none
        {% endif %}
1 Like

wow great find with the “lastupdated”! That solves the issue I had! :slight_smile:

I got a user, can get the list of devices … but not sure how to get the api-key???

instead of /api/sensor which command for the dimmer?

OK so its not an API key, its a ‘randomly generated username’ which you generate by following https://developers.meethue.com/documentation/getting-started

I just load the full page given by the URL in the rest sensor and browse until I find the name of the dimmer switch

Trying to have automation when Pressed On and an automation when pressed Off.
But it seems like it only triggers 1 of the 2 automations that should both trigger on the last status being updated.
This is what I have:

- alias: 'Hue Dimmer On'
  trigger:
    platform: state
    entity_id: sensor.hue_dimmer1_updated
  condition:
    condition: state
    entity_id: sensor.hue_dimmer1_state
    state: "1002"
  action:
    - service: notify.TelegramBot
      data:
        message: 'Dimmer Aan gezet'

- alias: 'Hue Dimmer Off'
  trigger:
    platform: state
    entity_id: sensor.hue_dimmer1_updated
  condition: 
    condition: and
    conditions: 
    - condition: state
      entity_id: sensor.hue_dimmer1_state
      state: "4002"
    - condition: time
      after: '17:00:00'
    - condition: time
      before: '05:00:00'
  action:
    - service: media_player.turn_off
      data:
        entity_id:
        - media_player.sony_bravia_tv

Dimmer On works, but Dimmer Off doesn’t.

Any ideas?
Can I have 2 automations that are checked for the same changed of status?

Try this:

#### Hue dimmer switch
- alias: Hue dimmer 1 automations
  trigger:
    platform: state
    entity_id: sensor.dimmer1_updated
  action:
    service: notify.ios_robins_iphone
    data_template:
      title: "Hue notification"
      message: >
        {% if states.sensor.dimmer1_state.state[0] == "1" %}
        'Button 1 pressed'
        {% elif states.sensor.dimmer1_state.state[0] == "2" %}
        'Button 2 pressed'
        {% elif states.sensor.dimmer1_state.state[0] == "3" %}
        'Button 3 pressed'
        {% elif states.sensor.dimmer1_state.state[0] == "4" %}
        'Button 4 pressed'
        {% else %}
        none
        {% endif %}

I notice that in my automation it is sometimes picking up the last sensor.hue_dimmer1_state state, and I have to press the button twice to get the true value of sensor.hue_dimmer1_state Have you noticed this?

Btw I made a post on Hackster covering the remote work, to be updated https://www.hackster.io/robin-cole/hijack-a-hue-remote-to-control-anything-with-home-assistant-5239a4

Yeah I think it’s because the Updated change is seen a bit earlier than the actual state change and thus the automation condition fails within that millisecond.

I changed my automation to this though didn’t test it yet:

- alias: 'Hue Dimmer Off'
  trigger:
    platform: state
    entity_id: sensor.hue_dimmer1_updated
  condition: 
    condition: and
    conditions: 
    - condition: state
      entity_id: sensor.hue_dimmer1_state
      state: "4002"
    # - condition: time
      # after: '17:00:00'
    # - condition: time
      # before: '05:00:00'
  action:
    - service: media_player.turn_off
      data:
        entity_id:
        - media_player.sony_bravia_tv

- alias: 'Hue Dimmer Off 2'
  trigger:
    platform: state
    entity_id: sensor.hue_dimmer1_state
    to: "4002"
  action:
    - service: media_player.turn_off
      data:
        entity_id:
        - media_player.sony_bravia_tv

BTW regarding your hackster submission, it’s not a wifi remote ;). Hue is zigbee.

Thanks for the tip!
Surely hue_dimmer1_state and hue_dimmer1_updated are updated in the same second, so I can’t see why the old value of hue_dimmer1_state would be picked up by HASS?

Why do we need a virtual sensor?
Only thing I did was to add this to my HA-conf:

  • platform: rest
    resource: http://[Hue bridge IP]/api/[API-KEY]/sensors/[Sensor ID]
    value_template: ‘{{ value_json.state.presence }}’
    scan_interval: 2
    name: ‘…’

Did the same thing to temperatur but I’m fetching that every 60 second. Does anybody experience any problem bu polling the motion every 2s?

This is what @ThinkPad wrote about it: “It could be indeed, that the presence is already exposed. But the benefit of having a virtual sensor is that you don’t have to create the logic on the HASS side and just have to poll one sensor (the virtual one).”

I still don’t see the major benefit. If I want to create the rules in hass, then it’s great that the logic is in hass?
And by polling the real sensor, I’m also just polling one sensor?

Am I missing something?