Philips Smart TVs also with SAPHI OS

I will as soon as I can, i’m upgrading HA from a rpi4 to and Intel nuc currently :+1:
Would be great to have this Integration.

Just to add, I had the same problem as Luitertje a few replies up. The Tv would go offline after a few minutes, sorry I’m not in possession of the logs anymore.

Have been the weekend away from home and once again lost the connection with the tv :unamused:.
Tried your PR and I can set the color with manual! What’s is the expert effect suppose to do? Would be nice if it you could set it back to follow the image.

Try grabbing a newer version of the pull. Turning the light entity off should return it back to following video.

I decided this entity is lounge light control. Ie non video following behaviour. It was hard to reason with when it should be off/on when some of the on states where related to video following and some not.

Ps. Loosing connection could sadly meen crashing things on the TV :frowning:

Hmm… I checked with the latest changes in the pull and the code seems to be the same.
I noticed that the light entity in HA goes off after like 10 seconds, seems a bit odd.

In manual mode and when the entity is off the endpoint ambilight/currentconfiguration gives:

{
	"styleName": "FOLLOW_COLOR",
	"isExpert": false,
	"menuSetting": "HOT_LAVA",
	"stringValue": "Hot Lava"
}

It doesn’t fall back to “FOLLOW_VIDEO” for now.

@Luitertje forgot that you are on a Saphi system. Could you try this command on your TV when it’s in that state.

First:

python -m haphilipsjs -i hostname -a 6 post ambilight/mode "{'current': 'internal'}"

Then

python -m haphilipsjs -i hostname -a 6 post ambilight/mode "{'current': 'internal_invalid'}"

I want to see if it perhaps has the same bug as android system.

With both I get

python -m haphilipsjs -i 192.168.178.XX -a 6 post ambilight/mode "{'current': 'internal'}"
usage: python -m haphilipsjs [-h] [-d] -i HOST -a API [-s] [-u USERNAME]
                             [-p PASSWORD]
                             {status,monitor,ambilight,pair,get,markdown} ...
python -m haphilipsjs: error: argument command: invalid choice: 'post' (choose from 'status', 'monitor', 'ambilight', 'pair', 'get', 'markdown')

Update the ha-philipsjs module to master:

pip install -I git+https://github.com/danielperna84/ha-philipsjs.git@master

Internal:

{}

internal_invalid:

WARNING:haphilipsjs:Post failed: {'current': 'internal_invalid'} -> <html><head><title>Service Unavailable</title></head><body>Service Unavailable</body></html>
None

Okey at least it behaves better than android in that regard. But it still doesn’t switch back to follow video?

Nope it doesn’t switch back to follow video.
In the settings of the tv it also states that it follows the app.
Also the entity in HA still goes off after a few seconds, both manual and expert effect.

Oh it goes off when in manual?

Could your get the ambilight/mode endpoint after you switched it to manual?

Maybe it has the other bug in that it doesn’t report state.

You can test just with the tool. Post it to manual with above command then get it back and see if actually report manual.

It goes off in manual and expert. Endpoint keeps the same.

{
	"current": "internal"
}

Ok. then there is a similar bug in this implementation that it can’t report the set mode. I should enable the quirk for that on the saphi systems too.

I have now updated the integration so that saphi tv’s have same work around as android. We remember the ambilight mode we set and ignore the invalid data from the device.

Can you update and see if at least the stays on?

I’m getting this error trying to turn the light on in HA.


Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/philips_js/light.py:121 
Integration: Home Assistant WebSocket API (documentation, issues) 
First occurred: 7:30:26 (5 occurrences) 
Last logged: 7:31:07

[140491537802576] 'algorithms'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 137, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1488, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1523, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 642, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 681, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 679, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 235, in async_handle_light_on_service
    await light.async_turn_on(**params)
  File "/config/custom_components/philips_js/light.py", line 296, in async_turn_on
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 295, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 313, in _async_write_ha_state
    attr = self.capability_attributes
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 464, in capability_attributes
    data[ATTR_EFFECT_LIST] = self.effect_list
  File "/config/custom_components/philips_js/light.py", line 118, in effect_list
    effects.extend(
  File "/config/custom_components/philips_js/light.py", line 121, in <genexpr>
    for algo in style["algorithms"]
KeyError: 'algorithms'

Oh right. I think I got that fixed. I ended upp adding support for all the expert styles the tv support.

Logger: homeassistant.config_entries
Source: loader.py:504
First occurred: 9:39:39 (1 occurrences)
Last logged: 9:39:39

Error setting up entry 50PUS6804/12 (FZ4A1940070795) for light
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 249, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 270, in async_setup_entry
    return await hass.data[DOMAIN].async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 140, in async_setup_entry
    platform = await async_prepare_setup_platform(
  File "/usr/src/homeassistant/homeassistant/setup.py", line 298, in async_prepare_setup_platform
    platform = integration.get_platform(domain)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 499, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 504, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 779, in exec_module
  File "<frozen importlib._bootstrap_external>", line 916, in get_code
  File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/philips_js/light.py", line 121
    for algo in style.get("algorithms", {})]
                                           ^
SyntaxError: closing parenthesis ']' does not match opening parenthesis '(' on line 118

Removing the ] on line 118 fixed it.
The entity stays on in HA and the effects seems to be all working.
I can change the color by setting the effect in expert and then choose the color.
Turning the entity off and it seems like it’s working now. :smiley:

{
	"styleName": "FOLLOW_VIDEO",
	"isExpert": false,
	"menuSetting": "STANDARD",
	"stringValue": "Standard"
}

I’m a bit confused with the different github repos being linked. Where is the custom component and do I need to run the python commands in terminal or are they only for debugging?

If somoene is able to provide simpler instructions on what I need to do to get the Philips 754 TV showing up in Home Assistant (similar to what @Kev1 achieved) that would be really helpful :slight_smile:

The integration is already in the latest HA. You can add it with the the integration Philips TV with api v6. The control of the ambilight not yet. There is this pull request for https://github.com/home-assistant/core/pull/44867
The python commands are only for debugging.