#How to define variables with the GUI block?

1 messages · Page 1 of 1 (latest)

next oasis
#

Can't seem to find a good example on the structure of this.

humble fable
#

Standard YAML syntax for dicts, lists, and key/value pairs

next oasis
#

Curious why it is giving me curly brackets then

humble fable
#

It's an empty dict

#

Represented in JSON syntax

#

Remove that and follow the examples in the docs to populate it with whatever you want

next oasis
#

Ah, so it doesn't crash I suppose

#

However, am getting an error when creating the automation like this following the example. Am I missing something?

humble fable
#

You're missing the {{ }} in your variable definition

#

And you need to quote it

#

See how you used the template properly below

next oasis
#

Oh right. And also quotes, like so?

humble fable
#

Please share text rather than images

next oasis
#
variables:
  new_volume: "{{ state_attr('media_player.chromecastultra1943', 'volume_level')) }}"

action: media_player.volume_set
metadata: {}
data:
  volume_level: "{{ new_volume }}"
target:
  device_id: 62676f98a5d747221ed9faf9fb48d8f7

humble fable
#

Yes

next oasis
#

Message malformed: invalid template (TemplateSyntaxError: unexpected ')') for dictionary value @ data['actions'][0]['choose'][1]['sequence'][1]['sequence'][0]['variables']['new_volume']

#

Bonus paranthesis

humble fable
#

You gave an extra )

next oasis
#

Gosh darn it's late. Thanks for the help by the way!

#

I'm finishing it up right now, trying to add multiple variables

#
variables: 
  curr_volume: " {{ state_attr('media_player.chromecastultra1943', 'volume_level') }}"
  increment: 0.05

action: media_player.volume_set
metadata: {}
data:
  volume_level: "{{ curr_volume }} + {{ increment }}"
target:
  device_id: 62676f98a5d747221ed9faf9fb48d8f7