Hi,
I’m new to HA but was able to do some basic set-up so far.
At this point I’m trying to make a script to identify the time slots for the lowest 25 percentile prices from the nordpool epex integration.
I have nordpool working perfectly fine and for my purpose I’m trying to loop through the ‘raw_today’ attribute list of the nordpool sensor.
I get to a point where I have an attribute list of values, but no way can I succeed to loop through it (for_each), I keep getting the error ‘‘repeat’ is undefined’.
I have read the script syntax manual up and down and I can’t even get the examples in there to work when I paste then in the template editor.
I’m sure the issue is a small detail, but I’ve spent many hours on it and I don’t see the problem.
The example code from the script syntax manual I’m trying to execute:
repeat:
for_each:
- language: English
message: Hello World
- language: Dutch
message: Hallo Wereld
sequence:
- action: notify.phone
data:
title: "Message in {{ repeat.item.language }}"
message: "{{ repeat.item.message }}!"
I don’t use Nordpool, so I may be missing something, but based on the template used in the first input_number.set_value action:
You are setting the value of a number entity to a list… which doesn’t make any sense
The for_each is being set to an object. In itself, this is fine, but…
a. The for_each configuration key can only handle simple objects, so if your object contains complex objects like datetime objects, it will fail.
The If condition is checking if a number is above an object… which doesn’t make any sense.
The Then action is setting a number to an object… which doesn’t make any sense
Hi,
Thank you for your swift reply.
I did so much testing and going back and forth between the template editor and the automation editor that I mixed up things and got confused.
My goal is to calculate the number of time slots when the prices are cheapest per day (24hrs) and daytime (12 hrs, 06:00 - 18:00) for dynamic electricity prices.
I use this information to calculate the required average charging power over these time slots (since Oct 1st this are 15min time slots) for my home battery and PHEV when there is no surplus power from the solar panels.
Meanwhile -and thanks to your message that made me rethink what I was doing- I got this working.
Below you find my test dashboard with the dynamic prices for today and tomorrow and the calculated number of 15-minute time slots for today.
I also added the Automation YAML script. This script also contains calculations for hourly averages, but this is for testing purposes only.
Thank you for your reaction.
Yes, I made that mistake in the first piece of code that I sent: ‘raw_today’ is indeed a list of dictionaries with a time and a value pair.
Later I realized that for the same entity there’s also a ‘today’ list attribute,so for my purpose I could simply use thar as I don’t require the time just for a count.
So in the current version of my script I’m using that list and that appears to be working just fine.