From 1edbd0bbf32312f19720bd38135eb7718647a847 Mon Sep 17 00:00:00 2001 From: SBRK Date: Tue, 8 Oct 2019 23:13:22 +0200 Subject: [PATCH 1/2] Added optional "id" config option that overrides the ambilight_hue_off nodeId --- .../philips_ambilight+hue/switch.py | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/custom_components/philips_ambilight+hue/switch.py b/custom_components/philips_ambilight+hue/switch.py index b98ba56..673be81 100755 --- a/custom_components/philips_ambilight+hue/switch.py +++ b/custom_components/philips_ambilight+hue/switch.py @@ -5,7 +5,7 @@ import voluptuous as vol from homeassistant.components.switch import ( DOMAIN, PLATFORM_SCHEMA, SwitchDevice, ENTITY_ID_FORMAT) -from homeassistant.const import (CONF_HOST, CONF_NAME, CONF_USERNAME, CONF_PASSWORD, STATE_OFF, STATE_STANDBY, STATE_ON) +from homeassistant.const import (CONF_HOST, CONF_NAME, CONF_USERNAME, CONF_PASSWORD, CONF_ID, STATE_OFF, STATE_STANDBY, STATE_ON) from requests.auth import HTTPDigestAuth from requests.adapters import HTTPAdapter @@ -14,31 +14,35 @@ DEFAULT_USER = 'user' DEFAULT_PASS = 'pass' DEFAULT_NAME = 'Ambilight+Hue' +DEFAULT_ID = '2131230774' BASE_URL = 'https://{0}:1926/6/{1}' # for older philps tv's, try changing this to 'http://{0}:1925/1/{1}' TIMEOUT = 5.0 CONNFAILCOUNT = 5 PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ - vol.Required(CONF_HOST, default=DEFAULT_HOST): cv.string, - vol.Required(CONF_USERNAME, default=DEFAULT_USER): cv.string, - vol.Required(CONF_PASSWORD, default=DEFAULT_PASS): cv.string, - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string + vol.Required(CONF_HOST, default=DEFAULT_HOST): cv.string, + vol.Required(CONF_USERNAME, default=DEFAULT_USER): cv.string, + vol.Required(CONF_PASSWORD, default=DEFAULT_PASS): cv.string, + vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, + vol.Optional(CONF_ID, default=DEFAULT_ID): cv.string }) def setup_platform(hass, config, add_devices, discovery_info=None): - name = config.get(CONF_NAME) - host = config.get(CONF_HOST) - user = config.get(CONF_USERNAME) - password = config.get(CONF_PASSWORD) - add_devices([AmbiHue(name, host, user, password)]) + name = config.get(CONF_NAME) + host = config.get(CONF_HOST) + user = config.get(CONF_USERNAME) + password = config.get(CONF_PASSWORD) + nodeId = config.get(CONF_ID) + add_devices([AmbiHue(name, host, user, password, nodeId)]) class AmbiHue(SwitchDevice): - def __init__(self, name, host, user, password): + def __init__(self, name, host, user, password, nodeId): self._name = name self._host = host self._user = user self._password = password + self._nodeId = int(nodeId) self._state = False self._connfail = 0 self._available = False @@ -63,15 +67,15 @@ def should_poll(self): def turn_on(self, **kwargs): - self._postReq('menuitems/settings/update', {"values":[{"value":{"Nodeid":2131230774,"Controllable":"true","Available":"true","data":{"value":"true"}}}]} ) + self._postReq('menuitems/settings/update', {"values":[{"value":{"Nodeid":self._nodeId,"Controllable":"true","Available":"true","data":{"value":"true"}}}]} ) self._state = True def turn_off(self, **kwargs): - self._postReq('menuitems/settings/update', {"values":[{"value":{"Nodeid":2131230774,"Controllable":"true","Available":"true","data":{"value":"false"}}}]} ) + self._postReq('menuitems/settings/update', {"values":[{"value":{"Nodeid":self._nodeId,"Controllable":"true","Available":"true","data":{"value":"false"}}}]} ) self._state = False def getState(self): - fullstate = self._postReq('menuitems/settings/current', {'nodes':[{'nodeid':2131230774}]}) + fullstate = self._postReq('menuitems/settings/current', {'nodes':[{'nodeid':self._nodeId}]}) if fullstate: self._available = True ahstat = fullstate['values'][0]['value']['data']['value'] From afd545ca1573e87715eede4862475ff4f1bff192 Mon Sep 17 00:00:00 2001 From: SBRK Date: Tue, 8 Oct 2019 23:18:05 +0200 Subject: [PATCH 2/2] Updated readme.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 6ddd9fe..5eeb905 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,11 @@ switch: host: 192.168.1.XXX username: !secret philips_username password: !secret philips_password + id: 2131230774 # ambilight_hue_off node id. Default is 2131230774, but some newer TVs use 2131230778 instead. scan_interval: 5 ``` +If the component is not working, try setting `2131230778` as the `id` in the config + *note:* there is often a noticeable lag between Home Assistant sending the request to toggle the setting, and receiving a status update from the API, for this reason, it is advised that you reduce your `scan_interval` (in seconds) to suit your needs. +