Ok, I’m a newby with HA, but have done quite some scripting with other platforms. Now after, looking at the documentation, trying the examples and searching through the forum and countless test/try iterations, I really can’t see why I can’t find my mistake. It’s like something is missing in the basic-set up.
So here a simple question:
It is so simple I’m a bit embarassed to even ask: I want to use a variable in a script, but whatever a try, I get errors when saving the script.
Message malformed: not a valid value for dictionary value @ data[‘sequence’][0][‘target’][‘entity_id’]
From this, I see that the variable is not evaluated. But why?
I have even tried the example script form the documentation, but get the same error? Is there something I have to set-up to be able to work with fields and variables?
script:
wakeup:
alias: "Wake Up"
icon: "mdi:party-popper"
description: "Turns on the bedroom lights and then the living room lights after a delay"
variables:
turn_on_entity: group.living_room
fields:
minutes:
description: "The amount of time to wait before turning on the living room lights"
example: 1
# If called again while still running (probably in delay step), start over.
mode: restart
sequence:
# This is Home Assistant Script Syntax
- event: LOGBOOK_ENTRY
event_data:
name: Paulus
message: is waking up
entity_id: device_tracker.paulus
domain: light
- alias: "Bedroom lights on"
service: light.turn_on
target:
entity_id: group.bedroom
data:
brightness: 100
- delay:
# supports seconds, milliseconds, minutes, hours
minutes: "{{ minutes }}"
- alias: "Living room lights on"
service: light.turn_on
target:
entity_id: "{{ turn_on_entity }}"
It would assume the text assigned to entity_id is the name of an entity. It definitely isn’t so it would cause an error.
The addition of target in automations is very new; the documentation (containing examples with target) was updated only about 10 days ago. I don’t think all the kinks have been ironed out yet …
About 9 days ago this PR to the Documentation repo updated various automation examples to include the use of target.
However, the following is the PR that introduced a description of target and how it’s used in service calls:
It’s dated 2020/12/13 and represents a significant enhancement to service calls. However, I don’t recall it being mentioned in either the January or February release notes.