dbuezas / lovelace-plotly-graph-card

Highly customisable Lovelace card to plot interactive graphs. Brings scrolling, zooming, and much more!
383 stars 17 forks source link

Error if HA port is changed from 8123 #288

Closed tomtom13 closed 1 year ago

tomtom13 commented 1 year ago

Describe the bug Experiencing rather bizzare bug in plotly if HA interface is not run on default 8123 port. From safari and chrome console I can gather that there is an unhandled exception in "promise":

2plotly-graph-card.js?hacstag=413812496333:2224 Uncaught (in promise) Error: Card didn't load at plotly-graph-card.js?hacstag=413812496333:2224:2402 at async GN.plot (plotly-graph-card.js?hacstag=413812496333:2224:2193)

That results in whole page layout being screwed up. I attach a code leading to it, that is navigated to when hitting the error in dev console:

            this._plot = OEe(async()=>{
                var p, m;
                if (this.pausedRendering)
                    return;
                let r = this.fetchScheduled;
                this.fetchScheduled = !1;
                let n = 0;
                for (; !(this.config && this.hass && this.isConnected); ) {
                    if (n++ > 50)
                        throw new Error("Card didn't load");

Screenshots If applicable, add screenshots to help explain your problem.

yaml I've removed all the graphs and tried the most basic 2h temp graphs - still same results.

Additional context So, if I run HASS from default port, everything seems to be running normal. When I switch it over to SSL - things fail. If I don't switch it to SSL, but pump trafic through HAproxy - things fail. There is a small caveat here: layout completelly implodes under safari, while under chrome just scrolling on HASS pages seems to be non functioning anymore (things like zigbee2mqtt seem to work OK, but then I don't see the plotly java part loading in the console soooooo ... )

dbuezas commented 1 year ago

H! This card doesn't specify the connection port, it only talks to HA through the API object provided by Home Assistant itself. https://github.com/dbuezas/lovelace-plotly-graph-card/blob/master/src/cache/fetch-states.ts#L28

Does any other plotting library work in your setup? (E.g ApexCharts or HistoryExplorer).

tomtom13 commented 1 year ago

@dbuezas Thanks for coming back to me. I shall test other plotters ... but what I've noticed via ios app is that when under ssl, the whole page seems to be refreshed every few seconds (which was very aparenty with plotly because there was visible delay between refresh). Maybe I've just found a bug where under SSL / diferent port, HA doesn't keep connections open and terminates those. and FYI this is replicable on my LAN, so there should be no involvement of any intermediaries, making it even more bizzare.

dbuezas commented 1 year ago

Very interesting, it may well be an issue with HA, this card only talks with the server via the objet provided by the front end.

For what it is worth, i have no issues when we connecting through nabucasa, which is ssl (at least for the browser and app)

tomtom13 commented 1 year ago

So yes, for testing purposed I added record to my local DNS server stating that domain resolves to local IP - so the SSL validation is working perfectly OK, other services are working 100% OK, it's just the HA has some stupid trouble :/ The HA community seems to have hidden their head in the sand and don't even want to respond.

I'm starting to be more on your side with "it's not down to plotly" I've removed (removed via hacks) and bunch of other unused hacs, and alto the issue doesn't happen that often - it's still there. What makes it worse is the fact the logon page can get all screwy as well... and after creating a thread on HA forums I get 0 traction there.

dbuezas commented 1 year ago

Haha, that's not how free stuff works. Have you tried a clean installation to make sure it is reproducible? My random guess is that HA thinks it went asleep (like a tab becoming inactive for too long) or the websocket connection was closed. It could be anywhere

tomtom13 commented 1 year ago

Weeeeeelllll about free stuff, most of the time you'll at least get the "have you tried to close & open it again" (sometimes in sarcastic form) here - nada "The clean install" ... something I'm dreading ... got like 150 zigbee devices and bucked load of node.red stuff (beyond that, it's pretty vanilla) I'm just very very puzzled why even the logon page get's all messed up ... even when you hit reload from source ... but not on the default 8123.

But anyway, I think this bug can be closed, since the maybe my issue is unrelated to plotly ( still throwing unhandled exceptions is a bad practice, right ? :D )

dbuezas commented 1 year ago

maybe you could make a backup or boot from an sd card or something like that?

BTW, out of curiosity, why do you need to change the port?

tomtom13 commented 1 year ago

So actually it's a good question "but why" So recently I started shifting my services inhouse from external servers ... just to stop paying them for essentially stuff that I already got setup. I run small proxmox cluster and got vm for web, for file sharing [not the type you think, but for work, sometimes it's convenient to share binary you cooked with your colleagues, or even share your vm image], and few others - I started exposing those via HAPROXY, but when I started exposing HASS to the internet I spotted that all the stuff it just wonky. I've scratched my head for way to long on this one and then I realised that I've not eliminated issues with HASS it self. Low and behold, I just tried different port, and things started going bad (and plotly started throwing exceptions) ... added ssl, still no cigar, made sure that there are no issues with DNS for SSL, still no luck ... I've even tesed ssl on original port - nope. Seems like hass doesn't like me unless I use 8123 within my own network without any encryption in as vanilla as possible "http:" section (or lack of it) in configuration.yaml

tomtom13 commented 1 year ago

I might add that HASS was a vm under proxmox for last 2 years and had no issues with it. Actually I wen't with the advice of "don't bother with docker, stupid, and use our own fully supported OS" (paraphrase from HASS website) ... and that "fully supported OS" seems to have different of definition of support to my one :D But hey, life is life, and beggars can't be choosers.

dbuezas commented 1 year ago

I see. I don't use nabu casa much, but I like their mission so much, and they are creating really cool stuff like piper, esphome and the HA wonder that I consider that as donation. IMO, we should be happy they even put effort and money into documenting how not to use their service šŸ˜

tomtom13 commented 1 year ago

True, I never bothered to document any of my patches to kernel ;D but also I feel like everybody owe me because of those patches (yes I know they don't ... but still ego always rears it's ugly head)

tomtom13 commented 1 year ago

BTW, I've by now removed quite a lot of things from my HA, and hey ... seems to be working " ok " (ie layout doesn't go hay wire) ... and plotly doesn't throw a exception. Some other bugs happen now, but I think I will keep on removing stuff to see when any errors stop and start adding stuff back in.

tomtom13 commented 1 year ago

@dbuezas, I think I found the issue.

It seems that the "reboot HA" from within HA does not really mean "full machine reboot"(and I don't mean the quick reboot thingy in the menu) ... I don't know why, but there seems to be some JS or some part of the OS that was keeping it self to old IP / port / encryption over reboot. I found this out when I was doing update on my proxmox cluster and had to reboot the host - hence the VM was rebooted (a proper way) - then all the problems with "promises" inside of dev console just magically disappeared.

Moral of the story - on network changes just reboot your hardware (or VM).

I'll drop it in the HA forum for posterity.

dbuezas commented 1 year ago

šŸŽ‰šŸŽ‰ "have you tried turning it off and on again" is still often the answer