Git Product home page Git Product logo

hue-remotes-hass's Introduction

Code style: black build status Coverage

FOR COMMUNITY SUPPORT PLEASE USE THIS THREAD

For Hue motion sensors checkout Hue-sensors-HASS

If using Home Assistant >= v0.108, please read the deprecation and suggested migration section

Hue-remotes-HASS

Custom integration for Hue & Lutron Aurora Friends of Hue (FOH) remotes with Home Assistant.

Overview

This custom integration provides the missing support for remote devices in the official Hue integration of HA Core, by registering the platform in the main integration and sharing the sensor data with it.

As this new platform imposes a lower scan_interval for all hue sensors (of 1Hz), sensors from the main hue integration will also increase their refresh rate to 1 Hz.

Be advised that the increased update of this custom integration may cause connectivity problems which can result in errors in the official hue integration, please do not create any issue for this. If you can't live with these errors, do not use this custom integration.

Suggested migration

Since HA v0.108 Hue switches are recognized in the hue integration, making this CC not really necessary anymore, but there are some caveats, as it is not a perfect replacement for this CC.

Now the main hue registers the remotes as devices, and fires events with the detected button presses. For easier usage from UI, it also presents the button presses as device triggers for automations. In addition, for battery-powered remotes it generates battery sensor entities.

The features of this CC over what the main hue offers are to:

  1. Expose the switches as entities (of kind remote, but they actually are sensor), showing the last button press as the state, using fixed state mappings (like code 3002 is "3_click_up", etc.)
  2. Modify the hue update interval to a fixed, much faster, rate (1Hz by default, customizable with scan_interval: X), to have a faster polling than the 5 secs of the main integration

But as this CC is not using the Integrations menu, it needs manual yaml and a HA restart for any config change. It also has some problems derived of doing too many calls to the Hue bridge, and its usage for automation triggers now presents some flaws with false positives.

In this context, this CC is being deprecated, and these are some suggestions to migrate to other HACS custom integrations to achieve the best results, depending of your own specific needs:

  • If you need a faster polling interval for the hue bridge than the 5s, use Fast-Hue CC to:

    • Modify the main hue update interval to any value, different for each bridge
    • Monitor the current refresh rates with sensor entities
    • Enable a service to change the refresh rate anytime
  • If you want to expose the remotes as entities, because you want to track their state or use it to trigger automations, use EventSensor CC

    • It is UI configurable (with no restart required) and has configuration wizards to help configure the Hue switches for this specific migration.
    • The mapping for the button presses is customizable, being the default maps the same ones used here
    • It will not generate false positives, as it listens to the events generated in the main hue (listening directly to those events, or using UI device triggers would also do the trick)

You can use both new CCs, or none of them, if you are comfortable with the main hue polling and change your automations to use 'device triggers'.

Both are configurable via UI, so no restarts are needed to install and try them. To do the smoothest migration, with just one HA restart, follow these steps:

  1. Remove the yaml config for this CC, and replace every remote.entity_name in your config (like in automations.yaml) to sensor.entity_name, as the new entities will be of sensor type.
  2. Disable all automations using the remotes, as we don't want them triggering until migration is finished :)
  3. Uninstall this CC from HACS.
  4. Restart HA. Now the remote.x entities should be gone and this CC would not be loaded.
  5. Install "Event sensor" from HACS.
  6. In Integrations, add and configure a new sensor for each old remote. Follow the wizard for Hue remotes, set the same name as before (so new entities will be sensor.entity_name), and, as the identifier, choose "id" and set the entity_name.

At that point the migration is done, and you can check the new sensor entities by pressing buttons, and then re-enable the automations to check that everything works as before.

If the fast polling interval is required, install "Fast-Hue polling" from HACS and configure it for your needs, taking into account that, if polling too fast, some logging errors may appear in the main hue. In that case, feel free of playing with different values to optimize your specific system, as there is a new service fasthue.set_update_interval to do just that in any moment.

Installation

Install via HACS. You need to set up your Hue bridge first.

Manual installation

Alternatively, place the custom_components folder in your configuration directory (or add its contents to an existing custom_components folder).

Configuration

Once installed add to your configuration:

remote:
  - platform: hueremote

The scan interval can be modified optionally, by adding scan_interval: 2.

Supported remotes

Developers

  • Create venv -> $ python3 -m venv venv
  • Use venv -> $ source venv/bin/activate
  • Install requirements -> $ pip install -r requirements.txt & $ pip install -r requirements-dev.txt
  • Run tests -> $ venv/bin/py.test --cov=custom_components tests/ -vv -p no:warnings
  • Black format -> $ venv/bin/black custom_components/* (or setup VScode for format on save)

Contributors

Please format code usign Black before opening a pull request.

A big thanks to Atsuko Ito and Eugenio Panadero for their many contributions to this work!

hue-remotes-hass's People

Contributors

azogue avatar inverse avatar robmarkcole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hue-remotes-hass's Issues

'HueBridge' object has no attribute 'sensor_manager'

Hi,

I am fairly new to HA. Im getting this error stated below. Anything I am missing?

My configuration looks like this:
hue:
bridges:
- host: 192.168.x.x
allow_unreachable: true
allow_hue_groups: true

remote:

  • platform: hueremote

Log Details (ERROR)
Wed Apr 08 2020 09:13:21 GMT+0200 (Central European Summer Time)
Error while setting up platform hueremote
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/home/homeassistant/.homeassistant/custom_components/hueremote/remote.py", line 40, in async_setup_platform
config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL),
File "/home/homeassistant/.homeassistant/custom_components/hueremote/data_manager.py", line 159, in async_add_platform_entities
async for is_new, model, dev_id, _ in self._iter_data(platform_models):
File "/home/homeassistant/.homeassistant/custom_components/hueremote/data_manager.py", line 56, in _iter_data
await bridge.sensor_manager.coordinator.async_request_refresh()
AttributeError: 'HueBridge' object has no attribute 'sensor_manager'

Archive this repo

Now there are better options, as documented in the readme, we are archiving this repo. This is to indicate that its time to move onto the better options, and prevent unwanted issues being opened here. This integration will remain on HACS until it (eventually breaks), then be removed.

Scan_interval still available?

During the realization of the new architecture of this custom integration, a scan setting was introduced to diverge form the default 0.5 hz frequency:

remote:
  - platform: huesensor
    scan_interval: 1

is this still available in the new split-up configuration? I ask because it isn't mentioned any more in the docs, but very much needed in the real life setup...to not Hammer the Hue Hub with an overdose of requests

aiohue.sensors missing?

Hey there, I followed the steps and added the hue_remote folder to custom_components

➜  homeassistant git:(master) ✗ ls custom_components/hueremote
implemented_remotes.py  __init__.py  manifest.json  __pycache__  remote.py

I am getting the following error

Platform error remote.hueremote - cannot import name 'TYPE_ZLL_ROTARY' from 'aiohue.sensors' (/usr/local/lib/python3.7/site-packages/aiohue/sensors.py)

Any ideas what I need to do to fix this?

Last button event does not refresh if same button is pressed again

On the Philips Hue Dimmer Switch, the last button event seems to "stick" until a different button is pressed. This prevents the user from pressing the button a second time, even if hours later. Can we add an option clear the last event immediately after (or shortly after) a button press?

Example:
I use the 3_click_up event (fan off button) to turn off a fan. Let's say I used the button to turn off the fan three hours ago. Then I later turn the fan back on by some means other than the remote. I now cannot use the 3_click_up event to turn off the fan because the last registered button event is still the 3_click_up from three hours ago. If I press the button, no new "to" 3_click_up event is registered now.

This is demonstrated in the screenshot below. The 3_click_up event triggered 3 hours ago, so I cannot trigger it again unless I click another button first.

image

Automations triggering on other attribute updates (since v0.2)

This may not be so much of a bug, but more of a how do I workaround this now.

I have a single automation for a remote, it looks like this:
trigger:

  • entity_id: remote.abc_bedroom_switch
    platform: state
    condition:
  • condition: or
    conditions:
    • condition: state
      entity_id: remote.abc_bedroom_switch
      state: 1_click_up
    • condition: state
      entity_id: remote.abc_bedroom_switch
      state: 2_click_up
    • condition: state
      entity_id: remote.abc_bedroom_switch
      state: 3_click_up
    • condition: state
      entity_id: remote.abc_bedroom_switch
      state: 4_click_up
      action:
  • data_template:
    button: '{{ trigger.to_state.state }}'
    room: abc_bedroom
    service: script.abc_bedroom_hue_remote

The script it calls looks like this:
abc_bedroom_hue_remote:
alias: ABC bedroom bedside hue remote
description: Call various scripts depending on the button/press type

sequence:
- service_template: >
{% set group = 'group.' ~ room ~ '_lights' %}
{% set script = {
'1_click_up': 'script.lights_off' if is_state(group, 'on') else 'script.lights_on',
'2_click_up': 'script.lights_increase_brightness',
'3_click_up': 'script.lights_decrease_brightness',
'4_click_up': 'script.lights_off',
}
%}
{{- script[button] -}}
data_template:
room: '{{ room }}'
lights: >
{% set group = 'group.' ~ room ~ '_lights' %}
{% set lights = {
'1_click_up': expand(group) | map(attribute='entity_id') | join(','),
'2_click_up': expand(group) | selectattr('state','eq', 'on') | map(attribute='entity_id') | join(','),
'3_click_up': expand(group) | selectattr('state','eq', 'on') | map(attribute='entity_id') | join(','),
'4_click_up': expand(group) | map(attribute='entity_id')| join(',') ~ ',' ~ expand('group.abc_bathroom_lights') | map(attribute='entity_id') | join(','),
}
%}
{{- lights[button] -}}

Probably not the most efficient way to do this, but I was using it as a reason to learn more about scripts. I plan to move most of it back to the automation, and reduce the number of script calls. I originally started with a bunch of ifs, but saw someone using the Jinja dicts in a neat way and I replicated it.

With the new version of HASS/Hueremote, additional attributes are exposed, including the battery level. While the last_updated: doesn't change, I've noticed the battery can jump around a bit, mainly after being used. What's now happening is I press a button, and it triggers as expected. Let's say I pressed button 1, and my lights toggle. The state may look like:

model: ZLLSwitch
last_button_event: 1_click_up
last_updated: 2020-04-18, 03:10:00
name: ABC Bedroom switch
on: true
reachable: true
battery_level: 94
friendly_name: ABC Bedroom switch
icon: mdi:remote
supported_features: 0

Shortly afterwards, my lights turn off again and I can see the state has changed to:
model: ZLLSwitch
last_button_event: 1_click_up
last_updated: 2020-04-18, 03:10:00
name: ABC Bedroom switch
on: true
reachable: true
battery_level: 93
friendly_name: ABC Bedroom switch
icon: mdi:remote
supported_features: 0

Since the button event doesn't have a reset back to 'none', the battery level updating causes the trigger to fire, and rerun the same action.

With my limited knowledge and skill set, I can see two ways to fix this. One would be to make a template sensor/input/something that just takes the button press event and replicates it without anything else attached. The other would be to check the last_updated and see if it's changed in the last second, but I don't know how to compare times yet, although I'm sure there are plenty of examples online.

I wanted to report this in case anyone else ran across it, or has suggestions on how best to deal with it.

Edit: I've added the following condition to my automation:

{{ as_timestamp(now()) | int - as_timestamp(states.remote.ABC_bedroom_switch.last_updated) | int < 1 }}

Fix tests

I quickly hacked the tests, but some still need fixing. Request assistance from @azogue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.