Support "remote"-entities
Closed this issue ยท 16 comments
The "Remotes" section in the web configurator currently supports only IR-remotes.
This is a request for it to also support the HA "remote" enitity exposed by some integrations (e.g. remote.philips_tv
).
Currently, it is necessary to create a script for each button in order to use the remote via HA. This is not only tedious to create but also problematic since an activity only allows 50 active entities and each press is an entity.
With remote entity support, you would just add the remote entity and thus expose all commands to Remote Two like with IR remotes.
This code comment seems somewhat related: https://github.com/unfoldedcircle/integration-home-assistant/blob/47903d484d09ee0f9534caaf553dfd625d06b2b7/src/client/service/media_player.rs#L87C44-L87C44
This would be cool, but not sure how UC would get to know about the supported commands for that specific Remote entity. Unfortunately HA has no mechanism to indicate which commands are supported.
There was an architectural discussion about something like this, but that seems to have died out home-assistant/architecture#875
Edit: that being said, just having a textbox or something where we could just copy-paste the supported commands from the Home Assistant documentation would be a great help.
This would be cool, but not sure how UC would get to know about the supported commands for that specific Remote entity. Unfortunately HA has no mechanism to indicate which commands are supported.
There was an architectural discussion about something like this, but that seems to have died out home-assistant/architecture#875
Edit: that being said, just having a textbox or something where we could just copy-paste the supported commands from the Home Assistant documentation would be a great help.
Indeed it could only be the same behaviour as the "send command" function where you type the corresponding command in plain text.
Actually this is a big limitation because the media player component has very limited functions (play/pause, next/previous) and not the additional commands (such as arrow keys/OK commands). And without the bluetooth devices integration this is a must have
Thank you
Hi again, I have moved forward to implement the remote entity into the home assistant integration :
- Declaration of new remote entity type and service
- Extraction of remote state
- Most important : implementation of send command with string parameter (as the list of commands are not predefined and have to be submitted manually by the user)
- Unlock of remote entity in filtering in the web configurator
However the features and attributes are removed then : it seems that the remote entity type has to be implemented on RC core side ?
Here is the trace from the web simulator :
2024-01-18 10:15:23 2024-01-18T09:15:23.365785Z WARN remote_core::intg::external::handler::entity: [hass] Removing unknown feature 'on_off' in entity remote.salon_homepod 2024-01-18 10:15:23 2024-01-18T09:15:23.365786Z WARN remote_core::intg::external::handler::entity: [hass] Removing unknown feature 'send' in entity remote.salon_homepod 2024-01-18 10:15:23 2024-01-18T09:15:23.365787Z WARN remote_core::intg::external::handler::entity: [hass] Removing unknown feature 'stop_send' in entity remote.salon_homepod 2024-01-18 10:15:23 2024-01-18T09:15:23.365788Z WARN remote_core::intg::external::handler::entity: [hass] Removing unknown attribute 'state' in entity remote.salon_homepod
To integrate HA remote-entites requires support in the integration API, core services and web-configurator. They don't fully match the current internal IR remote-entity and will require additional logic in the core services. If they currently slip through as available entities, then this is a bug and not a feature :-)
Only the documented entities in the Core-Api are supported.
Supporting more HA entities, including remotes, is planned though.
Ok thank you this is what I feared. I thought one could associate the HASS remote entity to reuse an existing RC2 entity type.
Meantime I have initialized the code for the hass integration part. I have not been able to submit it through a pull request, so here is a patch file based on head revision.
remote_entity.patch
EDIT : actually (without the patch above) remote entities are correctly filtered by the HASS integration. The filter in the web ui lets you select remote type but no entity is displayed which is expected at this state
I've worked around this limitation in a slightly annoying way, which nevertheless seems to work a bit better than the built-in appletv remote for e.g. play/pause buttons on the remote UI (e.g. unfoldedcircle/feature-and-bug-tracker#315). Here's what I did:
- Make one button helper entity per button on the appletv remote. Name them
Home Theater Remote - <command>
This is annoying to do, but you only have do it once. I don't think there's a way to export the yaml for the buttons I created, otherwise I'd paste it here to ease your suffering. - Make an automation that hooks the appletv remote entity up to each of those buttons:
id: '1708186917053'
alias: Translate AppleTV buttons to remote events
description: ''
trigger:
- platform: state
entity_id:
- input_button.home_theater_cursor_up
- input_button.home_theater_cursor_down
- input_button.home_theater_cursor_left
- input_button.home_theater_cursor_right
- input_button.home_theater_ok
- input_button.home_theater_remote_menu
- input_button.home_theater_remote_turn_off
- input_button.home_theater_remote_turn_on
- input_button.home_theater_remote_play_pause
- input_button.home_theater_remote_home
- input_button.home_theater_remote_volume_down
- input_button.home_theater_remote_volume_up
- input_button.home_theater_remote_channel_down
- input_button.home_theater_remote_channel_up
- input_button.home_theater_remote_next
- input_button.home_theater_remote_previous
condition: []
action:
- service: logbook.log
metadata: {}
data:
name: hi
message: |-
{{ trigger.from_state.attributes.friendly_name|regex_replace(
find='Home Theater Remote - ',
replace='') }}
alias: Log command we're sending
- service: remote.send_command
metadata: {}
data:
command:
- |-
{{ trigger.from_state.attributes.friendly_name|regex_replace(
find='Home Theater Remote - ',
replace='')
}}
target:
entity_id: remote.home_theater
mode: single
- Reload the home-assistant integration on the remote & import all the "Home Theater Remote - " buttons
- Then, you can add those to your appletv activity & use the buttons on operations that should always work (e.g. play/pause, the menu & select button, skip forward/back)
I think until we have reliable reconnection working in the appletv remote integration, this works a lot better: You still wait for the remote to wake up, but it can send the command to hass on the first try & that reliably pauses media!
Hi,
there is a more efficient approach (unless I missed something) : instead of input buttons + using automations, you should use scripts directly. Create one script per apple TV command, and import the scripts in the remote.
This is more efficient because you have : remote => HA script call => Apple TV Command instead of remote => event => automation trigger => Apple TV command
Good idea! In the meantime, I actually stopped using this (it did have some annoying latency when the remote went to sleep, even though it didn't show the red "internal server error" banner anymore); instead, I disable remote sleep while the appletv-using activity is running. That reduces latency to near-zero and hasn't shown me a single error yet.
Hi,
just some thoughts for @zehnm after I checked after the code and possibilities of Home assistant : to say it shortly, we are kind of stuck because of Home assistant limitations.
Media player entities from assistant are very limited : a few playback commands, the ability to select a source or a sound mode and that is pretty much. I raised a feature request for this as I don't understand why HA does not propose additional (common) features : arrow keys and OK, back, (context) menu, number digits, and alpha keys
Also they chose to separate media player and remote entities which has not many sense as this is same device most of the time, but I think this was designed for remotes with no media player skills.
But even with this remote entity we are stuck because there are no predefined commands at all : just a custom command string as a parameter which depends on the device.
So there is no possibility at this state to map the RC2 commands to the remote entity.
The only possibility is to design a custom text command field on the RC2 side to be transmitted to the HA remote entity when sending commands.
Also @zehnm I saw in Rust code of HA integration that you use the get states request to retrieve all the entities, am I right ?
I didn't find any other requests to do this job, which is problematic because this request does not return the link between entities : for ex usually a media player entity is linked to the remote entity through the same device or integration.
But none of these 2 links are returned
Work has been started in branch feat/remote-entity.
It doesn't work yet with the current core version. A new simulator- and beta-version will be released in the following days.
Only tested with the Android Remote Tv so far, but already works pretty well.
The remote entities provided by Remote Two integrations can be used in activities and macros, but won't be exposed in the web-configurator "Remotes" sections yet. This will follow later, maybe only in the new v2 version.
The HA remote-entity is indeed very limited. I was also surprised that there's no way to retrieve the available commands, not even if they are all defined in the HA configuration file (e.g. the Global Cache integration). An enhancement is proposed here: home-assistant/architecture#875
Please vote it up ๐
just having a textbox or something where we could just copy-paste the supported commands from the Home Assistant documentation would be a great help.
With the remote-entity restrictions in HA, there won't be a list of available commands exposed in simple_commands
. Only the on, off, toggle and generic send commands are available. The single HA send_command
is split into a "Send command" and "Command sequence" for easier handling in the web-configurator. (More infos in unfoldedcircle/core-api#44).
This is how it's going to look like with an Android TV Remote entity:
The command parameter names are still missing in the web-configurator. This will be fixed in a future update.
For the Android TV Remote entity, at least "all" keycodes can be sent (supported keycodes in Android TV is yet another sad issue though).
I saw in Rust code of HA integration that you use the get states request to retrieve all the entities, am I right ?
I didn't find any other requests to do this job, which is problematic because this request does not return the link between entities
The HA WebSocket API isn't that sophisticated or at least not that well documented. If I'm not mistaken, there are more calls possible which are not documented. Or it's just a feature with the generic call_service
and one has to figure out how it works ๐
One hacky way would be to search related devices based on the entity-id suffix and replace the prefix with media_player
.
For some, it would be straight forward:
Others require a wider search filter (media_player.office_tv
is associated to the Google Cast integration...)
With some luck it's possible to get the related entities with the WS API, but that will require some digging.
Well, just one more reason to replace the current HA integration with a "Remote Two integration for Home Assistant" to have full configuration access and to reduce the (very) talkative get_states
function & event subscriptions.
One step closer in linking entities of the same device:
-
Home Assistant WS API allows to call all kind of services. It's just not documented :-(
Fortunately it's open source, so we can dig into the code and find all kind of goodies!
For example the entity registry websocket functions: https://github.com/home-assistant/core/blob/2024.4.2/homeassistant/components/config/entity_registry.py#L23-L32 -
Retrieve entity registry:
{"type": "config/entity_registry/list", "id": 7}
- Response is a huge list with the complete entity registry. Filtering is not possible unfortunatately.
Snipped of the above Office TV device with 2 entities:
{
"id": 7,
"type": "result",
"success": true,
"result": [
{
"area_id": null,
"config_entry_id": "1fd39c6a519c757b9362b6e80de11477",
"device_id": "28566c0e829174e8e862fcb00727366e",
"disabled_by": null,
"entity_category": null,
"entity_id": "media_player.office_tv_2",
"platform": "androidtv_remote",
"..."
},
{
"area_id": null,
"config_entry_id": "1fd39c6a519c757b9362b6e80de11477",
"device_id": "28566c0e829174e8e862fcb00727366e",
"disabled_by": null,
"entity_category": null,
"entity_id": "remote.office_tv",
"platform": "androidtv_remote",
"..."
}
]
}
- Retrieve data from
entity_id
withconfig/entity_registry/get
{
"type": "config/entity_registry/get",
"entity_id": "remote.office_tv",
"id": 10
}
- Read
device_id
- Search related entities with
device_id
.
This seems to require reading the full list withconfig/entity_registry/list
:-( So we could already use it for step 1 and cache it. - Do some other magic based on
platform
value, e.g. expose Android TV Remote keycodes as simple commands for "androidtv_remote" or known Apple TV commands for "apple_tv". Ugly and sad having to do that, but would provide a much better user experience. Even better: merge it into the exposed media-player entity as simple commands, then we'd have keypad navigation and other features right in the Remote Two media player... - Profit!
So this would be possible, just with a bit of overhead due to missing filter options and having to deal with pretty big message responses. Going forward with a "Remote Two integration for Home Assistant" would be the better option.
Part of beta firmware release 1.7.10
Another creative way of getting the related entities of the same device: execute a template with the REST API:
curl --location 'http://homeassistant.local:8123/api/template' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer $TOKEN \
--data '{"template": "{{device_entities(device_id('\''remote.office_tv'\''))}}"}'
And back we get some non-json compatible data:
['media_player.office_tv_2', 'remote.office_tv']
But it's fragile: if the entity-id doesn't exist, the template returns some completely unrelated entities (likely the ones without a device association).
A well-typed API would be so much nicer...
Good catch, but indeed the websocket API is poor on hass and would need more APIs