Template YAML help

Hi can anyone help me with this its been driving me nuts for hours:

template:
  - sensor:
      - name: "Hours To Charge"
        state: >
        {% set forecast = states('sensor.solcast_forecast_tomorrow') | int %}
        {% set usage = 20 %}
        {{ ((usage - forecast) / 3.5 ) | round }}

Looking at the documentation this looks ok but I am getting this error in the editor:

missed comma between flow collection entries (64:10)

61 | - sensor:
62 | - name: “Hours To Chargee”
63 | state: >
64 | {% set forecast = states('sensor …
---------------^
65 | {% set usage = 20 %}"

and this error in the config checker:

Error loading /config/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/configuration.yaml”, line 64, column 10

Thanks!

Pretty sure you just need to indent the template in state one level further. So like this:

template:
  - sensor:
      - name: "Hours To Charge"
        state: >
          {% set forecast = states('sensor.solcast_forecast_tomorrow') | int %}
          {% set usage = 20 %}"
          {{ ((usage - forecast) / 3.5 ) | round }}

Also I think you have a stray quotation mark after {% set usage = 20 %}, FYI

1 Like

OMG thankyou so much!