AntonioMeireles / homebridge-vieramatic

Homebridge plugin for Panasonic™ Viera™ TVs (includes support for 2018 and later models)
Apache License 2.0
43 stars 9 forks source link

TV powering off on HB restart #42

Closed WummoFTW closed 3 years ago

WummoFTW commented 3 years ago

I have Panasonic Viera TX-48AS640E TV, it doeas not support remote power on (only remote power off) and every time I restart Homebridge I need to fight with this plugin so that it would work at least moderately. By that I mean powering it on when I see power on command in log. Is there any way to disable power switching on Homebridge boot?

I am running Homebridge UI X v4.32.0 in a Docker container and my Vieramatic plugin version is v2.0.8

AntonioMeireles commented 3 years ago

@WummoFTW

currently, no there isn't. will see what i can do; stay tuned :-)

WummoFTW commented 3 years ago

Okay, can't wait for that, LIKE LEGIT CANT WAIT BECAUSE THE OTHER PLUGINS ARE CLOSE TO DEAD

AntonioMeireles commented 3 years ago

upgrade and test please the just published homebridge-vieramatic@2.0.9. Hopefully it will make the issue go away.

WummoFTW commented 3 years ago

Okay, power off on HB restart problem stopped but I get this message

[11/14/2020, 10:37:30 PM] [PanasonicVieraTV] (setPowerStatus)/-> ON - unable to power cycle TV - probably unpowered

Everything else in the log looks good, but the power states are mixed up That means when I power on tv with remote, plugin does not get this info and then if I pres power on, on Homekit TV will power off and HomeKit will show it powered on for a brief moment and then off again

Damn, there were lots of power on's and off"s I hope you understood what I was trying to say

AntonioMeireles commented 3 years ago

weird (albeit your TV set is way old). Please provide full homebridge logs, homebridge config and contents of accessories/vieramatic.json (inside homebridge config dir) so that i try to spot what's going on.

Have a great weekend!

WummoFTW commented 3 years ago

vieramatic.json file:

{
  "4D454930-0200-1000-8001-20C6EBA6B210": {
    "data": {
      "inputs": {
        "hdmi": [],
        "applications": {
          "0": {
            "name": "Apps Market",
            "id": "0387878700000062",
            "hidden": 1
          },
          "1": {
            "name": "Screen Market",
            "id": "0387878700000064",
            "hidden": 1
          },
          "2": {
            "name": "VIERA Link",
            "id": "0387878700000016",
            "hidden": 1
          },
          "3": {
            "name": "Medijos leistuvas",
            "id": "0387878700000032",
            "hidden": 1
          },
          "4": {
            "name": "Daugialypės terpės serveris",
            "id": "0387878700000014",
            "hidden": 1
          },
          "5": {
            "name": "TV gidas",
            "id": "0387878700000003",
            "hidden": 1
          },
          "6": {
            "name": "Web Browser",
            "id": "0077777700140002",
            "hidden": 1
          },
          "7": {
            "name": "YouTube",
            "id": "0070000200000001",
            "hidden": 0
          },
          "8": {
            "name": "Meteonews TV",
            "id": "0020007100000001",
            "hidden": 1
          },
          "9": {
            "name": "Digital Concert Hall",
            "id": "0076002307000001",
            "hidden": 1
          },
          "10": {
            "name": "CineTrailer",
            "id": "0020001200000001",
            "hidden": 1
          },
          "11": {
            "name": "euronews",
            "id": "0020001000000001",
            "hidden": 1
          },
          "12": {
            "name": "Deezer",
            "id": "0020007600000001",
            "hidden": 1
          },
          "13": {
            "name": "my Stream",
            "id": "0387878700000056",
            "hidden": 1
          },
          "14": {
            "name": "Vaizdo dubliav.",
            "id": "0387878700000049",
            "hidden": 1
          },
          "15": {
            "name": "Fishing TV",
            "id": "0076002006000001",
            "hidden": 1
          },
          "16": {
            "name": "Netflix",
            "id": "0010000200000001",
            "hidden": 0
          },
          "17": {
            "name": "Russia. TV and Radio",
            "id": "0020004000000001",
            "hidden": 1
          },
          "18": {
            "name": "TuneIn",
            "id": "0010001800000001",
            "hidden": 1
          },
          "19": {
            "name": "Break Comedy App",
            "id": "0010000500000001",
            "hidden": 1
          },
          "20": {
            "name": "Meniu",
            "id": "0387878700000009",
            "hidden": 1
          },
          "21": {
            "name": "TV",
            "id": "0387878700000001",
            "hidden": 0
          },
          "22": {
            "name": "Skype",
            "id": "0070000600000001",
            "hidden": 1
          },
          "23": {
            "name": "AccuWeather.com",
            "id": "0070000C00000001",
            "hidden": 1
          }
        },
        "TUNER": {
          "hidden": 0
        }
      },
      "specs": {
        "friendlyName": "Panasonic_TV",
        "modelName": "Panasonic VIErA",
        "modelNumber": "TX-48AS640E",
        "manufacturer": "Panasonic",
        "serialNumber": "[redacted]",
        "requiresEncryption": false
      }
    }
  }
}

Sorry for a messy output

AntonioMeireles commented 3 years ago

OK. thnxs!

Could you please install Panasonic's own "Panasonic TV Remote TV 3" mobile app (IOS install link and Android install link) ? and confirm that it behaves with your TV ?

WummoFTW commented 3 years ago

Yes, I can confirm that it works perfectly except that turn on incompatibility

AntonioMeireles commented 3 years ago

Your model seems to be an old one that requires WakeOnLan to start ... i know how to implement it in the general sense, mess is i do not have access to such a model, and whatever i do it shouldn't break existing functionality for the more recent models... so progress a bit conservative/slow. On the other hand, i'm struggling to understand the power states mixups between reality and plugin, which should just not happen. could you please attach here the full homebridge logs ?

WummoFTW commented 3 years ago

I cherry picked all the important outputs because it contained some personal info, but i think that will help... _[11/15/2020, 11:07:25 PM] [PanasonicVieraTV] (getVolume) unable to get volume from TV... [11/15/2020, 11:07:58 PM] [PanasonicVieraTV] (getVolume) unable to get volume from TV... [11/15/2020, 11:08:02 PM] [PanasonicVieraTV] (getVolume) unable to get volume from TV... [11/15/2020, 11:08:12 PM] Plugin /homebridge/nodemodules/homebridge-eq3ble does not contain a package.json. [11/15/2020, 11:08:12 PM] Loaded plugin: homebridge-vieramatic@2.0.10 [11/15/2020, 11:08:12 PM] Registering platform 'homebridge-vieramatic.PanasonicVieraTV' [11/15/2020, 11:08:12 PM] [PanasonicVieraTV] handling 192.168.0.206 from config.json [11/15/2020, 11:08:14 PM] [PanasonicVieraTV] IGNORING '192.168.0.206' as it is not reachable. [11/15/2020, 11:08:14 PM] [PanasonicVieraTV] Please make sure that your TV is powered ON and connected to the network.

I think you don't need to try to implement some weird power on feature, just power off and power state detection

AntonioMeireles commented 3 years ago

@WummoFTW

could you plz give a try to homebridge-vieramatic=2.0.11-beta.2 and report back? (needs to be installed manually - npm install homebridge-vieramatic=2.0.11-beta.2 as plain update won't do since i've tagged it as beta.)

Power ON/OFF detection refactored a lot. (see #43 for the gory details)

thanks for your patience

WummoFTW commented 3 years ago

Okay, this version works flawlessly, the only thing that was off was the log output:

[11/16/2020, 8:15:40 PM] [PanasonicVieraTV] (remoteControl)/(RETURN) Error: timeout of 3500ms exceeded
    at createError (/homebridge/node_modules/homebridge-vieramatic/node_modules/axios/lib/core/createError.js:16:15)
    at RedirectableRequest.handleRequestTimeout (/homebridge/node_modules/homebridge-vieramatic/node_modules/axios/lib/adapters/http.js:264:16)
    at Object.onceWrapper (events.js:421:28)
    at RedirectableRequest.emit (events.js:315:20)
    at Timeout._onTimeout (/homebridge/node_modules/homebridge-vieramatic/node_modules/follow-redirects/index.js:166:13)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7) {
  config: [Object],
  code: 'ECONNABORTED',
  request: [Writable],
  response: undefined,
  isAxiosError: true,
  toJSON: [Function: toJSON]
}

Thank you for your work and your responsiveness

AntonioMeireles commented 3 years ago

we're making progress 😃; a quick question - error above only happens when using ios' remote when tv is off right?

WummoFTW commented 3 years ago

Yup and I overlooked this log message when tv was off: [11/16/2020, 8:32:25 PM] [PanasonicVieraTV] (getVolume) unable to get volume from TV...

But in my opinion this message should be just supressed

AntonioMeireles commented 3 years ago

tricky to suppress those error messages as sometimes they matter, and those ones only happen in older models, where most of the API really disappears :/ unlike in newer ones. need to think a bit to find the right balance.

AntonioMeireles commented 3 years ago

@WummoFTW

what time zone are you on ? would you have some time for a live debug session, soon ?

Thanxs again.

WummoFTW commented 3 years ago

Hey, I saw you mentioned this issue in another thread, I have noticed it too, but in my case TV name was already what i I intended in HomeKit, so I think a quick fix would be to name the Tv to its intended name on TV settings

And for a debugging session I'm free on Saturday and my timezone is GMT+2 (Lithuania)

g30r93g commented 3 years ago

@AntonioMeireles Correct me if I'm wrong but the only reason to call unsubscribe on the UPnP Subscription here is to stop listening to updates from the TV. If you remove this, the polling timer in accessories.ts is made redundant since you will have faster updates from the TV and you may find that this issue will be resolved. The only problem that can arise is if the TV forces the expiry of all subscriptions when the TV is turned off. The package you use for UPnP node-upnp-subscription states it handles renewals so potentially it is just a matter of removing the unsubscribe line and then ensuring the retry cycle for resubscribing to the TV doesn't time out.

AntonioMeireles commented 3 years ago

@g30r93g

you touched the core of the puzzle - so far there isn't a single method that we can rely that works for ALL models specially older ones. Worst, i've just found that even for recent ones API endpoints slightly different across different geografies.

In short, main issue from my side isn't detecting if TV is on or off (with more or less tests one gets it) is to get it (always) done in a short amount of time so that HomeKit power states don't get fuzzy. In real world, people don't use only iphones to control TVs, and one think we got right - for the models it supports 100% - is close to perfect sync between HK status and tv status regardless of TV being controlled by phone of plain remote with no race conditions/whatever (and no global locks as i 've used in despair in the past).

So, at sight the issue of relying only in node-upnp-subscription is that for models where it doesn't fit handling the timeouts becomes messy. (and we can't have too short ones as we 've found to have people in noisy wireless networks with too high latency). OTOH in the meantime we really need the unsubscribe, as a safeguard, because we do know that for some oldish sets (old plasmas, old models that require WakeOnLan) currently it will just crash. what i'm trying do do, at the cost of the small extra overhead (of having the poller always reinstantiated) is to catch that crash in-place and find a way to workaround it. (see one in #39) so basically i 'd expect to end having the whole Promise here in a try/catch scheme, being that i'm yet determining both what exactly to put in the catch part and how to test it :-)

do note that the paragraph above may age badly if and only if we spot a way to grab the different way that oldish models (see here expose the X_ScreenState also from within the upnp and there are no remaining modes with aditional variations of behaviour).

Anyway, just keep the feedback coming!!! the more eyes, brains the better :-)

finally, @g30r93g many many thanks for all your hard work over the years on your side it was really the inspiration to start my humble side gig on this. [btw, what model do you have, on your side ? ;-) ]

All the best!

g30r93g commented 3 years ago

Ahh I see. The variation in model implementations are annoying, but definitely will have a good think about what other methods of grabbing X_ScreenState could be implemented.

[I have a TX-40EX700B ;-)]

AntonioMeireles commented 3 years ago

@g30r93g from here from @jerrodh we now know that oldish models have available...

<serviceStateTable>
    (...)
    <stateVariable sendEvents="yes">
      <name>X_ScreenState</name>
      <dataType>string</dataType>
    </stateVariable>
   (...)
<serviceStateTable>

question is ... how to grab / test those events :-) ... @jerrodh what time zone are you in ? available for a live debug session ?

jerrodh commented 3 years ago

I'm in USA CST: GMT-6.

Sure, we can find a way to do live debug, if my toddler and newborn (okay, wife) will permit me some time to geek out in a bunker. Perhaps this evening or tomorrow?

If we really want to get geeky, I may be able to give you temporary VPN info with direct access to my TV.

AntonioMeireles commented 3 years ago

@jerrodh

replying in #39

AntonioMeireles commented 3 years ago

regarding this specific issue @WummoFTW anything still left (as off 2.0.11) or is it all working as expected for you now ?

AntonioMeireles commented 3 years ago

regarding this specific issue @WummoFTW anything still left (as off 2.0.11) or is it all working as expected for you now ?

@jerrodh, ping

AntonioMeireles commented 3 years ago

@jerrodh may i close this ? or still room for improvement ?

jerrodh commented 3 years ago

I'm not having any additional issues currently - thanks.

AntonioMeireles commented 3 years ago

I'm not having any additional issues currently - thanks.

Closing then.

thanks again!