thomasloven / hass-lovelace_gen

🔹 Improve the lovelace yaml parser for Home Assistant
MIT License
209 stars 22 forks source link

Jinja2 not recognized #3

Closed titouanlh closed 4 years ago

titouanlh commented 4 years ago

Hi ! First of all, thank you Thomas for your amazing work, your plugins are trully great. I'd like to use a basic Jinja2 template in my config, here is the begining of my ui-lovelace.yaml

# lovelace_gen
{% set v1 = switch.bin1 %}

And this is what I get when refreshing Lovelace :

while scanning for the next token found character '%' that cannot start any token...

In my config I also have included views like this :

views:
  - !include lovelace/010_default.yaml

And if I had # lovelace_gen on top of those, I get this :

Unknown error

Did I do something wrong ? Also, lovelace-gen seems to be recognized by Hass, as I get this on startup :

[homeassistant.loader] Loaded lovelace_gen from custom_components.lovelace_gen

I'm using Hass v0.97.2 on Windows in a Python virtual environment Many thank's :)

thomasloven commented 4 years ago

Add quotes around switch.bin1. That's a bug in the readme. Thanks for letting me know.

titouanlh commented 4 years ago

Thank you for your help, but I'm still having the same issue... The error seems to be caused by the % character but I don't understand why.

And about the error I get when adding # lovelace_gen to my included files ? Is it normal ? Maybe both issues are related ?

sti0 commented 4 years ago

Same here, added

# lovelace_gen
{% set my_lights = ["light.buro", "light.kuche"] %}

to my ui-lovelace.yaml and got the same error on refreshing:

while scanning for the next token found character '%' that cannot start any token in "/config/ui-lovelace.yaml", line 2, column 2

thomasloven commented 4 years ago

I've had some problems with using lovelace_gen on ui-lovelace.yaml itself. Try including a file and do everything there instead.

sti0 commented 4 years ago

Thanks. Got it to work now :)

oyvindhauge commented 3 years ago

First of all, thanks to Thomas for all the great work you do for the community! Second, I am sorry if posting on a closed bug is the wrong way to go around.

However, I believe I have the same problem as described above. In my case it prevents HACS from starting when I restart Home Assistant. If I comment out the include below, I am able to start Home Assistant normally. And if I then uncomment the line again after the restart, the view is displayed correctly.

In my log file I have the following error message

Error setting up entry for hacs 4:12:43 PM – util/yaml/loader.py (ERROR)

This is followed by the more detailed log trace `... File "/usr/local/lib/python3.8/site-packages/yaml/scanner.py", line 258, in fetch_more_tokens raise ScannerError("while scanning for the next token", None, yaml.scanner.ScannerError: while scanning for the next token found character '%' that cannot start any token in "/config/lovelace/views/01_light_view.yaml", line 8, column 8

The above exception was the direct cause of the following exception: ...`

My ui-lovelace.yaml does not contain anything regarding lovelace_gen. It does however have the following include - !include lovelace/views/01_light_view.yaml

The 01_light_view_yaml contains the following relevant lines ` # lovelace_gen title: Lighting icon: mdi:lightbulb path: lighting cards:

-------------BASEMENT------------------------------

  {% set lights = ["light.basement_stairs_ceiling_dz", "light.basement_gym_ceiling", "light.basement_storage_ceiling_dz", "light.basement_laundry_ceiling_dz", "light.basement_laundry_sink", "light.cinema_ceiling", "light.lower_back"] %}
  - type: glance

` I am more than happy to provide more information, if that may help solve the problem. Thanks in advance for any suggestions.