cristian5th / homebridge-appletv

Configuration of pyatv and cmd4 for reading the Apple TV status in Homebridge
GNU General Public License v3.0
25 stars 2 forks source link

Power State Always On (even when off) #3

Closed roundaboutluke closed 2 years ago

roundaboutluke commented 2 years ago

Weird issue, got this running on Ubuntu with a few path changes. No errors in debug, and the switch can turn off the Apple TV (and thus turns off my TV) just fine. The Playback switch also functions fine.

However shortly afterwards it polls and receives the result that the TV is On and the Switch turns back on (which doesn't turn the TV on). Running the commands manually it always seems to return that the power is '1' even when the TV is off.

I'm not sure if this is the desired behaviour?

cristian5th commented 2 years ago

No. This is not at all the desired behavior.

I never use the switch so maybe there is a bug that I didn't notice. If you turn on your TV (only your TV), do you see the Apple TV to be actually on? Or maybe it is just an incorrect value when getting the state.

cristian5th commented 2 years ago

I wonder about the companion credentials usage.

What if you change the lines at the shell script:

if [ "${ATV_POWER_STATE}" = "PowerState.On" ]
then
    /home/pi/.local/bin/atvremote --id ${ATV_id} --companion-credentials ${companion_credentials} turn_off
else
    /home/pi/.local/bin/atvremote --id ${ATV_id} --companion-credentials ${companion_credentials} turn_on
fi

With these:

if [ "${ATV_POWER_STATE}" = "PowerState.On" ]
then
    /home/pi/.local/bin/atvremote --id ${ATV_id} --airplay-credentials ${airplay_credentials} turn_off
else
    /home/pi/.local/bin/atvremote --id ${ATV_id} --airplay-credentials ${airplay_credentials} turn_on
fi
roundaboutluke commented 2 years ago

No. This is not at all the desired behavior.

I never use the switch so maybe there is a bug that I didn't notice. If you turn on your TV (only your TV), do you see the Apple TV to be actually on? Or maybe it is just an incorrect value when getting the state.

I tried this and noted the Apple TV was not on - so believe it is just an incorrect value.

I wonder about the companion credentials usage.

What if you change the lines at the shell script:

if [ "${ATV_POWER_STATE}" = "PowerState.On" ]
then
    /home/pi/.local/bin/atvremote --id ${ATV_id} --companion-credentials ${companion_credentials} turn_off
else
    /home/pi/.local/bin/atvremote --id ${ATV_id} --companion-credentials ${companion_credentials} turn_on
fi

With these:

if [ "${ATV_POWER_STATE}" = "PowerState.On" ]
then
    /home/pi/.local/bin/atvremote --id ${ATV_id} --airplay-credentials ${airplay_credentials} turn_off
else
    /home/pi/.local/bin/atvremote --id ${ATV_id} --airplay-credentials ${airplay_credentials} turn_on
fi

This seems to exhibit the same behaviour, though the initial power off brings up the control centre menu just before it turns off.

To be fair, this doesn't actually affect my use case either - I just wanted a switch to turn off the TV set as part of my goodnight routine (why oh why can it only natively be paused through HomeKit is beyond me!) I just thought it was worth noting!

cristian5th commented 2 years ago

If your interest is more on the switch, then I suggest that you try the plugin homebridge-cmd-television by @NorthernMan54.

As what is happening is that you get an incorrect value from the shell script, it might be the atvremote application doing something wrong, but this is beyond my capabilities. Just to make sure, when you are in this state that the Apple TV is off but you get 1 as the output of the shell script, what do you get if you execute directly the atvremote command at the terminal?

/home/pi/.local/bin/atvremote --id ${ATV_id} --airplay-credentials ${airplay_credentials} power_state Replace ${ATV_id} with your Apple TV id data and ${airplay_credentials} with your AirPlay credentials. And replace also the atvremote path with the one that fits your installation.

You should get PowerState.On or PowerState.Off

roundaboutluke commented 2 years ago

If your interest is more on the switch, then I suggest that you try the plugin homebridge-cmd-television by @NorthernMan54.

As what is happening is that you get an incorrect value from the shell script, it might be the atvremote application doing something wrong, but this is beyond my capabilities. Just to make sure, when you are in this state that the Apple TV is off but you get 1 as the output of the shell script, what do you get if you execute directly the atvremote command at the terminal?

/home/pi/.local/bin/atvremote --id ${ATV_id} --airplay-credentials ${airplay_credentials} power_state Replace ${ATV_id} with your Apple TV id data and ${airplay_credentials} with your AirPlay credentials. And replace also the atvremote path with the one that fits your installation.

You should get PowerState.On or PowerState.Off

You are right - it is always returning On, even when the TV is off, I have tried with that plugins method too and experience the same thing, so definitely on the atvremote side I think, I'll report it there.

PS - chose this over homebridge-cmd-television because I already use CMD4 for a few things and I like the way it's so open - I am actually planning to expose the playback here as an occupancy sensor and control my lighting at night accordingly so thanks for the work here!

EDIT: Immediately found the culprit! https://github.com/postlund/pyatv/issues/1667 I too use Homepod's for the default Audio output. No way to fix, maybe worth a mention in the readme to save future tickets 👍