Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When powering on state switches to "inactive" instead "on" #135

Open
kender65 opened this issue Feb 13, 2023 · 8 comments
Open

When powering on state switches to "inactive" instead "on" #135

kender65 opened this issue Feb 13, 2023 · 8 comments

Comments

@kender65
Copy link

Describe the bug
I'm relatively new to HA and I was happy to find a custom integration for my RX-V671 AVR.

After the initial integration everything looked fine for me. Playing around a little bit and setting up an automation where I wanted to use the state as a trigger then showed that the state for both zones Main and Zones 2 changed from "off" to "inactive" instead "off" to "on".
Behavior is independent from powering on the AVR with Yamaha WebUI, Android App, Pushbutton on the front of the AVR or using Homeassistant Media Control Card.

It's not possible to use the state change to "on" in an automation, because state changes unexpectedly to "inactive".

Steps to reproduce the behavior:

  1. Go to Media Control Card
  2. Click on "Power button" to turn zone or system power on
  3. Go to details of device
  4. See error
    image

Powering it off shows expected state "off"
image

Standard integration shows expected and correct state for "on" and "off"
image

image

HA has been restarted several times since integration was set up.

Diagnostics
Anonymized the serial_url...
config_entry-yamaha_ynca-78bf481c90a5a6cffc8990660c186983.json (1).txt

Home Assistant version information:

  • Version 2023.2.3
@mvdwetering
Copy link
Owner

The states for the mediaplayer in Home Assistant are a bit complicated, unfortunately there is more than just On and Off.

In the past I used to have On, but there were issues with that when selecting sources that could actually do playback, like NetRadio or Spotify so I revered back to using Idle.

I see that the Home Assistant Yamaha integration seems to indicate On for inputs like HDMI, but Idle for inputs like NetRadio. I could add that, but not sure if that is the correct way to do it. Building automations on the On state would then still break if you happend to have a playable source selected.

In my opinion Idle, Playing, Paused and On are all variants of On, but is not how Home Assistant treats it.
I need to ask around a bit to see what the intended way to handle this in Home Assistant is before I change stuff.

Meanwhile, would it be possible to reverse the logic? So check on "not Off" as that would cover all the other states.

@kender65
Copy link
Author

Thanks for your quick reply!

I get your point that handling this AVR and the media player in HA is a bit confusing.
The "off" state of the AVR is not really "off", it is more like "standby"; powering it "on" could / should result in different states depending on the source, playable or not.

A Node-Red package handles it that way: "on" or "standby"; there's no distinction between playable or not playable sources.
At least I have not seen any differentiation because I've never used a playable source

Until I tried "to get smart" for me it was only "on" or "off";

I have modified your suggestion a bit and use the state change "from Off"... so it doesn't matter which state it changes to...
Additionally I check the input source and everything works fine for me (right now ;-) )

@mvdwetering
Copy link
Owner

Glad you found a way to get it working for now 👍

I want to look more into the mediaplayer states at some point, but not a lot of time for that now.

@grahamw72
Copy link

This works for my system by capturing all the different states of “on” regardless of selected source.


switch:
  - platform: template
    switches:
      yamaha_amp_power:
        unique_id: "yamaha_zone1_power_switch"
        icon_template: mdi:numeric-1-box
        value_template: >
          {% if states('media_player.rxv1085') in ['on', 'idle', 'playing', 'paused', 'unavailable'] %}
            on
          {% else %}
            off
          {% endif %}
        turn_on:
          service: media_player.turn_on
          target:
            entity_id: media_player.rxv1085
        turn_off:
          service: media_player.turn_off
          target:
            entity_id: media_player.rxv1085

@raptile
Copy link

raptile commented Jul 20, 2024

[quote]Meanwhile, would it be possible to reverse the logic? So check on "not Off" as that would cover all the other states.[/quote]

Is it possible to do something like this in tiles?
image

@raptile
Copy link

raptile commented Jul 21, 2024

I managed to get it working by creating a "switch" in the configuration yaml.

switch:
  - platform: template
    switches:
      versterker:
        friendly_name: "Versterker"
        value_template: >
          {% if is_state('media_player.rx_a3030_main', 'inactive') or
                is_state('media_player.rx_a3030_main', 'on') or
                is_state('media_player.rx_a3030_main', 'idle') or
                is_state('media_player.rx_a3030_main', 'playing') or
                is_state('media_player.rx_a3030_main', 'paused') %}
            true
          {% else %}
            false
          {% endif %}
        turn_on:
          service: media_player.turn_on
          target:
            entity_id: media_player.rx_a3030_main
        turn_off:
          service: media_player.turn_off
          target:
            entity_id: media_player.rx_a3030_main

And used it in the tile.
The color was orange when it was turned on and i wanted it to stay blue so i had to set that as well.

type: tile
entity: switch.versterker
tap_action:
  action: toggle
icon_tap_action:
  action: toggle
name: Versterker
hide_state: false
icon: mdi:audio-video
color: blue

@slyoldfox
Copy link

Wanted to add to this issue by telling I was first confused when my receiver wasn't turning off when I clicked the power button on the card. First read through this thread and then came up with the following automation:

alias: "RX-A2010: toggle"
description: ""
triggers:
  - trigger: event
    event_type: call_service
    event_data:
      domain: media_player
      service: toggle
      service_data:
        entity_id: media_player.rx_a2010_main
conditions: []
actions:
  - if:
      - condition: state
        entity_id: media_player.rx_a2010_main
        state:
          - "on"
          - idle
    then:
      - action: media_player.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: media_player.rx_a2010_main
mode: single

It was only later that I realised that it was a feature of the card itself.
I use https://github.com/kalkih/mini-media-player and it has an option toggle_power which is default true (and calls toggle on media_player)

Once you set toggle_power: false on that card it would work as expected.

@mvdwetering
Copy link
Owner

Yeah, the toggle doesn't turn it Off when in Idle. In my opinion this is a bug in Home Assistant, it also happens with other media_players that use Idle state see home-assistant/core#77412

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants