home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.11k stars 29.79k forks source link

media_player.play_media no longer works after 2024.8.0 #123801

Open talondnb opened 4 weeks ago

talondnb commented 4 weeks ago

The problem

After 2024.8.0 (and also now on 2024.8.1), media_player no longer plays a locally hosted file (either through url or locally stored media:

Automations

automation:
# Adhan
  - alias: Adhan
    trigger:
    - platform: state
      entity_id: sensor.salah_actual
      to:
      - Fajr
      - Dhuhr
      - Asr
      - Maghrib
      - Isha
    action:
    - action: notify.ios_all
      data:
        message: "It is {{ states.sensor.salah_actual.state }} time, please perform wudhu."
    - action: media_player.media_pause
      target:
        entity_id:
          - media_player.android
          - media_player.shield
    - action: switch.turn_on
      target:
        entity_id: switch.pc_mute
    - action: media_player.volume_set
      target:
        entity_id: media_player.living_room_speaker
      data:
        volume_level: 0.6
    - action: media_player.play_media
      data:
        media_content_id: "http://10.10.1.200:8123/local/adhan-{{'fajr' if trigger.to_state.state == 'Fajr' else 'main'}}.mp3"
        media_content_type: music
      target:
        entity_id:
          - media_player.living_room_speaker
          - media_player.bedroom

What version of Home Assistant Core has the issue?

2024.8.1

What was the last working version of Home Assistant Core?

2024.7.x

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Automation

Link to integration documentation on our website

https://www.home-assistant.io/integrations/media_player/

Diagnostics information

No response

Example YAML snippet

# Automations
automation:
# Adhan
  - alias: Adhan
    trigger:
    - platform: state
      entity_id: sensor.salah_actual
      to:
      - Fajr
      - Dhuhr
      - Asr
      - Maghrib
      - Isha
    action:
    - action: notify.ios_all
      data:
        message: "It is {{ states.sensor.salah_actual.state }} time, please perform wudhu."
    - action: media_player.media_pause
      target:
        entity_id:
          - media_player.android
          - media_player.shield
    - action: switch.turn_on
      target:
        entity_id: switch.pc_mute
    - action: media_player.volume_set
      target:
        entity_id: media_player.living_room_speaker
      data:
        volume_level: 0.6
    - action: media_player.play_media
      data:
        media_content_id: "http://10.10.1.200:8123/local/adhan-{{'fajr' if trigger.to_state.state == 'Fajr' else 'main'}}.mp3"
        media_content_type: music
      target:
        entity_id:
          - media_player.living_room_speaker
          - media_player.bedroom

Anything in the logs that might be useful for us?

No response

Additional information

I've also tried using the following:

media_content_id: "media-source://media_source/local/adhan-{{'fajr' if trigger.to_state.state == 'Fajr' else 'main'}}.mp3"

home-assistant[bot] commented 4 weeks ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (media_player) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `media_player` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign media_player` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


media_player documentation media_player source (message by IssueLinks)

mib1185 commented 4 weeks ago

please provide the log file, thx :+1:

talondnb commented 4 weeks ago

please provide the log file, thx 👍

2024-08-13 18:46:06.055 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/google_assistant/report_state.py", line 129, in _async_entity_state_listener if not checker.async_is_significant_change(new_state, extra_arg=entity_data): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/significant_change.py", line 234, in async_is_significant_change result = check_significantly_changed( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/media_player/significant_change.py", line 45, in async_check_significant_change old_attrs_s = set( ^^^^ TypeError: unhashable type: 'dict' 2024-08-13 18:46:06.650 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'to_state' when rendering 'http://10.10.1.200:8123/local/adhan-{{'fajr' if trigger.to_state.state == 'Fajr' else 'main'}}.mp3' 2024-08-13 18:46:06.651 ERROR (MainThread) [homeassistant.components.automation.adhan] Adhan: Error executing script. Error for call_service at pos 5: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state' 2024-08-13 18:46:06.658 ERROR (MainThread) [homeassistant.components.automation.adhan] Error while executing automation automation.adhan: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'

I'm not sure if this is going to be accurate as it waits for a particular state to be achieved, but standby and i'll post the log from an actual event instead of a manual trigger.

talondnb commented 4 weeks ago

Oddly, at the correct time it has now played fine. Closing for now, will reopen if required.

talondnb commented 4 weeks ago

So it appears to be sporadic:

2024-08-14 15:26:45.991 ERROR (MainThread) [homeassistant.components.automation.adhan] Adhan: Error executing script. Error for call_service at pos 2: CastMediaPlayerEntity.media_pause Failed: Failed to execute pause. 2024-08-14 15:26:45.995 ERROR (MainThread) [homeassistant.components.automation.adhan] Error while executing automation automation.adhan: CastMediaPlayerEntity.media_pause Failed: Failed to execute pause. 2024-08-14 15:26:48.268 ERROR (MainThread) [homeassistant.components.automation.adhan] Adhan: Error executing script. Error for call_service at pos 2: CastMediaPlayerEntity.media_pause Failed: Failed to execute pause. 2024-08-14 15:26:48.271 ERROR (MainThread) [homeassistant.components.automation.adhan] Error while executing automation automation.adhan: CastMediaPlayerEntity.media_pause Failed: Failed to execute pause.

I'm now wondering if there's a dependency on this section to have active media_players before the automation would be successful?

- action: media_player.media_pause
  target:
    entity_id:
      - media_player.android
      - media_player.shield

This wasn't the case previously when running as services, I'll try revert to services again instead of using the actions syntax.

talondnb commented 4 weeks ago

Reverting to service instead of action made no difference.

mib1185 commented 4 weeks ago

Stil, please provide the log file as requested in https://github.com/home-assistant/core/issues/123801#issuecomment-2285940547 (not only some parts of it) Further, which integration(s) provide the media player entities?

talondnb commented 4 weeks ago

home-assistant_2024-08-14T07-50-04.853Z.log

The media_player entities are a combination of Kodi and Google Cast. I've stripped the play_media action to only kodi for now but makes no difference. As mentioned, this all worked fine prior to 2024.8.0.

I'm now exploring using if/then/else in the play_media action, will post results.

mib1185 commented 4 weeks ago

home-assistant_2024-08-14T07-50-04.853Z.log

Is it still the same automation code, as on your initial post?

This error message indicates, that the trigger was not a valid state trigger:

[homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'to_state' when rendering 'http://10.10.1.200:8123/local/adhan-{{'fajr' if trigger.to_state.state == 'Fajr' else 'main'}}.mp3'

How was the automation triggered which is shown in this log file? If you triggered in manually, than the error is expected - we need to wait, until the error occurs on its own or you overwrite the state of sensor.salah_actual via the dev tools states tab manuelly, so the automation is triggered.

talondnb commented 4 weeks ago

home-assistant_2024-08-14T07-50-04.853Z.log

Is it still the same automation code, as on your initial post?

This error message indicates, that the trigger was not a valid state trigger:

[homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'to_state' when rendering 'http://10.10.1.200:8123/local/adhan-{{'fajr' if trigger.to_state.state == 'Fajr' else 'main'}}.mp3'

How was the automation triggered which is shown in this log file? If you triggered in manually, than the error is expected - we need to wait, until the error occurs on its own or you overwrite the state of sensor.salah_actual via the dev tools states tab manuelly, so the automation is triggered.

Yes, so with the actual automation trigger occurring, the playback of audio didn’t work. Manually triggering I understand won’t work but it seems as though it’s sporadic at this point.

it seems as though the new automation action doesn’t like JSON or something, no error appears in the log when the event triggers.

talondnb commented 4 weeks ago

Testing with the below automation seems to be working OK so far. It's not ideal though.

automation:
  - alias: Adhan
    trigger:
    - platform: state
      entity_id: sensor.salah_actual
      to:
      - Fajr
      - Dhuhr
      - Asr
      - Maghrib
      - Isha
    action:
    - service: notify.ios_all
      data:
        message: "It is {{ states.sensor.salah_actual.state }} time, please perform wudhu."
    - service: media_player.media_pause
      target:
        entity_id: media_player.android
    - service: switch.turn_on
      target:
        entity_id: switch.pc_mute
    - service: media_player.volume_set
      target:
        entity_id: media_player.living_room_speaker
      data:
        volume_level: 0.6
    - if:
        - condition: state
          entity_id: sensor.salah_actual
          state: "Fajr"
      then:
        - service: media_player.play_media
          data:
            media_content_id: "http://10.10.1.200:8123/local/adhan-fajr.mp3"
            media_content_type: music
          target:
            entity_id:
              - media_player.living_room_speaker
              - media_player.denzel_bedroom
      else:
        - service: media_player.play_media
          data:
            media_content_id: "http://10.10.1.200:8123/local/adhan-main.mp3"
            media_content_type: music
          target:
            entity_id:
              - media_player.living_room_speaker
              - media_player.denzel_bedroom
issue-triage-workflows[bot] commented 2 weeks ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

talondnb commented 2 weeks ago

Testing with the below automation seems to be working OK so far. It's not ideal though.

automation:
  - alias: Adhan
    trigger:
    - platform: state
      entity_id: sensor.salah_actual
      to:
      - Fajr
      - Dhuhr
      - Asr
      - Maghrib
      - Isha
    action:
    - service: notify.ios_all
      data:
        message: "It is {{ states.sensor.salah_actual.state }} time, please perform wudhu."
    - service: media_player.media_pause
      target:
        entity_id: media_player.android
    - service: switch.turn_on
      target:
        entity_id: switch.pc_mute
    - service: media_player.volume_set
      target:
        entity_id: media_player.living_room_speaker
      data:
        volume_level: 0.6
    - if:
        - condition: state
          entity_id: sensor.salah_actual
          state: "Fajr"
      then:
        - service: media_player.play_media
          data:
            media_content_id: "http://10.10.1.200:8123/local/adhan-fajr.mp3"
            media_content_type: music
          target:
            entity_id:
              - media_player.living_room_speaker
              - media_player.denzel_bedroom
      else:
        - service: media_player.play_media
          data:
            media_content_id: "http://10.10.1.200:8123/local/adhan-main.mp3"
            media_content_type: music
          target:
            entity_id:
              - media_player.living_room_speaker
              - media_player.denzel_bedroom

This has fixed my issue but indicates there was some change in the way jinja templating is handled within automations prior to 2024.8.0 versions.

issue-triage-workflows[bot] commented 11 hours ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.