Hue motion sensors + remotes: custom component

is there a way of making the click function of the dimmer switch work as an event? similar to button pressed? I can’t seem to make the dimmer sensor register if I press the same button later on, if I don’t press another button first. Meaby possible with signal recieved? But don’t know if that is possible with the hue bridge.

In answer to both questions, this required the remotes to be rewritten as true remotes components. PR welcome :smiley:

It would take a while to I have learned enough about python to help you there, but you think it is possible to do it with the hue bridge and the dimmer switch?

It’s pretty simple, you would just fire an event on last_updated == current time

Thank you so much, got it to work at last using this method:

   trigger:
    - platform: state
      entity_id: sensor.dimmer_hue_template_last_updated
   condition: 
    condition: template
    value_template: '{{ states.sensor.hue_dimmer_switch_gang.last_updated.strftime("%H:%M:%S") == utcnow().strftime("%H:%M:%S") and states.sensor.hue_dimmer_switch_gang.state == "1_click" }}'
   action:
    - service: light.turn_on
2 Likes

Thanks for this. I was previously using the ‘old’ version (REST sensor) and it used to display lux in thousands (13000, 14500 etc.) whereas now it displays them as 41.33, 38.02 etc.

Should it still be displaying the lux in thousands or are the lower readings ‘the way forward’?
I’m only asking as I have some automations that trigger when the light level drops below 13000. If the lux will always use the lower readings going forward then I’ll adjust my automations accordingly :slight_smile:

I recall there was a PR from someone who put these values in correct ‘lux’ units, I think there is a formula included in the current repo. You will just want to update your thresholds.
Cheers

1 Like

Great, thanks for confirming that :+1:t3:

of course thats very nice! Although: cant you set that in the hue app itself? Maybe much simpler.
What i like about this is the option to trigger something else than light.turn_on. One could trigger anything available in HA for that matter, from a switch, door to complete scenes?

Very nice indeed.

interesting read: https://www.howtogeek.com/244803/how-to-re-program-the-hue-dimmer-switch-to-do-anything-with-your-lights/

or this one by a certain author :wink:

Thank you. Of course I don`t use that automation to control my hue lights, that would be stupid :stuck_out_tongue: The service there was just an example, it was the trigger and condition set up that was of interest. I use the remote to turn off all my lights, which is 433 Mhz devices and hue lights, my tv, stereo etc. What I like about the remote is that it is seems more stable than my previous 433 Mhz remote, and is 3 times cheaper than a z-wave remote :slight_smile:

I dont`t use iphone, so I wouldn’t know about the app.
The link you referring are just setup using rest sensor instead of the custom component? Since the custom component register the remote anyways, that is the old way of doing it, as the link refers to the custom component?

Btw, if you want to use both long click and click function, you need to do one of the following, since when you long click, you first send a click command, then the hold command:

1: Set longer update interval for all your sensor, so homeassistant don`t register the click command when you long press.

or

2: Add delay and condition in action:

 - alias: "Lys Spotter Kjokken På 2"
   trigger:
    - platform: state
      entity_id: sensor.dimmer_hue_template_last_updated
   condition: 
    condition: template
    value_template: '{{ states.sensor.hue_dimmer_switch_gang.last_updated.strftime("%H:%M:%S") == utcnow().strftime("%H:%M:%S") and states.sensor.hue_dimmer_switch_gang.state == "4_click" }}'   
   action:
    - delay: 00:00:01
    - condition: state
      entity_id: sensor.hue_dimmer_switch_gang
      state: '4_click'
    - service: light.turn_on
      data:
        entity_id: light.lys_spotter_stue 
        brightness_pct: 100    

You just need to add that to the automation you want when you use the click as trigger condition. The hold state won’t be triggered unexpected.

Thanks again @robmarkcole for this great custom component! Just hope in the future it would be possible to get rid of all the error messages in the log. Then everything would be perfect :slight_smile:

Edit: Can of course do it a little easier:

 - alias: "test"
   trigger:
    - platform: state
      entity_id: sensor.dimmer_hue_template_last_updated
   condition: 
    condition: state
    entity_id: sensor.hue_dimmer_switch_gang
    state: '4_click'
    for:
      seconds: 1
   action:
     - service: switch.turn_on
       entity_id: switch.lys_taklys_kjokken 

 - alias: "test2"
   trigger:
    - platform: state
      entity_id: sensor.dimmer_hue_template_last_updated
   condition: 
    condition: state
    entity_id: sensor.hue_dimmer_switch_gang
    state: '4_hold'
   action:
    - service: light.turn_on
      data:
        entity_id: light.lys_spotter_kjokken  
        brightness_pct: 100

I’m struggling a bit to get this working, and I’m wondering if there’s a step I’m missing.

platform: rest
resource: http://[ipaddress]/api/[key]/sensors/5/config
method: put
name: Movie Room Sensor
body_on: '{"on": true}'
body_off: '{"on": false}'

I’m using Hassio and connecting via Duckdns. The ip address is in the internal network (192.168.x.x). To run it, I’m simply doing the following:

  - alias: "Movie Room Sensor On"
    trigger:
      - platform: state
        entity_id: input_boolean.movie_room_sensor
        to: 'on'
         
      
    action:

        - service: switch.turn_on
          entity_id: switch.movie_room_sensor
     
  - alias: "Movie Room Sensor Off"
    trigger:
      - platform: state
        entity_id: input_boolean.movie_room_sensor
        to: 'off'
         
      
    action:
   
        - service: switch.turn_off
          entity_id: switch.movie_room_sensor

Is anything jumping out to you? It’s working when I use the hue debugger, so I know I got the syntax and URL correct.

Hi @Litrecola have you got it working with requests or Postman?
I can’t see anything obviously wrong but I would certainly debug with one of those tools.

I was able to get the GET REST working from the sensor without a problem (for the temperature). My syntax must just be off. Luckily another user got around the issues they were having through CURL:

1 Like

Hey there! I just got a pi and home assistant to trigger wemo lights with hue motion sensor and remotes.

I followed the instructions in https://github.com/robmarkcole/Hue-sensors-HASS
but it replaced all of my discovered devices with my sensors plus some weird attributes.

Do you see any obvious mistake I made?

Hi Rob!

When I try to create a binary sensor out of this sensor’s attributes, I always get errors. Any idea why this may be?

config:

- platform: template
  sensors:
    kitchen_is_lit:
      friendly_name: 'Kitchen Is Lit'
      device_class: light
      value_template: {{ is_state_attr('sensor.kitchen_motion_sensor', 'dark', false) }}

result:

ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: while parsing a flow mapping
  in "/config/binary-sensors.yaml", line 24, column 32
expected ',' or '}', but got '<scalar>'
  in "/config/binary-sensors.yaml", line 24, column 79

Any help would be appreciated!

Appears you have not specified an attribute (Lux) the example config in the github repo should help

The temperature and light level work nicely. I wanted to do a binary_sensor here, but no matter what I tried, I never got on/off from the true/false of the attributes.

Please use the dev-template tool to check what your template is returning, as to me your config looks fine.

I must be overlooking something obvious! Currently trying

    kitchen_motion:
      friendly_name:          Kitchen Motion
      device_class:           motion
      value_template:         {{ states('sensor.kitchen_motion_sensor') == 'on' }}

when in the config file

ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: invalid key: "OrderedDict([("states('sensor.kitchen_motion_sensor') == 'on'", None)])"
  in "/config/binary-sensors.yaml", line 24, column 0

but in dev-template the same template {{ states('sensor.kitchen_motion_sensor') == 'on' }} returns true/false as expected.

Try putting the value template inside string quotation marks as others have done on this thread