Hm… one step closer, seems that as @petro suggested adding custom event section might be solution… but yet automation does not register, with conversation service call error. Here is the full code for this automation (it is a bit more complex, as it serves several different media_players at the same time, so I had to use some additional variables):
- id: 'update_media_info'
alias: Update Media Info
initial_state: true
variables:
player: >-
{{ trigger.entity_id }}
artist: >-
{% set string=trigger.entity_id %}
{% set result=state_attr(string, 'media_artist') %}
{{ result }}
album: >-
{% set string=trigger.entity_id %}
{% set result=state_attr(string, 'media_album_name') %}
{{ result }}
output: >-
{% set string=trigger.entity_id %}
{% set string=string.split('.') %}
{% set result="input_text." + string[1] + "_media_info" %}
{{ result }}
trigger:
- platform: state
entity_id:
- media_player.audiocast
- media_player.denon_heos_s750h
- media_player.marantz_sacd30n
- media_player.volumio_2
attribute: media_album_name
condition: []
action:
- service: conversation.process
data:
agent_id: 9194fb3fee4a1e2220e2f47a524fce92
text: Tell me about {{ artist }}'s album {{ album }} in less than 100 words
response_variable: chatgpt
event: >-
{{ trigger.entity_id }}_response
event_data:
response: "{{chatgpt.response.speech.plain.speech | trim | replace('\"','')}}"
Error I receive in the log seems to be related to actual service call, so this part:
action:
- service: conversation.process
data:
agent_id: 9794fb3fee4a1e2220e2f47a524fce93
text: Tell me about {{ artist }}'s album {{ album }} in less than 100 words
response_variable: chatgpt
And error itself:
2023-07-08 16:44:49.635 ERROR (MainThread) [homeassistant.components.automation] Automation with alias 'Update Media Info' could not be validated and has been disabled: extra keys not allowed @ data['action'][0]['data']. Got {'agent_id': '9194fb3fee4a1e2220e2f47a524fce92', 'text': "Tell me about {{ artist }}'s album {{ album }} in less than 100 words"}
extra keys not allowed @ data['action'][0]['response_variable']. Got 'chatgpt'
extra keys not allowed @ data['action'][0]['service']. Got 'conversation.process'
Configuration check does not indicate any errors. Error appears when the automation is executed.
Then the sensor to consume response looks like (for one of media players, volumio_2 inthis case):
template:
- trigger:
- platform: event
event_type: media_player.volumio_2_response
- platform: state
entity_id:
- media_player.volumio_2
attribute: media_title
sensor:
- name: volumio_2_album_description
state: 'on'
attributes:
album_description: >
{% if trigger.platform == 'event' %}
{{ trigger.event.data.response }}
{% else %}
{{ this.attributes.album_description | default('') }}
{% endif %}
album_title: "{{ state_attr('media_player.volumio_2', 'media_album_name') }}"
artist_name: "{{ state_attr('media_player.volumio_2', 'media_artist') }}"
song_title: "{{ state_attr('media_player.volumio_2', 'media_title') }}"
album_art: "{{ state_attr('media_player.volumio_2', 'entity_picture') }}"
But yet to be tested, as is not triggered due to error in automation…