#Script Help Needed

1 messages · Page 1 of 1 (latest)

runic goblet
#

I am working on creating a script to handle a bug with my new Zigbee bulbs until I can run Zigbee2MQTT (i.e. I get a new Zigbee stick) and can update the firmware on them. However, I cannot get it to work, and get an error in the logs. I'm sure its simple and I'm just missing it. Help is appreciated.

script:
  master_bedroom:
    initial_state: True
    trigger:
      platform: time
      at: input_datetime.bedtime
    conditions:
      - condition: state
        entity_id: 'group.bedtimephones'
        state: 'home'
    sequence:
      - alias: "Turn on Shaun's nightstand"
        action: light.turn_on
        target:
          entity_id: light.shaun_nightstand_2
     - alias: "Wait 100ms"
       - delay:
           milliseconds: 100
     - alias: "Set color and brightness of Shaun's nightstand"
        action: light.turn_on
        target:
          entity_id: light.shaun_nightstand_2
          data:
            brightness_pct: 50
            rgb_color:
              - 0
              - 0
              - 0
     - alias: "Wait 100ms"
       - delay:
           milliseconds: 100
     - alias: "Set color and brightness of Shaun's nightstand"
        action: light.turn_on
        target:
          entity_id: light.shaun_nightstand_2
          data:
            brightness_pct: 50
            rgb_color:
              - 0
              - 0
              - 0```
#
      - alias: "Turn on Heidi's nightstand"
        action: light.turn_on
        target:
          entity_id: light.third_reality_inc_3rcb01057z
     - alias: "Wait 100ms"
       - delay:
           milliseconds: 100
     - alias: "Set color and brightness of Heidi's nightstand"
        action: light.turn_on
        target:
          entity_id: light.third_reality_inc_3rcb01057z
          data:
            brightness_pct: 50
            rgb_color:
              - 0
              - 0
              - 0
     - alias: "Wait 100ms"
       - delay:
           milliseconds: 100
     - alias: "Set color and brightness of Heidi's nightstand"
        action: light.turn_on
        target:
          entity_id: light.third_reality_inc_3rcb01057z
          data:
            brightness_pct: 50
            rgb_color:
              - 0
              - 0
              - 0```
floral marten
#

You've got big problems with whitespace alignment, and too many list items.
Did you write this all in YAML by hand?

runic goblet
#

Yes, I did. It looks good when looking at it in Notepad++

floral marten
#
    sequence:
      - alias: "Turn on Shaun's nightstand"
        action: ...
     - alias: "Wait 100ms"

All items in a list need to have the same indentation level. The second item here has one whitespace too few.

#
-     - alias: "Wait 100ms"
-       - delay:
-           milliseconds: 100
+     - alias: "Wait 100ms"
+       delay:
+         milliseconds: 100
#

This should be one list item, not two, as it describes a single sequence item with two properties, an alias, and a delay.
All the keys of the object need to have the same indentation level.

#
     - alias: "Set color and brightness of Shaun's nightstand"
        action: light.turn_on

Also wrong

#

That should give you a start for what kind of issues you need to fix. (The UI editor would have maybe made this easier)

runic goblet
#

Unfortunately, I can't use the UI editor

floral marten
#

I see. (Any reason why you'd care to share?)
You can of course do this in YAML as well.

runic goblet
#

Because I'm used to writing code in individual functions so all my automations are broken apart into individual automations files. So they are not stored in automations.yaml

#

Ok, closer. Now I need to remember how to get a group state to work. "mapping values are not allowed here"

#

Ok, since I apparently can't think or Google today. How do I re-write

    conditions:
      condition: state
        entity_id: {{ state('group.bedtimephones') }}
        state: 'home'``` for a script
cobalt needle
#

You can't use templates in entity_id:. If you are just providing a static entity_id, just type in group.bedtimephones directly without the template syntax. If you need to dynamically provide the entity_id, use a template condition with value_template: "{{ is_state(some_var, 'home') }}"

runic goblet
#

I did try

      condition: state
        entity_id: group.bedtimephones
        state: 'home'````
and got the same error, let me try 
```yaml
value_template: "{{ is_state(''group.bedtimephones'', 'home') }}"```
floral marten
#

FYI a yaml key value can be either a string, or an object, but not both.
Valid:

key: foo

Valid:

key: 
  this: that

Not valid:

key: foo
  this: that
runic goblet
#

2025-03-18 08:09:32.314 ERROR (SyncWorker_0) [homeassistant.util.yaml.loader] mapping values are not allowed here
in "/config/automations/bedtimemasterbedroom.yaml", line 6, column 18

#

What is annoying, there is a firmware upgrade for the bulbs that this deals with but I cannot apply it with ZHA. Need to use Zigbee2mqtt which doesn't work with my adapter

runic goblet
#

I got a new Zigbee stick so I can use Zigbee2mqtt, are 2 hour long updates normal?