#using a boolean from a script

1 messages · Page 1 of 1 (latest)

toxic walrus
#

Hi all,
I have an automation that runs a script with a bit of logic in it that returns which scene I should be in for my energy usage, and a boolean that is whether or not I should activate that scene in the automation.

The script is running fine, and it returns what I expect it to, but traces on my automation show that my conditional is evaluated as false, even when my script is returning true.

Here's the YAML for the actions part of my automation

actions:

  • action: script.scene_selector_script
    metadata: {}
    data: {}
    response_variable: new_scene
  • if:
    • condition: template
      value_template: "{{ new_scene.update }}"
      then:
    • action: scene.turn_on
      metadata: {}
      data: {}
      target:
      entity_id: "{{ new_scene.scene }}"

And here is the changed variables section of my trace

context:
id: 01JHTTKG6CJDD7EMG7NK7808V3
parent_id: 01JHTTKG6B9THZ81190RKWVJJR
user_id: null
new_scene:
scene: scene.save_power
update: true

But when I look at the step details for my conditional:

if
Executed: January 17, 2025 at 2:07:26 PM
Result:
result: false
if/condition/0
[If template renders a value equal to true]
Executed: January 17, 2025 at 2:07:26 PM
Result:
result: false
entities: []

Can anyone help me figure out why the conditional is evaluating to false even though the script is returning true?

Thanks!

echo hatch
#

Nothing jumping out at me as obviously wrong, though if you share the full trace json on a code share site we can load it in the trace viewer and get a more detailed look.

cobalt thistle
#

may be true and false are not boolean but seen as texts ???
i tested the following:


{{ ( ( 1 == 1 ) == True )  }}  => return True 
{{ ( ( 1 == 1 ) == "True" )  }}  => return False
{{ ( ( 1 == 1 ) == "True"|bool )  }}    => return True
trail wedge
#

I don't know if it would help, but it would be worth trying to add a delay of a second or so. It shouldn't be necessary for it to worth properly, but it could help rule out timing the variable being set vs the timing of execution.