tavicu / homebridge-samsung-tizen

Homebridge plugin for Samsung TV's with Tizen OS
MIT License
647 stars 87 forks source link

Samsung QE75Q80T Home app icon turns to off immediately after using the accessory #417

Closed tzclucian closed 2 years ago

tzclucian commented 2 years ago

Hello @tavicu

Running 5.1.0. The TV powers on for couple of seconds then in Homekit the TV icon immediately shows it's off altough the TV is on.

I've tried starting from scratch and even updating the accessories config file by myself but this keeps happening.

Any hints?

PS: My api info includes a powerstate: on field. Model: QE75Q80TATXXH

I also get this logs when restarting Homebridge

Starting to advertise 'Homebridge E0FC 869C' using bonjour-hap backend!
[10/6/2021, 1:05:43 PM] Homebridge v1.3.4 (Homebridge E0FC) is running on port 51449.
Preparing Advertiser for 'TV 9D48' using bonjour-hap backend!
Starting to advertise 'TV 9D48' using bonjour-hap backend!
[10/6/2021, 1:05:43 PM] TV 9D48 is running on port 56244.
[10/6/2021, 1:05:43 PM] Please add [TV 9D48] manually in Home app. Setup Code: 936-45-292
[10/6/2021, 1:06:15 PM] [TV] TV is offline
tavicu commented 2 years ago

Everything you posted is ok until the last line. Does that line appears when you click to make an action or just appears on the console?

tzclucian commented 2 years ago

Nope, it simply appears after a while no matter whether I use the TV or the Home app.

If I enable "List Apps" that line pops up even faster.

tavicu commented 2 years ago

Ok. Please start homebridge in debug mode homebridge -D so we will get more informations regarding what is happening.

Are you sure your IP is ok in the config and also the device you are running homebridge on it's in the same network as the TV?

Because from what you tell me until now looks like the plugin can't reach the TV. Since the TV powers on when you request it means that the MAC address is ok and the TV is in the same network. So more indications that the IP address it's not correct in config.

tzclucian commented 2 years ago

Done.

Yes, that's why it seemed weird to me as well.

The TV is paired. I've clicked allow and all the settings under Device Connection Manager are set to allowed.

Access Notifications is set to off.

Preparing Advertiser for 'Living Room TV 9D48' using bonjour-hap backend!
Starting to advertise 'Living Room TV 9D48' using bonjour-hap backend!
[10/6/2021, 1:15:46 PM] Living Room TV 9D48 is running on port 56788.
[10/6/2021, 1:15:46 PM] Please add [Living Room TV 9D48] manually in Home app. Setup Code: 936-45-292
[10/6/2021, 1:16:00 PM] [Living Room TV] [DEBUG] TV is offline
[10/6/2021, 1:16:05 PM] [Living Room TV] [DEBUG] TV is offline
[10/6/2021, 1:16:10 PM] [Living Room TV] [DEBUG] TV is offline
[10/6/2021, 1:16:10 PM] [Living Room TV] Failed to pair! Make sure TV is online and you click "Allow" on the popup
[10/6/2021, 1:16:10 PM] [Living Room TV] [DEBUG] PairFailedError: Failed to pair! Make sure TV is online and you click "Allow" on the popup

This is what I was saying about the app listing. It happens immediately after I start the TV via the home app (therefor the IP and the MAC are good...?)

[10/6/2021, 1:25:24 PM] Please add [Living Room TV 9D48] manually in Home app. Setup Code: 936-45-292
[10/6/2021, 1:25:32 PM] [Living Room TV] TV is offline! Can't get installed apps!
[10/6/2021, 1:25:32 PM] [Living Room TV] [DEBUG] TvOfflineError: TV is offline! Can't get installed apps!

The icon always turns to off if I try to use one of the inputs: e.g. The Netflix app. I found this error in the logs

[10/6/2021, 1:26:51 PM] [Living Room TV] Opening handshake has timed out
[10/6/2021, 1:26:51 PM] [Living Room TV] [DEBUG] SocketOpenError: Opening handshake has timed out
tavicu commented 2 years ago

Are you able to open this url? http://TV_IP:8001/api/v2/, replace TV_IP with your ip from config

Everything you are showing me indicates that the homebridge server can't access the IP address of TV.

  1. Pair-ing is failing cause the plugin can't reach the IP
  2. Can't get the installing apps because of the same problem
  3. Can't send commands cause the plugin can't reach socket of TV on that IP address
tzclucian commented 2 years ago

Yes.

Removed the screenshots.

tavicu commented 2 years ago

Ok, i will ask you to change some things on a js file if you are comfortable with this. It will indicates what is failing to check. Unfortunately i don't have any debug here yet so it's the only way.

We will have to edit this file: /lib/methods/base.js Example: https://github.com/tavicu/homebridge-samsung-tizen/blob/master/lib/methods/base.js

  1. getStatePing function at line 50 From:

    getStatePing() {
        return isPortReachable(8001, {
            host: this.ip,
            timeout: this.timeout
        });
    }

    To:

    getStatePing() {
        return isPortReachable(8001, {
            host: this.ip,
            timeout: this.timeout
        }).then((data) => { 
            console.log('ping', data); 
            return data;
        });
    }
  2. getStateHttp on line 64 From:

    getStateHttp() {
        return this.getInfo().then(data => {
            if (data.device && data.device.PowerState) {
                return data.device.PowerState == 'on';
            }
    
            return true;
        })
        .catch(() => false);
    }

    To:

    getStateHttp() {
        return this.getInfo().then(data => {
            console.log('http', data);
    
            if (data.device && data.device.PowerState) {
                return data.device.PowerState == 'on';
            }
    
            return true;
        })
        .catch((e) => {
            console.log('http catch', e);
            return false;
        });
    }

After that restart homebridge server and let's see what and why is failing to see that TV is online. Also, make sure your TV is on :))

tzclucian commented 2 years ago

I'm a programmer myself so that should be ok.

I'll reply soon with the updates.

Thank you so much for your help.

tzclucian commented 2 years ago

The Homebridge is installed as a service on a Mac.

[10/6/2021, 1:55:23 PM] Please add [Living Room TV 9D48] manually in Home app. Setup Code: 936-45-292
ping false
ping false
ping true
ping true
http catch AbortError: The user aborted a request.
    at abort (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/node-fetch/lib/index.js:1440:16)
    at AbortSignal.abortAndFinalize (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/node-fetch/lib/index.js:1455:4)
    at AbortSignal.dispatchEvent (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/event-target-shim/src/event-target.mjs:337:35)
    at abortSignal (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/abort-controller/src/abort-signal.ts:68:12)
    at AbortController.abort (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/abort-controller/src/abort-controller.ts:26:9)
    at Timeout._onTimeout (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/timeout-signal/index.js:15:14)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  type: 'aborted'
}
[10/6/2021, 1:55:33 PM] [Living Room TV] TV is offline! Can't get installed apps!
[10/6/2021, 1:55:33 PM] [Living Room TV] [DEBUG] TvOfflineError: TV is offline! Can't get installed apps!
    at WebSocketSecure.getApplications (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/lib/methods/ws.js:55:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
ping true
http catch AbortError: The user aborted a request.
    at abort (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/node-fetch/lib/index.js:1440:16)
    at AbortSignal.abortAndFinalize (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/node-fetch/lib/index.js:1455:4)
    at AbortSignal.dispatchEvent (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/event-target-shim/src/event-target.mjs:337:35)
    at abortSignal (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/abort-controller/src/abort-signal.ts:68:12)
    at AbortController.abort (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/abort-controller/src/abort-controller.ts:26:9)
    at Timeout._onTimeout (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/timeout-signal/index.js:15:14)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  type: 'aborted'
}
ping true
http catch AbortError: The user aborted a request.
    at abort (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/node-fetch/lib/index.js:1440:16)
    at AbortSignal.abortAndFinalize (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/node-fetch/lib/index.js:1455:4)
    at AbortSignal.dispatchEvent (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/event-target-shim/src/event-target.mjs:337:35)
    at abortSignal (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/abort-controller/src/abort-signal.ts:68:12)
    at AbortController.abort (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/abort-controller/src/abort-controller.ts:26:9)
    at Timeout._onTimeout (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/timeout-signal/index.js:15:14)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  type: 'aborted'
}
ping true
http catch AbortError: The user aborted a request.
    at abort (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/node-fetch/lib/index.js:1440:16)
    at AbortSignal.abortAndFinalize (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/node-fetch/lib/index.js:1455:4)
    at AbortSignal.dispatchEvent (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/event-target-shim/src/event-target.mjs:337:35)
    at abortSignal (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/abort-controller/src/abort-signal.ts:68:12)
    at AbortController.abort (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/abort-controller/src/abort-controller.ts:26:9)
    at Timeout._onTimeout (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/timeout-signal/index.js:15:14)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  type: 'aborted'
}
ping true
http catch AbortError: The user aborted a request.
    at abort (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/node-fetch/lib/index.js:1440:16)
    at AbortSignal.abortAndFinalize (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/node-fetch/lib/index.js:1455:4)
    at AbortSignal.dispatchEvent (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/event-target-shim/src/event-target.mjs:337:35)
    at abortSignal (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/abort-controller/src/abort-signal.ts:68:12)
    at AbortController.abort (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/abort-controller/src/abort-controller.ts:26:9)
    at Timeout._onTimeout (/Users/hiddenusername/.nvm/versions/node/v16.4.2/lib/node_modules/homebridge-samsung-tizen/node_modules/timeout-signal/index.js:15:14)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  type: 'aborted'
}
ping true
tavicu commented 2 years ago

Ok, so ping it's ok but the request to http is taking too long and gets cancelled. The timeout is set to 250ms and it's configurable.

Let's change it to 1500ms and see the results. Example how to change it:

{
    "platform": "SamsungTizen",
    "devices": [
        {
            "name": "Bedroom TV",
            "ip": "10.20.30.40",
            "mac": "A0:B1:C2:D3:E4:F5",
            "timeout": 1500
        }
    ]
}

After you change it restart homebridge instance.

tzclucian commented 2 years ago

It started to work much better but the same error still happens from time to time. Should I further increase the timeout?

Also, it seems the inputs will not change. e.g. from Netflid to Apple TV and so on...

It seems only: 111299001912 - YouTube works.

tavicu commented 2 years ago

Try to hard reboot your TV by pressing power button on the remote until the samsung logo appears. Wait for a few minutes (2-3) for TV to settle (it's responding very hard at the beginning until it loads everything) then restart the homebridge server.

That request should open in a few ms. So increasing the timeout it's not an option cause it will delay everything in the flow.

tavicu commented 2 years ago

I knew for sure i already followed all the steps to diagnose this in another issue. This is the issue: https://github.com/tavicu/homebridge-samsung-tizen/issues/324

You could look over there especially starting with this comment: https://github.com/tavicu/homebridge-samsung-tizen/issues/324#issuecomment-804746398

As you could se the request should take ~7ms to respond.

In the end his problem was with the machine it was running homebridge on and not the TV itself.

So first let's see how the curl command responds and will see from there what steps to follow

tzclucian commented 2 years ago

@tavicu it seems that after tuning the timeout the behaviour is ok.

Thank you very much for helping out with this issue. From my side, you can close it.

The average curl response for me was about 33ms.

tavicu commented 2 years ago

Awesome. Glad to see it's ok now :)