Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0d52c38
Update manifest.json
Mr-Groch Apr 4, 2021
ea7b66d
0.0.2
Mr-Groch Apr 4, 2021
5c6af3a
0.0.2
Mr-Groch Apr 4, 2021
8aa2b95
Update README.md
Mr-Groch Apr 4, 2021
7e88bcb
0.0.3 - configurable secured_transport and api_version
Mr-Groch May 5, 2021
4f2fd5e
0.0.3
Mr-Groch May 5, 2021
38e1391
0.0.3
Mr-Groch May 5, 2021
14666f7
Update info.md
Mr-Groch May 5, 2021
8719a53
Update manifest.json
Mr-Groch May 5, 2021
ca23601
Update README.md
Mr-Groch May 5, 2021
afc45d8
Create FUNDING.yml
Mr-Groch May 5, 2021
cdea67a
Create validate.yaml
Mr-Groch May 14, 2021
39245a8
Create hassfest.yaml
Mr-Groch May 14, 2021
2fe5167
Add issue_tracker and iot_class
Mr-Groch May 14, 2021
dd25f57
Create hacs.json
Mr-Groch May 14, 2021
2e6e0c3
Update README.md
Mr-Groch May 14, 2021
7e25019
Update info.md
Mr-Groch May 14, 2021
30ecc07
Update info.md
Mr-Groch May 14, 2021
b4d3699
Update README.md
Mr-Groch Jun 13, 2021
3386206
unique_id and default icon
Mr-Groch Jan 8, 2022
00c227d
huge refactor
Mr-Groch Mar 18, 2022
81ac819
remove + sign from integration path
Mr-Groch Mar 18, 2022
227bbef
Delete info.md
Mr-Groch Mar 18, 2022
24ee1c5
Update hacs.json
Mr-Groch Mar 18, 2022
62d3d80
Update manifest.json
Mr-Groch Mar 18, 2022
60a14c2
Update README.md
Mr-Groch Mar 18, 2022
b283685
Add files via upload
alicialiali Apr 3, 2022
f1d1ddc
Merge pull request #3 from LeandroIssa/master
Mr-Groch Apr 24, 2022
99dd6f0
v1.0.1
Mr-Groch Apr 24, 2022
d65175a
Update HACS URL
wrt54g May 16, 2022
aacd560
Update hacs.json
Mr-Groch May 25, 2022
cf27a09
Merge pull request #4 from wrt54g/master
Mr-Groch May 25, 2022
bd419f5
Config entry platforms
Mr-Groch Mar 12, 2023
b25dfa3
1.0.2
Mr-Groch Mar 12, 2023
e068ae8
Missing version
Mr-Groch Mar 12, 2023
8eca367
Keys order
Mr-Groch Mar 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [Mr-Groch]
custom: ["https://paypal.me/MrGroch", "https://www.buymeacoffee.com/MrGroch"]
14 changes: 14 additions & 0 deletions .github/workflows/hassfest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Validate with hassfest

on:
push:
pull_request:
schedule:
- cron: "0 0 * * *"

jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: home-assistant/actions/hassfest@master
17 changes: 17 additions & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Validate

on:
push:
pull_request:
schedule:
- cron: "0 0 * * *"

jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- name: HACS validation
uses: "hacs/action@main"
with:
category: "integration"
49 changes: 30 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/hacs/integration)
[![paypalme_badge](https://img.shields.io/badge/Donate-PayPal-0070ba)](https://paypal.me/MrGroch)
[![Buy me a coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/MrGroch)

# Philips TV Ambilight+Hue (Switch) Component
A Switch component for automating the control of the Ambilight+hue setting on a Philips TV, this reveals the current status of the menu setting to Home Assistant, and allows for remote or automated toggling.

Forked from not maintained for a long time jomwell's repo:
https://github.com/jomwells/ambihue

## Installation

#### Option 1: (recommended)
This repository is compatible with the Home Assistant Community Store ([HACS](https://community.home-assistant.io/t/custom-component-hacs/121727)).
### Using [HACS](https://hacs.xyz/) (recommended)

This integration can be installed using HACS. To do it search for `Philips Ambilight+Hue Switch` in Integrations section.

### Manual

1. Using the tool of choice open the directory (folder) for your HA configuration (where you find `configuration.yaml`).
2. If you do not have a `custom_components` directory (folder) there, you need to create it.
3. In the `custom_components` directory (folder) create a new folder called `philips_ambilight_hue`.
4. Download _all_ the files from the `custom_components/philips_ambilight_hue/` directory (folder) in this repository.
5. Place the files you downloaded in the new directory (folder) you created.
6. Restart Home Assistant.
7. [Configure](#Configuration) custom component using Config Flow UI.


## Configuration

After installing HACS, install 'Philips Ambilight+Hue' from the store, and use the ```configuration.yaml``` example below.
After installation of the custom component, it needs to be added using **Config Flow UI**.

#### Option 2: (manual)
If you have already set up the [Ambilight (Light) component](https://github.com/jomwells/ambilights), installing this component is very simple, copy the ```philips_ambilight+hue``` directory into your ```config/custom_components/``` directory,
enter the same username and password as for the ambilight component in the configuration.yaml, along with the IP of the TV, and restart home assistant:
To configure this integration go to: _Configuration_ -> _Integrations_ -> _Add integration_ -> _Philips TV Ambilight+Hue_.

If you have not setup any other Philips TV components, use the tool linked in the Ambilight (Light) component docs to obtain your username and password.
```
switch:
- platform: philips_ambilight+hue
name: Ambilight+Hue
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
```
You can also use following [My Home Assistant](http://my.home-assistant.io/) link

If the component is not working, try setting `2131230778` as the `id` in the config
[![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=philips_ambilight_hue)

*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.
Configuration steps are similar to official Philips TV integration, so if you need help look [here](https://www.home-assistant.io/integrations/philips_js/).

*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.
8 changes: 0 additions & 8 deletions custom_components/philips_ambilight+hue/manifest.json

This file was deleted.

117 changes: 0 additions & 117 deletions custom_components/philips_ambilight+hue/switch.py

This file was deleted.

142 changes: 142 additions & 0 deletions custom_components/philips_ambilight_hue/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
"""The Philips Ambilight+Hue integration."""
from __future__ import annotations

from typing import cast, Optional
import asyncio
from collections.abc import Mapping
from datetime import timedelta
import logging

from haphilipsjs import ConnectionFailure, PhilipsTV
from haphilipsjs.typing import SystemType

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_API_VERSION,
CONF_HOST,
CONF_PASSWORD,
CONF_USERNAME,
Platform,
)
from homeassistant.core import (
HomeAssistant,
callback,
)
from homeassistant.helpers.debounce import Debouncer
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import CONF_SYSTEM, DOMAIN

PLATFORMS = [
Platform.SWITCH,
]

LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Philips TV from a config entry."""

tvapi = PhilipsTV(
entry.data[CONF_HOST],
entry.data[CONF_API_VERSION],
username=entry.data.get(CONF_USERNAME),
password=entry.data.get(CONF_PASSWORD),
)
coordinator = PhilipsTVDataUpdateCoordinator(hass, tvapi, entry.options)

await coordinator.async_refresh()
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = coordinator

for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)

entry.async_on_unload(entry.add_update_listener(async_update_entry))

return True


async def async_update_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Update options."""
await hass.config_entries.async_reload(entry.entry_id)


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, component)
for component in PLATFORMS
]
)
)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok


class PhilipsTVDataUpdateCoordinator(DataUpdateCoordinator[None]):
"""Coordinator to update data."""

def __init__(self, hass, api: PhilipsTV, options: Mapping) -> None:
"""Set up the coordinator."""
self.api = api
self.options = options

self.huelampstate: Optional[str] = None

super().__init__(
hass,
LOGGER,
name=DOMAIN,
update_interval=timedelta(seconds=30),
request_refresh_debouncer=Debouncer(
hass, LOGGER, cooldown=2.0, immediate=False
),
)

@property
def system(self) -> SystemType:
"""Return the system descriptor."""
if self.api.system:
return self.api.system
return self.config_entry.data[CONF_SYSTEM]

@property
def unique_id(self) -> str:
"""Return the system descriptor."""
entry: ConfigEntry = self.config_entry
assert entry
if entry.unique_id:
return entry.unique_id
assert entry.entry_id
return entry.entry_id

async def getHueLampState(self):
r = await self.api.getReq("HueLamp/power")
if r:
self.huelampstate = cast(str, r["power"])
else:
self.huelampstate = None
return r


async def setHueLampState(self, state):
data = {"power": state}
if await self.api.postReq("HueLamp/power", data) is not None:
self.huelampstate = state
return True

@callback
async def _async_update_data(self):
"""Fetch the latest data from the source."""
try:
await self.getHueLampState()
await self.api.update()
except ConnectionFailure:
pass
Loading