Help with For each loop

So i am making an automation but i dont really get the for loop with the repeat.item.

So i have a set of devices: i wanna loop trought them and change the string to a different one

repeat:
  for_each:
    - climate.bathroom_vtherm
    - climate.bedroom_2_vtherm
  sequence:
    - action: versatile_thermostat.set_preset_temperature
      data:
        preset: frost
        temperature: {{states('number.'~{{ repeat.item }}[8:]~'_preset_frost_temp') }}
        temperature_away: 16.0

climate.bathroom_vtherm string should be changed into number.bathroom_vtherm_preset_frost temp but i can make out why i cant make it work

so basicly i wanna trim the name of the repeat.item and turn it in to a new string that i can use :frowning:

Single-line templates must be quoted and you don’t want the extra brackets:

        temperature: "{{ states('number.'~repeat.item[8:]~'_preset_frost_temp') }}"

thanks so much, thats seem to be working…

only it seem to be bumpong onto the next error

the target

Fout: extra keys not allowed @ data['target']
Resultaat:
params:
  domain: versatile_thermostat
  service: set_preset_temperature
  service_data:
    preset: frost
    temperature: 16
    temperature_away: 16
    target:
      entity_id: climate.bathroom_vtherm
  target: {}
running_script: false

script is

repeat:
  for_each:
    - climate.bathroom_vtherm
    - climate.bedroom_2_vtherm
    - climate.living_room_vtherm
    - climate.bedroom_vtherm
    - climate.kitchen_vtherm
  sequence:
    - action: versatile_thermostat.set_preset_temperature
      data:
        preset: frost
        temperature: "{{ states('number.'~repeat.item[8:]~'_preset_frost_temp') }}"
        temperature_away: 16
        target:
          entity_id: "{{ repeat.item }}"

You’ve over-indented target:: it should not be part of data:.

  sequence:
    - action: versatile_thermostat.set_preset_temperature
      data:
        preset: frost
        temperature: "{{ states('number.'~repeat.item[8:]~'_preset_frost_temp') }}"
        temperature_away: 16
      target:
        entity_id: "{{ repeat.item }}"

See here: versatile_thermostat/documentation/en/reference.md at e727c0628e23aba486f15215e4d76b3e0c6500d8 · jmcollin78/versatile_thermostat · GitHub

that was it. Thanks a lot for your help.

Swithcing from node red to autoamtiions more and more and lotsa to learn :smiley:

Happy holidays

1 Like