tjntomas / HADashboard-widgets

Widgets for HADashboard / Appdaemon
MIT License
52 stars 26 forks source link

No connection to server #8

Closed tollerm closed 5 years ago

tollerm commented 5 years ago

When trying to run this plugin I got the following message in the web console: Firefox can't establish a connection to the server at ws://undefined/api/websocket. application.js:2889:11 Connection to Home Assistant closed

Other widgets in the panel perform without any problem.

tjntomas commented 5 years ago

Hi, which of the widgets are you using? I have 5 widgets in the repo. Please also post your widget definition from your .dash file.

tollerm commented 5 years ago

i am trying to get a graph widget working. My widget definition is a copy of a recommended setup:

mvp: widget_type: hagraph entities:

layout:

tjntomas commented 5 years ago

Did you add the required entries to parameters.yaml file of the skin you are using?

tollerm commented 5 years ago

I use a default skin. It does not have the 'parameters.yaml' file. I presume that you mean the 'variables.yaml' file. I added the required lines to that file. I used the same long-live token as that for the 'appdaemon'. Do I need to generate in the Homeassistant a new token and put it into the 'variables.yaml' file?

tjntomas commented 5 years ago

Yes, I meant variables.yaml. No, the same token as you use for appdaemon should be fine. It appears that the widget is not able to read the hagraph_path: http://url_to_your_home_assistant_instance:8123 # Adjust the port if needed.

What do you have in this entry?

tjntomas commented 5 years ago

If you don´t mind doing some debugging, you can add console.log(self.parameters.css.ha_url) after line 342 in the basehagraph.js file (that´s the line async function get_history(self, entity, time_filter, index, callback){ and see what you get in the console.

tollerm commented 5 years ago
  1. I have the following line in my 'variables.yaml' file. hagraph_path: http://192.168.2.15:8123

  2. I added the statement for debugging but it did not produced any additional output in the web console. It seems indeed that something is wrong with the path. However, all other widgets are working fine. Moreover, when I change some variables in this file, the dashboard responds to these changes.

tjntomas commented 5 years ago

Very strange. Do you have your default skin in the custom_css folder and also have you tried specifying the skin to use by adding ?skin=default to the end of your url? More things to try: After line 53, that´s this line: WidgetBase.call(self, widget_id, url, skin, parameters, monitored_entities, callbacks) add console.log(self.parameters) and console.log(self.parameters.css)

tjntomas commented 5 years ago

And of course you can try to restart appdaemon and clear the browser cache.

tollerm commented 5 years ago

After clearing the browser cache I got this message: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://192.168.2.15:8123/api/history/period/2019-04-16T20:17:48?authSig=
filter_entity_id=sensor.temp_xiaomi2. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

tjntomas commented 5 years ago

Ok, that´s easy to fix! In configuration.yaml for your ha instance, you need to add the url to your appdaemon instance under the http: section. It should look something like this:

http:
  cors_allowed_origins:
    - http://192.168.2.15:5050

Then restart Home Assistant and appdaemon and the cors error should be gone.

tollerm commented 5 years ago

Now it works! Thank you very much for help.

tjntomas commented 5 years ago

Great!