mvdwetering / yamaha_ynca

Custom integration for Home Assistant to support Yamaha AV receivers with the YNCA protocol (serial and network).
Apache License 2.0
39 stars 4 forks source link

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

Open kender65 opened 1 year ago

kender65 commented 1 year ago

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:

mvdwetering commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 3 months ago

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 commented 1 month ago

[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 commented 1 month ago

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