#Using field data in variables seems to fail

1 messages ยท Page 1 of 1 (latest)

thorn wharf
#

My intent is to use both fields and variables in the same script. The field is, of course, the input and the variables are derived using this input. The purpose of the variables is mostly to DRY things up. I believe I may be hitting a case where variables are resolved before fields, but I'm not sure.

When I call this script via script.turn_on or script.<script entity> with the field input of a climate entity, it errors out with thermostat is Undefined as if I had not provided thermostat input.

steep mango
#

is there a trace that might have any more detail?

compact pagoda
thorn wharf
thorn wharf
compact pagoda
#

Yes it should be ok. There has to be something passed to it and/or have a default, though

#

If you are just using the UI test, nothing will be passed in...

thorn wharf
#

I'm calling it this way:

action: script.turn_on
data:
  entity_id: script.emergency_heat_boost_with_temperature_increase
  variables:
    thermostat: climate.buck_knoll_common_areas
#

which yields:

Source: helpers/script.py:2032
integration: Script (documentation, issues)
First occurred: November 7, 2024 at 8:08:15 PM (13 occurrences)
Last logged: 7:59:42 AM

Emergency Heat Boost with Temperature Increase: Error rendering variables: UndefinedError: 'thermostat' is undefined
Emergency Heat Boost with Temperature Increase: Already running
Emergency Heat Boost with Temperature Increase: Error executing script. Error for call_service at pos 2: Set temperature action was used with the target temperature parameter but the entity does not support it
#

the 2 last errors are historical and from my debugging attempts

compact pagoda
#

Mine are more like this to pass data to a script...


            - action: script.personalert_notify
              data:
                person: "{{ trigger.from_state.attributes.friendly_name }}"
                place_to: "{{ trigger.to_state.state }}"
                place_from: "{{ trigger.from_state.state }}"
                notify_id: "{{ trigger.from_state.context.id }}"
                phase: leave
#

I don't like that variables key in there, not sure about it.

thorn wharf
#

calling the entity id of the script instead of script.turn_on seems to be the main difference there?

steep mango
#

variables seems to be used in the example

compact pagoda
#

ok, not familiar with that syntax,

thorn wharf
#

okay, so using the example from the docs, i call it via

action: script.turn_on
target:
  entity_id: script.emergency_heat_boost_with_temperature_increase
data:
  variables:
    thermostat: climate.buck_knoll_common_areas

and get the same thermostat is undefined error

#

it seems like variables in the script are parsed before fields are and thermostat is not yet defined until fields is parsed, but i haven't looked over the code

steep mango
#

I copy/pasted your script and tried it and I'm having no issue

#

can't reproduce any error

thorn wharf
#

o_O okay... that is extra puzzling ๐Ÿ˜†

steep mango
#

make sure your script is the one you think it is? haven't accidentally created multiple copies, or calling the wrong one

compact pagoda
#

Pointing at this then? climate.buck_knoll_common_areas

#

MT?

thorn wharf
#

this is actually my first script, so it's the only script.

steep mango
#

unsaved changes? I'm grasping at straws ๐Ÿ˜‚

thorn wharf
#

did you remove the filter when you pasted it?

steep mango
#

yes I did

#

shouldn't matter AFAIK

thorn wharf
#

๐Ÿคฆ i removed the filter and now it works.

steep mango
#

that's curious...

thorn wharf
#

errr, to be more clear, i removed the entire selector dict

steep mango
#

try putting it back

#

I still have this:

fields:
  thermostat:
    name: Thermostat Entity
    description: The climate entity for controlling temperature
    selector:
      entity: null
    example: climate.zone_1_bedrooms
    required: true
thorn wharf
#

now i can't get it to fail with that error no matter what i do ๐Ÿคท i mimicked your setup, then added the filter back.

#

unexplainable for sure

steep mango
#

my bet is on that you forgot to save the changes, but of course I don't know ๐Ÿคท
glad it's working

thorn wharf
#

i had edited and saved so many times, but yeah who knows. it's working now. i'll leave heisenbugs for my dayjob ๐Ÿ˜†