Help splitting up script files

Tags: #<Tag:0x00007f3274214118> #<Tag:0x00007f327119bf90>

I need some help with setting up script within my configuration and splitting up into different files.
I’m running version 2021.1.1 of Home Assistant.

I have the following in my configuration.yaml:

---
homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: !secret homeassistant_latitude
  longitude: !secret homeassistant_longitude
  # HA internal and external URL's
  internal_url: !secret homeassistant_internal_url
  external_url: !secret homeassistant_external_url
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 10
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/Amsterdam
  # Customization #
  customize: !include_dir_merge_named customizations/entities
  # Lets me custimize all entities in a domain
  # customize_domain: !include_dir_merge_named customizations/domains
  # Packages #
  packages: !include_dir_named components/packages
  # Whitelist #
  # whitelist_external_dirs: !secret whitelist_dir_config
  # Auth Providers #
  auth_providers:
    - type: homeassistant
    - type: trusted_networks
      trusted_networks:
        - 192.168.32.0/24

# Configure a default setup of Home Assistant (frontend, api, etc)
# default_config:

config:

frontend:

logbook:

# Discovery integrations
ssdp:
zeroconf:

person:

sun:

# System integration
system_health:

updater:

# Enables map
map:

# Configures logging
logger:
  default: info
  logs:
    pydeconz: debug
    homeassistant.components.deconz: debug

# Configures history
history:

# Discover some devices automatically
discovery:

# Enable IOS frontend
ios:

# Enable mobile_app
mobile_app:

#https://www.home-assistant.io/lovelace/yaml-mode/
lovelace:
  mode: yaml
  resources:
  - url: /local/community/mini-media-player/mini-media-player-bundle.js
    type: module
  - url: /local/community/lovelace-layout-card/layout-card.js
    type: module
  - url: /local/community/battery-state-card/battery-state-card.js
    type: module
  - url: /local/community/vertical-stack-in-card/vertical-stack-in-card.js
    type: module
  - url: /local/community/lovelace-auto-entities/auto-entities.js
    type: module
  - url: /local/community/lovelace-fold-entity-row/fold-entity-row.js
    type: module
  - url: /local/community/entity-attributes-card/entity-attributes-card.js
    type: module
  - url: /local/community/lovelace-card-mod/card-mod.js
    type: module

# integrate ZiggoNext https://github.com/Sholofly/ZiggoNext
ziggonext:
  username: !secret ziggo_username
  password: !secret ziggo_password

# integrate spotify
spotify:
  client_id: !secret spotify_client_id
  client_secret: !secret spotify_client_secret

# config mqtt broker
mqtt:
  broker: 192.168.32.20
  username: !secret mqtt_broker_user
  password: !secret mqtt_broker_password

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
http:
  # base_url: https://hensl-home.duckdns.org:8123
  # ssl_certificate: /ssl/fullchain.pem
  # ssl_key: /ssl/privkey.pem

# Moved to UI Integration
# hue:
#   bridges:
#     - host: 192.168.32.21
#       allow_unreachable: true
#       allow_hue_groups: true

# config buienradar
weather:
  - platform: buienradar
    name: 'buienradar_groningen'
    latitude: !secret homeassistant_latitude
    longitude: !secret homeassistant_longitude
    forecast: true

camera:
  - platform: buienradar
    name: 'buienradar_groningen'
    dimension: 512
    delta: 600
    country_code: NL

# Zones configuration
zone:
  - name: Home
    latitude: !secret homeassistant_latitude
    longitude: !secret homeassistant_longitude
    radius: 150
    icon: mdi:account-multiple
  - name: Work - Kevin
    latitude: !secret work_kevin_latitude
    longitude: !secret work_kevin_longitude
    radius: 200
  - name: Work - Erika
    latitude: !secret work_erika_latitude
    longitude: !secret work_erika_longitude
    radius: 350

input_select:
  active_cube_side:
    name: Active Cube side
    options:
      - none
      - side1
      - side2
      - side3
      - side4
      - side5
      - side6
    initial: none

input_boolean:
  bedtime_active:
    name: Bedtime is active
    initial: 'off'
    icon: mdi:bed
  # trash_reminder:
  #   name: Trash reminder enabled
  #   initial: 'on'

google_assistant:
  project_id: homeassistant-608aa
  service_account: !include SERVICE_ACCOUNT.json
  report_state: true
  expose_by_default: false
  exposed_domains:
    - group
    - switch
    - light
    - sensor

nest:
  client_id: !secret nest_client_id
  client_secret: !secret nest_client_secret
  # "Project ID" in the Device Access Console
  project_id: !secret nest_project_id
  # Provide the full path exactly as shown under "Subscription name" in Google Cloud Console
  subscriber_id: !secret nest_subcriber_id

alarm_control_panel:
  - platform: manual
    name: Home Alarm
    code: '9999'
    arming_time: 5
    delay_time: 5
    trigger_time: 5
    disarmed:
      trigger_time: 5
    armed_home:
      arming_time: 5
      delay_time: 5
    armed_away:
      arming_time: 5
      delay_time: 5

# # Text to speech
tts:
  - platform: google_translate

# group: !include groups.yaml
light:
  - platform: group
    name: bedroom_nightstand_lights
    entities:
      - light.bedroom_nightstand_kevin
      - light.bedroom_nightstand_erika

sensor: !include_dir_merge_list components/sensors

switch: !include_dir_merge_list components/switches

automation: !include_dir_merge_list  components/automations

media_player: !include_dir_merge_list components/media_players

script: !include_dir_merge_list components/scripts

And the following script in components/scripts/bedtime.yaml:

activate_bedtime:
  alias: Script activate bedtime
  sequence:
    - service: notify.mobile_app_iphone_van_kevin
      data:
        title: "[HomeAssistant] Scene"
        message: "Bedtime activated"
    - service: light.turn_off
      data:
        entity_id:
          - light.living_room_stand_2
          - light.living_room_stand_3
        transition: 10
    - service: light.turn_on
      data:
        entity_id:
          - light.living_room_stand_1
        brightness_pct: 10
    - service: media_player.turn_off
      data:
        entity_id:
          - media_player.stb_arris_uhd
          - media_player.tv

For some reason I’m getting a error that HA isn’t able to setup groups. Am I doing something wrong?
The error that I find in the logs:

Invalid config for [group]: [alias] is an invalid option for [group]. Check: group->group->activate_bedtime->alias. (See ?, line ?). Please check the docs at https://www.home-assistant.io/integrations/group

If anyone can help me with this issue that would be great!

Show us your whole configuration.yaml

Based on the bedtime.yaml, that should be loaded as a list, not a dictionary as include_dir_merge_named does.
Try instead:
script: !include_dir_merge_list component/scripts

@qoheleth Does that mean that I should change the contents of bedtime.yaml also to a list?
After only changing my configuration to:

script: !include_dir_merge_list components/scripts

I end up with the same error:

Invalid config for [group]: [alias] is an invalid option for [group]. Check: group->group->activate_bedtime->alias. (See ?, line ?). Please check the docs at https://www.home-assistant.io/integrations/group

@mf_social I edited the post with my full configuration.yaml

Post the script file with the bedtime script, it could be malformed and someone might be able to debug it for you.

@CO_4X4 Underneath the full configuration.yaml I posted the contents of the script file

@123 That is by design. The only “group” that I use is under the light domain.
I am also working to get the Google Assistant integration working. I’ll change that integration and see if it works

If it’s it by design then there should be no references to groups elsewhere, like in google_assistant.

I removed the line - group and I still have the same error.
line in configuration.yaml now:

script: !include_dir_merge_list components/scripts

contents of components/scripts/bedtime.yaml:

activate_bedtime:
  alias: Script activate bedtime
  sequence:
    - service: notify.mobile_app_iphone_van_kevin
      data:
        title: "[HomeAssistant] Scene"
        message: "Bedtime activated"
    - service: light.turn_off
      data:
        entity_id:
          - light.living_room_stand_2
          - light.living_room_stand_3
        transition: 10
    - service: light.turn_on
      data:
        entity_id:
          - light.living_room_stand_1
        brightness_pct: 10
    - service: media_player.turn_off
      data:
        entity_id:
          - media_player.stb_arris_uhd
          - media_player.tv

What’s in your packages? Something somewhere is trying to load that script as a group through some kind of cyclical include.

1 Like

From reading the message it sure seems like there is a GROUP issue rather than SCRIPT. Is it possible you saved the yaml to the wrong folder where you store groups?

@mf_social Thank you! That was the issue indeed. I had an old debug file with a group include. Completely overlooked that one.

1 Like

@123 The problem was the file located at components/packages/script.yaml. This file I copied some months ago to do some testing with script. The contents of that file was:

---
# Groups allow the user to combine multiple entities into one.
# This loads up my custom created groups
#
# https://www.home-assistant.io/components/group/
#

group: !include_dir_merge_named ../scripts

I didn’t got to the point that time that I actually could test some scripts. That’s the reason why I completly overlooked this file.
The include pointed to the relative directory where I had stored the bedtime.yaml. This is the cause of the error that I saw in the logs.

@123 - you’ve missed something somewhere along the line. It had nothing to do with the group: declarations really.

The problem was when OP tried to include the scripts he accidentally used a path that was already in use for a group declaration in a package that he’d forgotten about.

That’s all there is to it. The group declaration in configuration.yaml made no difference whatsoever, and neither did his use (or otherwise) of default_config.

That’s not the case, the package would still have been merged on boot and the problem would still have emerged.

The problem here isn’t where the keys are, the problem is keeping track of one’s configuration and organising it well.

The ease of spotting it wasn’t lost. It only took me two posts, and one of those was only necessary because the OP forgot to post sufficient of his configuration when opening the thread.

The only reason this thread is 22 posts long (including this one) is because of contributers going down the wrong rabbit holes.

?

Given multiple identical domain keys, the last one takes precedence. The package is defined at the beginning of configuration.yaml whereas group was at the end. You’re saying the one in package would have taken precedence?

That’s not how packages work. You can use multiple domains in multiple packages. That’s the whole point of packages.

Given multiple identical domains in packages, what is each one’s scope?

It all gets merged in to one long single document in the end.

If I declare one group directly in configuration.yaml, one in package_1.yaml and two in package_2.yaml, then when I boot homeassistant I will have 4 groups.

You can see the result of the merge by running a configuration check with an added switch, but I can’t remember the exact command off the top of my head.

To use my example above

configuration.yaml

homeassistant:
  packages:  !include_dir_named packages

group:
  group_one:
    entities: [ ]

packages/package1. yaml

group:
  group_two:
    entities: [ ]

packages/package2.yaml

group:
  group_three:
    entities: [ ]

  group_four:
    entities: [ ]

Once this is merged on boot, what homeassistant will ‘see’ is a single yaml document containing

group:
  group_one:
    entities: [ ]
  group_two:
    entities: [ ]
  group_three:
    entities: [ ]
  group_four:
    entities: [ ]
2 Likes