Error in templates.yaml

Hello agian
New error this time in my templates.yaml,
The error is in line 3 and it says
end of stream or a document separator is expected

bellow my code

- sensor:
##### Nord Pool Energyprices ############**********************
state:>                                                                    (error show up in this row)
- name: "NordPool Energyprices"
attributes:
  unit_of_measurement:"SEK"
  unique_id: 'db748368-1554-42fd-9d25-764de08311c7'
{{ states('sensor.nordpool_kwh_se4_sek_3_10_025')}}
times:>
{% -set ns = namespace(times=[]) -%}
{%- set today = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'raw_today') -%}
{%- for hours in today -%}
{%- set ns.times = ns.times + [as_local((hours.start)) .strftime("%Y-%m-%d %H:%M:%S")] -%}
{%- endfor -%}
{%- set tomorrow = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'raw_tomorrow") -%} I
{%- for hours in tomorrow -%}
{%- set ns.times = ns.times + [as_local((hours.start)).strftime("%Y-%m-%d %H:%M:%S")] -%}
{%- endfor -%}
{{ ns.times}}
prices:>
{% set ns = namespace (prices=[]) -%}
{%- set today = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'raw_today') -%}
{%- for hours in today -%}
{%- set ns.prices = ns.prices + [hours.value + states ('input_number.nordpool_additional costs') | float] -%}
{%- endfor -%}
{%- set tomorrow = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'raw_tomorrow') -%}
{%- for hours in tomorrow -%}
{% if hours.value %}
{%- set ns.prices = ns.prices + [hours.value + states('input_number.nordpool_additional_costs') | float] -%}
{% endif %}
{%- endfor -%}
{{ ns.prices}}

indentation. and state:> does not belong there.

See here for an example :

As well as your indentation issues you appear to have a stray “I” at the end of this line:

{%- set tomorrow = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'raw_tomorrow") -%} I

Yes I saw it too, removed it but no change still same error
/Gassen

When I check in this exaple there is a state >

state: >
          {% set bedroom = states('sensor.bedroom_temperature') | float %}
          {% set kitchen = states('sensor.kitchen_temperature') | float %}

Look at the example, where you put state, and where state is in the example

template:
  - sensor:
      - name: "Average temperature"
        unit_of_measurement: "°C"
        state: >
          {% set bedroom = states('sensor.bedroom_temperature') | float %}
          {% set kitchen = states('sensor.kitchen_temperature') | float %}

          {{ ((bedroom + kitchen) / 2) | round(1, default=0) }}

Thank but when I change to as bellow same error

- sensor:
##### Nord Pool Energyprices ############
- name: "NordPool Energi priser"
state:>
{{ states('sensor.nordpool_kwh_se4_sek_3_10_025')}}
attributes:

indentation !!!
Look at the white-space in the example, and the white-space in your sensor !!!
Yours is all sticky to the left, which is totally wrong.

Ok
I will change i to have indentation and se what’s happening.
/Gassen

I have now change all i the file
and when i thry to save I get this message in Studio code server
image

my code is now like this

sensor:

 ##### Nord Pool elpriser ##############

    - name: "Nord Pool Elpriser"

      unique_id: a739c027-575d-44e8-bb46-c95fa67c3142

      icon: €mdi:currency-eur

      unit_of_measurement: "SEK"

      state: >

        {{ states('sensor.nordpool_kwh_se4_sek_3_10_025')}}

      attributes:

        times: >

          {% set ns = namespace (times=[]) -%}

          {% - set today = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'raw_today') -%}

          {%- for hours in today -%}

            {%- set ns.times = ns.times + [as_local((hours.start)).strftime("%Y-%m-%d %H:%M:%5")] -%}

          {%- endfor -%}

          {%- set tomorrow = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'raw_tomorrow') -%}

          {%- for hours in tomorrow -%}

            {%-set ns.times = ns. times + [as_local((hours.start)).strftime("%Y-%m-%d %H:%M:%5")] -%}

          {%- endfor -%}

          {{ ns.times }}

        prices: >

          {% set ns = namespace (prices=[]) -%}

          {%- set today = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'raw_today") -%}

          {%- for hours in today -%}

            {%- set ns.prices = ns.prices + [hours.value + states ('input_number.nordpool_additional costs') | float] -%}

          {%- endfor -%}

          {%- set tomorrow = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'raw_tomorrow') -%}

          {%- for hours in tomorrow -%}

          {% if hours.value %}

            {%- set ns.prices = ns.prices + [hours.value + states ('input_number.nordpool_additional costs') | float] -%}

          {% endif %}

          {%- endfor -%}

          {{ ns.prices}}

Thanks francisp
I think it is solved, using file editor in HA then it works to save the file, and I hope it will work when I restart HA

/Gassen

In case you want to get more out of the data, you can check out the macro I created:

It did not work
got this error

Invalid config for [template]: invalid template (TemplateSyntaxError: expected token ',', got 'input_number') for dictionary value @ data['sensor'][0]['attributes']['prices']. Got '{% set ns = namespace(prices=[]) -%} {%- set today = state_attr(\'sensor.nordpool_kwh_se4_sek_3_10_025\',\'raw_today") -%} {%- for hours in today -%}\n {%- set ns.prices = ns.prices + [hours.value + states(\'input_number.nordpool_c4energi_costs\') | float] -%}\n{%- endfor -%} {%- set tomorrow = state_attr(\'sensor.nordpool_kwh_se4_sek_3_10_025\',\'raw_tomorrow\') -%} {%- for hours in tomorrow -%} {% if hours.value %}\n {%- set ns.prices = ns.prices + [hours.value + states(\'input_number.no... invalid template (TemplateSyntaxError: tag name expected) for dictionary value @ data['sensor'][0]['attributes']['times']. Got '{% set ns = namespace(times=[]) -%} {% - set today = state_attr(\'sensor.nordpool_kwh_se4_sek_3_10_025\',\'raw_today\') -%} {%- for hours in today -%}\n {%- set ns.times = ns.times + [as_local((hours.start)).strftime("%Y-%m-%d %H:%M:%S")] -%}\n{%- endfor -%} {%- set tomorrow = state_attr(\'sensor.nordpool_kwh_se4_sek_3_10_025\',\'raw_tomorrow\') -%} {%- for hours in tomorrow -%}\n {%-set ns.times = ns.times + [as_local((hours.start)).strftime("%Y-%m-%d %H:%M:%S")] -%}\n{%- endfor -%} {{ ns.... (See /config/configuration.yaml, line 14).

In raw 14 in configuration.yaml it says
template: !include templates.yaml

Code in templates.yaml

sensor:

  ##### Nord Pool elpriser ##############

  - name: "Nord Pool Elpriser"

    unique_id: a739c027-575d-44e8-bb46-c95fa67c3142

    icon: €mdi:currency-eur

    unit_of_measurement: "SEK"

    state: >

      {{ states('sensor.nordpool_kwh_se4_sek_3_10_025')}}

    attributes:

      times: >

        {% set ns = namespace(times=[]) -%}

        {% - set today = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025','raw_today') -%}

        {%- for hours in today -%}

          {%- set ns.times = ns.times + [as_local((hours.start)).strftime("%Y-%m-%d %H:%M:%S")] -%}

        {%- endfor -%}

        {%- set tomorrow = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025','raw_tomorrow') -%}

        {%- for hours in tomorrow -%}

          {%-set ns.times = ns.times + [as_local((hours.start)).strftime("%Y-%m-%d %H:%M:%S")] -%}

        {%- endfor -%}

        {{ ns.times }}

      prices: >

        {% set ns = namespace(prices=[]) -%}

        {%- set today = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025','raw_today") -%}

        {%- for hours in today -%}

          {%- set ns.prices = ns.prices + [hours.value + states('input_number.nordpool_c4energi_costs') | float] -%}

        {%- endfor -%}

        {%- set tomorrow = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025','raw_tomorrow') -%}

        {%- for hours in tomorrow -%}

        {% if hours.value %}

          {%- set ns.prices = ns.prices + [hours.value + states('input_number.nordpool_c4energi_costs') | float] -%}

        {% endif %}

        {%- endfor -%}

        {{ ns.prices }}

2 spaces before sensor:

do you meen that it should be 2 spaces?

like

  sensor:

Change it to that and same error

Check the last quote-sign in the last line below

      prices: >

        {% set ns = namespace(prices=[]) -%}

        {%- set today = state_attr('sensor.nordpool_kwh_se4_sek_3_10_025','raw_today") -%}

Hello all, I need some help with templating if possible.

I have created a sensors.yaml file where I have created 2 sensors that do simple conversion.

Here it is:

- platform: template
  sensors:
  
  
    convert_grid_power:
      unique_id: convert_grid_power
      friendly_name: "Grid Power Watts"
      value_template: "{{ states('sensor.solarnet_power_grid') | float * 1000 | round(2) }}"
     
    convert_charge_power:
      unique_id: convert_charge_power
      friendly_name: "Charge Power KW"
      value_template: "{{ (states('sensor.wattpilot_charging_energy') | float / 1000) | round(2) }}"   

I am now trying to add the “System Monitor” code into that file from the system monitor guide:

https://www.home-assistant.io/integrations/systemmonitor/

They are suggesting that if should put the code in my config.yaml file and when i do that it breaks the template sensors created.

Since the sensors file is included in the config.yaml, I am trying to get the code into that file, but I keep getting errors:

The code:

# Example configuration.yaml entry with all entry types (delete/comment out as necessary)
sensor:
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /config
      - type: disk_use
      - type: disk_free
      - type: memory_use_percent
      - type: memory_use
      - type: memory_free
      - type: swap_use_percent
      - type: swap_use
      - type: swap_free
      - type: load_1m
      - type: load_5m
      - type: load_15m
      - type: network_in
        arg: eth0
      - type: network_out
        arg: eth0
      - type: throughput_network_in
        arg: eth0
      - type: throughput_network_out
        arg: eth0
      - type: packets_in
        arg: eth0
      - type: packets_out
        arg: eth0
      - type: ipv4_address
        arg: eth0
      - type: ipv6_address
        arg: eth0
      - type: processor_use
      - type: processor_temperature
      - type: last_boot

The error originates from “sensor” at the top of this code as I have “sensors” at the top of the template sensors.

Can anyone tell me what I am doing wrong? Removing “sensor” doesn’t help .

besides removing the sensor: part, you also need to make sure the indentation is the same as for your template sensors, so you need to remove 2 spaces for every line, or at least these:

  - platform: systemmonitor
    resources:
1 Like