gassentb
(Gassentb)
September 13, 2023, 8:59am
1
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}}
francisp
(Francis)
September 13, 2023, 9:02am
2
indentation. and state:> does not belong there.
See here for an example :
tom_l
September 13, 2023, 9:07am
3
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
gassentb
(Gassentb)
September 13, 2023, 9:10am
4
Yes I saw it too, removed it but no change still same error
/Gassen
gassentb
(Gassentb)
September 13, 2023, 9:12am
5
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 %}
francisp
(Francis)
September 13, 2023, 9:17am
6
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) }}
gassentb
(Gassentb)
September 13, 2023, 9:23am
7
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:
francisp
(Francis)
September 13, 2023, 9:24am
8
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.
gassentb
(Gassentb)
September 13, 2023, 9:32am
9
Ok
I will change i to have indentation and se what’s happening.
/Gassen
gassentb
(Gassentb)
September 13, 2023, 10:05am
10
I have now change all i the file
and when i thry to save I get this message in Studio code server
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}}
gassentb
(Gassentb)
September 13, 2023, 10:09am
11
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
TheFes
(The Fes)
September 13, 2023, 10:53am
12
In case you want to get more out of the data, you can check out the macro I created:
gassentb
(Gassentb)
September 14, 2023, 1:30pm
13
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 }}
gassentb
(Gassentb)
September 14, 2023, 2:04pm
15
do you meen that it should be 2 spaces?
gassentb
(Gassentb)
September 14, 2023, 2:08pm
17
Change it to that and same error
TheFes
(The Fes)
September 18, 2023, 11:39am
18
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") -%}
wgumaa
(Waleed)
October 19, 2023, 2:37pm
19
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 .
TheFes
(The Fes)
November 2, 2023, 10:29am
20
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