Help needed : Using Fields in a script

Hello, I am try for a few hours to make this script work ; I just don’t get it.

I have an “input helper” to configure the temperature set point I want all my thermostats to use when I’m going away. I need this to be called via a script.

The usage of seems the way to go, I followed many exemples, but it returns error when I try to use it.

This is my script :

fields:
  away_temperature:
    selector:
      attribute:
        entity_id: input_number.away_temperature
    name: Away Temperature
    required: true
    default: editable
sequence:
  - action: climate.set_temperature
    metadata: {}
    data:
      temperature: "{{ away_temperature }}"
      hvac_mode: heat
    target:
      device_id:
        - 09ffb85ed8fc045cf7f98ce923e07d1b
        - a20453a1a3b8186b74bd73bb69d2a73d
        - 7e18e604180b0c29b8a116cdfd97d8e8
        - 5f3d97482da338a802177d5338c9ac1a
        - f46a4795cab2713faa1a1e6f0458403c
        - 0b1d7ebf184c65cd67794d9fa65e4c06
alias: "[Heating] [Away] Set all thermostat to specified set point"
description: ""

When using the script, I select “Managed Via UI” as the option

And this is the error I get :

Failed to perform the action script/heating_away_set_all_thermostat_to_specified_set_point. 
expected float for dictionary value @ data['temperature']

I did try some stuff like {{ away_temperature | float }} but I get syntax error…

Clearly I am missing something… I would appreciate some help here.

There are various issues with your example… but can you clarify what you are trying to do with this script?

Issues:

  • The Selector you have chosen doesn’t make sense. What options do you expect the selector to give you? An Attribute selector allows you to select an attribute of a given entity… The attributes of an input_number do not include any value that would be useful in this script, based on your description. The attribute “Managed via UI” will only ever return the string “editable”. Similarly, the other attributes will always return their attribute ID strings like “min”, “max”, “initial”.
    I would guess that what you actually want is a Select selector which would allow you have a drop down with options like “Away Mode”, etc. If that is not what you want, please clarify.
  • The default you have provided, the string “editable”, makes no sense as a value for a temperature.
  • The script does not provide any branching logic. What should happen for each of the available options from the selector?

Further Questions:

  • How is the temperature value of these thermostats normally managed? Are there other automations or scripts that control them?
  • Do those other control mechanism need to be influenced by this script, or do they already account for people being away?

Thanks for the feedback… clearly I’m using it wrong…

The use case is :

  • I want an input variable where a can set values like "the temperature I want to set all thermostat when I go away for the weekend or when I leave the house". I want to do this on the UI in a section where all of those variable are sets. So lets say 15 Celsius
  • I want to use this variable in automation (when I set the Alarm in Away mode)
  • I want to use this variable with an action tied to a button that could be a preset.

I was of course able to do it directly in an automation, but I wanted to reuse some code with a script.

I was trying to pass the setpoint contained in my “input_number.away_temperature” to the action “action: climate.set_temperature” . But clearly I misunderstood how this selector is working.

Now, trying the Select Selector I still don’t know what to specify to reference the set point. The way I did it, it doesn’t pass the content of the variable (15), it seems to pass the text (input_number.away_temperature). Trying to use a template like {{ states(‘input_number.away_temperature’) }} doesn’t seems to work.

fields:
  away_temperature:
    selector:
      select:
        options:
          - input_number.away_temperature
    name: Away Temperature
    required: true
sequence:
  - action: climate.set_temperature
    metadata: {}
    data:
      temperature: "{{ away_temperature }}"
      hvac_mode: heat
    target:
      device_id:
        - 09ffb85ed8fc045cf7f98ce923e07d1b
        - a20453a1a3b8186b74bd73bb69d2a73d
        - 7e18e604180b0c29b8a116cdfd97d8e8
        - 5f3d97482da338a802177d5338c9ac1a
        - f46a4795cab2713faa1a1e6f0458403c
        - 0b1d7ebf184c65cd67794d9fa65e4c06
alias: "[Heating] [Away] Set all thermostat to specified set point"
description: ""

Hope I clarified what I’m trying to do.

This is what I was picturing based on your original description, so you could create other input_number Helpers (whose entity IDs follow a pattern) to hold the setpoint for other modes and just add those to the options list:

fields:
 mode:
   selector:
     select:
       options:
         - Away
         - Example
   name: Mode
   required: true
sequence:
 - variables:
     #The following template will turn the mode value from the field 
     #into the state of an entity id like "input_number.example_temperature"  
     temp: "{{ states('input_number.'~mode|slugify~'_temperature') | float(0) }}"
 - action: climate.set_temperature
   metadata: {}
   data:
     temperature: "{{ temp }}"
     hvac_mode: heat
   target:
     device_id:
       - 09ffb85ed8fc045cf7f98ce923e07d1b
       - a20453a1a3b8186b74bd73bb69d2a73d
       - 7e18e604180b0c29b8a116cdfd97d8e8
       - 5f3d97482da338a802177d5338c9ac1a
       - f46a4795cab2713faa1a1e6f0458403c
       - 0b1d7ebf184c65cd67794d9fa65e4c06
alias: "[Heating] [Away] Set all thermostat to specified set point"
description: ""

This is templating “wizardery” for me!

Implemented your solution and it’s working perfectly. Just learned a lot of stuff here… :slight_smile:

Thanks a lot for your help!

/e