jsiegenthaler / homebridge-samsungtvht

Homebridge plugin for Samsung TV (D5000 series) and Home Theater (D5500 series) from ca 2011.
MIT License
13 stars 1 forks source link

Hard to reproduce - Sometimes HomeKit status gets stuck in 'ON' even when TV is off #12

Closed TheEngineerGuy closed 1 year ago

TheEngineerGuy commented 1 year ago

Describe The Bug: Hard to reproduce - Sometimes HomeKit status gets stuck in 'ON' even when TV is off.

To Reproduce: Turn TV off from remote. Sometimes, HomeKit TV status stays ON perpetually.

Expected behavior: Turn TV off from remote. HomeKit TV status changes to OFF.

Plugin Config:

            "name": "Samsung TV HT",
            "pingCommand": "ping -c 1 -w 20",
            "pingInterval": 3,
            "pingResponseOn": "received, 0% packet",
            "pingResponseOff": "received, 100% packet",
            "doublePressTime": 250,
            "triplePressTime": 450,
            "doublePressDelayTime": 300,
            "devices": [
                {
                    "name": "Samsung",
                    "ipAddress": "x.x.x.x",
                    "type": "television",
                    "manufacturer": "Samsung",
                    "modelName": "Samsung",
                    "powerOnCommand": "echo 'on 0' | cec-client -s -d 1",
                    "powerOffButton": "KEY_POWEROFF",
                    "viewTvSettingsCommand": "KEY_MENU",
                    "inputs": [
                        {
                            "inputName": "Apple TV",
                            "inputKeyCode": "KEY_AUTO_ARC_PIP_RIGHT_BOTTOM",
                            "inputSourceType": "3",
                            "inputDeviceType": "4"
                        },
                        {
                            "inputName": "TV",
                            "inputKeyCode": "KEY_TV",
                            "inputSourceType": "2",
                            "inputDeviceType": "1"
                        }
                    ],
                    "arrowUpButton": "KEY_UP",
                    "arrowUpButtonDoubleTap": "KEY_CHUP",
                    "arrowUpButtonTripleTap": "KEY_UP",
                    "arrowDownButton": "KEY_DOWN",
                    "arrowDownButtonDoubleTap": "KEY_CHDOWN",
                    "arrowDownButtonTripleTap": "KEY_DOWN",
                    "arrowLeftButton": "KEY_LEFT",
                    "arrowLeftButtonDoubleTap": "KEY_REWIND",
                    "arrowLeftButtonTripleTap": "KEY_LEFT",
                    "arrowRightButton": "KEY_RIGHT",
                    "arrowRightButtonDoubleTap": "KEY_FF",
                    "arrowRightButtonTripleTap": "KEY_RIGHT",
                    "selectButton": "KEY_ENTER",
                    "selectButtonDoubleTap": "KEY_SOURCE",
                    "selectButtonTripleTap": "KEY_HDMI",
                    "playPauseButton": "KEY_PLAY",
                    "playPauseButtonDoubleTap": "KEY_PAUSE",
                    "playPauseButtonTripleTap": "KEY_STOP",
                    "backButton": "KEY_RETURN",
                    "backButtonDoubleTap": "KEY_EXIT",
                    "backButtonTripleTap": "KEY_RETURN",
                    "infoButton": "KEY_MENU",
                    "infoButtonDoubleTap": "KEY_INFO",
                    "infoButtonTripleTap": "KEY_TOOLS",
                    "volupButton": "KEY_VOLUP",
                    "voldownButton": "KEY_VOLDOWN",
                    "voldownButtonTriplePress": "KEY_MUTE",
                    "muteButton": "KEY_MUTE"
                }
            ],
            "platform": "samsungtvht"
        }

Screenshots:

Environment:

jsiegenthaler commented 1 year ago

Hi @TheEngineerGuy The only way the plugin can determine the power state of the TV is to ping the network port. Ping response is subject to your local network topology. The ping response is parsed to see if the TVs network port is responding, indicating that the TV is on or off.

Please read also this wiki page: https://github.com/jsiegenthaler/homebridge-samsungtvht/wiki/Power-Control#detecting-current-power-state

You may also want to tune your Ping Command and Ping Interval to be more reliable on your local network

Note that a hard-wired LAN where Homebridge and the TV are on the same LAN and same segment will always work better

TheEngineerGuy commented 1 year ago

Correct. My TV isn't hardwired, and I ran packet capture on my Firewall in the middle, no ping response was being sent back by the TV. That is why I posted here :).

I don't believe it is because the status recognized is ON, it is possibly because status update to OFF is not being reflected.

I use another plugin at the same time, which reflects the state correctly.

jsiegenthaler commented 1 year ago

My plugin works as follows: If a ping response is received, the TV is deemed to be ON If no ping response is received, the TV is deemed to be OFF It's the only means of determining the power state of the TV. This is why you need to up the debugLevel and observe the ping responses. Make sure the ping response for no connection contains the string you have in the plugin config pingResponseOff field

What other plugin are you using? If it contains a different and more reliable power state detection mechanism, I'd be interested in seeing what it does.

TheEngineerGuy commented 1 year ago

I totally get this. And I am in agreement that your plugin works this way. But sometimes the status gets 'stuck at ON' per say. Not sure why.

The other plugin I use is 'https://github.com/mmende/homebridge-samsungtv-control2'

jsiegenthaler commented 1 year ago

What model TV do you have?Regards JochenSent from my iPhoneOn 15 Oct 2022, at 17:33, TheEngineerGuy @.***> wrote: I totally get this. And I am in agreement that your plugin works this way. But sometimes the status gets 'stuck at ON' per say. Not sure why. The other plugin I use is 'https://github.com/mmende/homebridge-samsungtv-control2'

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

TheEngineerGuy commented 1 year ago

2012 Samsung UNES6100F

johnnyacarter commented 1 year ago

I have a similar problem with my Samsung ES7000 which keeps toggling to ON in HomeBridge even when the TV is turned OFF

This is what the log shows when it happens

Samsung TV HT] Samsung TV LR: getInput returning input 999 [UNKNOWN] [11/17/2022, 9:07:39 AM] [Samsung TV HT] Samsung TV B1: getInput returning input 999 [UNKNOWN] [11/17/2022, 9:07:43 AM] [Samsung TV HT] Samsung TV LR: sendKey: keySequence KEY_POWEROFF [11/17/2022, 9:07:43 AM] [Samsung TV HT] Samsung TV LR: sendKey: send KEY_POWEROFF [11/17/2022, 9:08:15 AM] [Samsung TV HT] Samsung TV LR: Power changed from 0 OFF to 1 ON

jsiegenthaler commented 1 year ago

@johnnyacarter Thanks, that helps. I've also noticed some strange behavior since iOS 16. I'll spend some time on in in the next few days.

johnnyacarter commented 1 year ago

For some reason it's remaining OFF currently, but i'm getting a lot of these lines in the log

[11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV B1: getInput returning input 999 [UNKNOWN] [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV B1: getCurrentMediaState returning 2 [STOP] [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV B1: getTargetMediaState returning 2 [STOP] [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV LR: getInput returning input 999 [UNKNOWN] [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV LR: getCurrentMediaState returning 2 [STOP] [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV LR: getTargetMediaState returning 2 [STOP] [11/17/2022, 2:40:48 PM] [Sonos] Kitchen Sonos: get Remaining Duration: return 0s [11/17/2022, 2:40:48 PM] [Sonos] Library Sonos: get Remaining Duration: return 0s [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV B1: getInput returning input 999 [UNKNOWN] [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV B1: getCurrentMediaState returning 2 [STOP] [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV B1: getTargetMediaState returning 2 [STOP] [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV LR: getInput returning input 999 [UNKNOWN] [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV LR: getCurrentMediaState returning 2 [STOP] [11/17/2022, 2:40:48 PM] [Samsung TV HT] Samsung TV LR: getTargetMediaState returning 2 [STOP] [11/17/2022, 2:40:52 PM] [Sonos] Kitchen Sonos: get Remaining Duration: return 0s [11/17/2022, 2:40:52 PM] [Sonos] Library Sonos: get Remaining Duration: return 0s [11/17/2022, 2:40:52 PM] [Samsung TV HT] Samsung TV B1: getInput returning input 999 [UNKNOWN] [11/17/2022, 2:40:52 PM] [Samsung TV HT] Samsung TV B1: getCurrentMediaState returning 2 [STOP] [11/17/2022, 2:40:52 PM] [Samsung TV HT] Samsung TV B1: getTargetMediaState returning 2 [STOP] [11/17/2022, 2:40:52 PM] [Samsung TV HT] Samsung TV LR: getInput returning input 999 [UNKNOWN] [11/17/2022, 2:40:52 PM] [Samsung TV HT] Samsung TV LR: getCurrentMediaState returning 2 [STOP] [11/17/2022, 2:40:52 PM] [Samsung TV HT] Samsung TV LR: getTargetMediaState returning 2 [STOP]

jsiegenthaler commented 1 year ago

@johnnyacarter I think I'll modify the ping response. At the moment it relies on 0% loss for ON, and 100% loss for OFF. Any ping response which is between 0% and 100% does not get evaluated. I plan to change it to 100% loss = OFF, anything else showing at least one ping response was received = ON

jsiegenthaler commented 1 year ago

@johnnyacarter, @TheEngineerGuy I've made the changes, documented in this branch: https://github.com/jsiegenthaler/homebridge-samsungtvht/tree/Improve-PowerStateMonitor

I have released v0.1.24-beta.1 I would appreciate it if you could install it, try it for a few days, and let me know if detection of the power state is more stable

johnnyacarter commented 1 year ago

@johnnyacarter, @TheEngineerGuy I've made the changes, documented in this branch:

https://github.com/jsiegenthaler/homebridge-samsungtvht/tree/Improve-PowerStateMonitor

I have released v0.1.24-beta.1

I would appreciate it if you could install it, try it for a few days, and let me know if detection of the power state is more stable

I have installed v0.1.24-beta.1, seems to be working but still getting these lines in the log

getInput returning input 999 [UNKNOWN]

jsiegenthaler commented 1 year ago

Hi @johnnyacarter : "getInput returning input 999 [UNKNOWN]" is behaviour by design when the plugin debugLevel is >0. Set debugLevel to None in the plugin settings, or "debugLevel": 0, in the config.json. Then restart Homebridge and those debug messages will no longer appear in the log.

jsiegenthaler commented 1 year ago

The reason getinput always returns UNKNOWN is that te plugin has no means of requesting the current state of the TV, and thus never knows which Input the TV is set to (HDMI1, HDMI2, etc)

TheEngineerGuy commented 1 year ago

Good find!! Seems to be working fine now. Closing the issue. Thanks @jsiegenthaler .

In my view, this plugin is perfect now.

johnnyacarter commented 1 year ago

It’s still doing it, after a restart of Homebridge, the Samsung ES7000 TV is ON when it is actually OFF. My second Samsung ES6540 TV ES6540 is reporting OFF. Both TV’s are set up the same

On 22 Nov 2022, at 02:19, TheEngineerGuy @.***> wrote:

 Closed #12 as completed.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

jsiegenthaler commented 1 year ago

Hi @johnnyacarter Happy to help further, but I do need logs. Please put Homebridge in debug mode, and restart. Make sure that your observed issue is produced. If not, truncate the log, do another restart, and observe again. Once you see the issue occurring, send me the log file by email (insert a g between j and s of my username and use that well known email service starting with g)

johnnyacarter commented 1 year ago

HB-Log.log

Here is a section of the log, I turned the TV OFF on IOS Home at 10:40 and it then later turned its self back ON, I then repeated it again at 10:43

johnnyacarter commented 1 year ago

I have worked out why my Samsung TV flipped to "ON" in the plugin in homebridge. In the TV settings under system there is a preference for auto update firmware in standby mode, if you turn this off the plugin won't get successful ping request and then assumes the TV is on. Hope this helps someone out there

jsiegenthaler commented 1 year ago

Thanks for the feedback. That confirms it is not a plugin issue at all. I'll close the issue.