A graph widget for HADashboard

I’ve tried both ideas and it’s still the same mistake.

ok, can you post your http section from configuration.yaml?

Also clear the browser cache since the changed widget wont be reloaded otherwise.

I always clear the cache at every change, but it still doesn’t work.
This is my configuration.

http:
  api_password: xxxxxxxxxxx
  ssl_certificate: /home/homeassistant/.homeassistant/certificate.pem
  ssl_key: /home/homeassistant/.homeassistant/privkey.pem
  # Secrets are defined in the file secrets.yaml
  # api_password: !secret http_password
  # Uncomment this if you are using SSL/TLS, running in Docker container, etc.
  #base_url: 192.168.1.200:8123

One more thing to check before I’ll try using ssl myself: Can you post your appdaemon.yaml file?

Ok, I enabled ssl on my Home Assistant instance and I figured out what the problem is. If ssl is used, I need to access the websocket through wss:// instead of ws://. After changing this, I got it working. I will make adjustments to the widget code and upload.

appdaemon:
  logfile: STDOUT
  errorfile: STDERR
  disable_apps: 0
  plugins:
    HASS:
      type: hass
      ha_url: https://192.168.1.200:8123
      ha_key: xxxxxxxx
      cert_verify: False
      token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZWMwNjYyYWY5ZGI0NTExOWY0YmQwNjIzOWE4ZGM1MyIsImlhdCI6MTU0MTE4NzM3NSwiZXhwIjoxODU2NTQ3Mzc1fQ.7nV5GoVLrcfXLBG1MQQQCzwbGyeoHt29N89Kk-7r40j

hadashboard:
  dash_url: http://127.0.0.1:5050
  dashboard_dir: /home/homeassistant/conf/dashboards
  always_compile: 0
  dash_compile_on_start: 1
  
#rss_feeds:
#  - feed: http://rss.sensacine.com/cine/semana
#    target: rss_cine
#rss_update: 480

log:
  accessfile: /home/homeassistant/logs/access.log
  errorfile: /home/homeassistant/logs/error.log
  logfile: /home/homeassistant/logs/appdaemon.log
  log_generations: 3
  log_size: 1000000

@daekka

I have update the basehagraph.js file to handle ssl now. Please give it a try.

Now, there is no error but the widget is still not visible.
A question?
The entitie has to be defined as:
-recorder?
-History?
-history_graph?

So a slight improvement. Does it show anything else in the log?

I don’t understand your question but your widget definition is correct as you have posted it above.

In configuration.yaml, you need to have the history component enabled with either

history:

or with some selected entites to save in history:

history:
  include:
    entities:
      - sensor.pressure_158d0001e45542
      - sensor.pressure_158d0001e45693

I use the include section to limit the size of the home assistant db.

I’m sorry, but the widget doesn’t show.
I have no errors.
I have no idea.

Hi, tjntomas
I have reinstalled the whole system and now I get different errors. I attach a screenshot
Any suggestions?

Hi, you are getting cors errors. Have you configured cors_allowed_origins in configuration.yaml? This is my http configuration:

http:
  ssl_certificate: /home/homeassistant/.homeassistant/certificate.pem
  ssl_key: /home/homeassistant/.homeassistant/privkey.pem
  cors_allowed_origins:
    - http://local_ip_for_your_ha_instance:8123
    - https://public_ip_for_your_ha_instance:8123 

I do have the option cors_allowed_origins configured as you.

One thing that makes me wonder is that I do not use influxdb-latest.js but the errors refer to it. Anyway I installed the javascript to see if the error disappeared.

I also miss the error when accessing the sensor and the error 404. If I make a request like:
curl https://xxxxx.duckdns.org:8123/api/history/period/2019-03-16T00:00:00?api_password=xxxxxxxxx
The answer is correct.

Hi, regarding the influx error, I noticed that I am including the influx library in the basehagraph.html file in line 2 and this is not neccesary. You can remove that line from your basehagraph.html file. I just forgot to remove the line since this is used in the similar influxdb widget I posted earlier. I also switched from using api_password to a long lived access token but I guess you have that entry in the skin? That would be
hagraph_token: YOUR_LONG_LIVED_ACCESS_TOKEN

Ok, I looked a bit more and the websocket connection to your home assistant instance works. The widget reads the history by requesting a “signed path” and it appears that XMLHttpRequest for this signed path fails. Please try to copy the url in the log starting with "Access to XMLHttpRequest at " and paste it into your browser. The signed path only lives for 20 seconds so you need to be fast. If you have

https://YOUR_DOMAIN.duckdns.org:8123

configured in cors_allowed_origin, you really should’t see this error so it is a bit strange.

Same answer: 404: Not Found.
I’ve even updated from YOUR_LONG_LIVED_ACCESS_TOKEN. But I do not get a correct answer. Always error 404
This is my TOKEN:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NTMwMTM5MjQsImV4cCI6MTg2ODM3MzkyNCwiaXNzIjoiOTQ5MGI4ZmZkM2JiNGUxNDlhYmU4ZjZhOGNmNzc0OTgifQ.l82ao6haa0YsQ-i8y7wdotilqw2RIddj0-YQ6t_FN04
And this my GET request:
https://xxx.duckdns.org:8123/api/history/period/18/3/2019T17:45:54?authSig=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NTMwMTM5NTUsInBhdGgiOiIvYXBpL2hpc3RvcnkvcGVyaW9kLzE4LzMvMjAxOVQxNzo0NTo1NCIsImV4cCI6MTU1MzAxMzk3NSwiaXNzIjoiOTQ5MGI4ZmZkM2JiNGUxNDlhYmU4ZjZhOGNmNzc0OTgifQ.AuQi7U8FunWA9UsheTKZHuFqRdWjUOx1Q_5t01zKD7U&filter_entity_id=sensor.temperatura_salon

I think it’s a problem with the format of the date request. The request is: https://xxx.duckdns.org:8123/api/history/period/19/3/2019T20:34:24?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI5NDkwYjhmZmQzYmI0ZTE0OWFiZThmNmE4Y2Y3NzQ5OCIsImlhdCI6MTU1MzExMDQ2OCwiZXhwIjoxNTUzMTEwNDk4LCJwYXRoIjoiL2FwaS9oaXN0b3J5L3BlcmlvZC8xOS8zLzIwMTlUMjA6MzQ6MjQifQ.kO7zDn8TAIxYe-lM1RTtRJUoYte_zlLAAQq2eGyXqAM&filter_entity_id=sensor.temperatura_salon
But modifying the format of the date works: … / period / 2019-3-19T20: 34: 24

My knowledge of javascript is not enough to solve this problem.

Try changing the last line of code in basehagraph.js from

	return today.toLocaleDateString() + "T" + today.toLocaleTimeString()

to

	return today.toLocaleDateString("sv-SE") + "T" + today.toLocaleTimeString()

and see if it works.