Missed comma between flow collection entries

Hi there, I want to create a sensor that spits out the current price of electrical power. My power company conveniently provides this code:

sensor:
- platform: rest
name: "momentaner Strompreis (Verbrauch)"
unit_of_measurement: "ct/kWh"
resource: https://i.spottyenergie.at/api/yaddayaddaAPIcall
value_template: >-
{% set now = now() %}
{% set ns = namespace(last_price=None) %}
{% if value_json %}
{% for item in value_json %}
{% if item.from | as_datetime < now %}
{% set ns.last_price = item.price %}
{% else %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
{{ ns.last_price }} 

HA returns:

missed comma between flow collection entries (19:2)

16 | unit_of_measurement: “ct/kWh”
17 | resource: https://i.spottyenergi
18 | value_template: >-
19 | {% set now = now() %}
-------^
20 | {% set ns = namespace(last_price …

I did try ‘xx’ the meaty part, also double brackets, to no avail. Where is the mistake? Thanks!

Is that really what they shared with you?

Because the correct indentation (which is important in YAML) is missing.

sensor:
  - platform: rest
    name: "momentaner Strompreis (Verbrauch)"
    unit_of_measurement: "ct/kWh"
    resource: https://i.spottyenergie.at/api/yaddayaddaAPIcall
    value_template: >-
      {% set ns = namespace(last_price=None) %}
      {% if value_json %}
        {% for item in value_json if item.from | as_datetime | as_local < now() %}
          {% set ns.last_price = item.price %}
          {% break %}
        {% endfor %}
      {% endif %}
      {{ ns.last_price }}
1 Like

Oh wow. Really. Nah they provided it correctly, I fucked that one up. T’was my first time fiddling around in there & it shows since I didn’t know that’s important in any other way than make it clearly arranged :wink:

Thank you! That did it!

1 Like