Problem calling a script from an automation when renaming the script

Hello,
I have been trying to debug for a while a problem with an Automation calling a script.

I have the automation pasted at the bottom of this message.

I have a script named like shown in the Automation.

A while ago, I renamed two scripts. Script called script.scenecontrol_LivingRoom_scene001 was renamed script.scenecontrol_LivingRoom_scene005 and vice-versa.

Now, every time I press the button that should be calling script 1 is calling script 5…

You can see in this capture that it is supposed to be calling the right script:

But the trace for Script 5 is empty… and there is a trace on script 1:

It is almost as if at some point, the name of the script was changed to call a UUID and no mater what the name is, it calls the original first called script…

What am I doing wrong? Is this a bug? how to report such a bug if it is one?

Automation:

alias: Automation_LivingRoom_ZoozController
description: Zooz Controller for Living Room
trigger:
  - platform: event
    event_type: zwave_js_value_notification
    event_data:
      command_class_name: Central Scene
      device_id: dfa2f03da2ebe7fe45ed838e3282d127
condition: []
action:
  - variables:
      scene_id: "{{ trigger.event.data.label }}"
      attribute_id: "{{ trigger.event.data.value }}"
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ scene_id == 'Scene 001' }}"
        sequence:
          - service: script.scenecontrol_LivingRoom_scene001
            data:
              attribute_id: "{{ attribute_id }}"
      - conditions:
          - condition: template
            value_template: "{{ scene_id == 'Scene 002' }}"
        sequence:
          - service: script.scenecontrol_LivingRoom_scene002
            data:
              attribute_id: "{{ attribute_id }}"
      - conditions:
          - condition: template
            value_template: "{{ scene_id == 'Scene 003' }}"
        sequence:
          - service: script.scenecontrol_LivingRoom_scene003
            data:
              attribute_id: "{{ attribute_id }}"
      - conditions:
          - condition: template
            value_template: "{{ scene_id == 'Scene 004' }}"
        sequence:
          - service: script.scenecontrol_LivingRoom_scene004
            data:
              attribute_id: "{{ attribute_id }}"
      - conditions:
          - condition: template
            value_template: "{{ scene_id == 'Scene 005' }}"
        sequence:
          - service: script.scenecontrol_LivingRoom_scene005
            data:
              attribute_id: "{{ attribute_id }}"
mode: single
  • Go to your list of scripts (settings → automations & scenes → select the ‘scripts’ tab)
  • Select the three dots to the right of the script called scenecontrol_LivingRoom_scene001
  • Select ‘information’ from the menu
  • in the window that pops up, select the gear in the upper right corner

What does it say in the box labeled entity_id?

Thanks for your response!
image

And there is the problem…
Something seems broken… or… let me try to understand… The name has nothing to do anywhere… and really, when I call a service script.scenecontrol… it is the entity and not the name?

It is the entity.

The entity_id must be unique, be all lowercase, and not have any spaces or special characters besides underscores. The name can be whatever you want.

When you refer to an entity in the code you must use the entity_id. When you rename an entity you must take care to understand which one you are changing.

Click on the trigger, then click on the changed variables tab and paste the results here.

image

Do the same for the variables step.

also, that should be all lowercase.

I tried renaming the entity names… but now everything is a mess…
When I select scene005 in the Automation, it shows the name of 001…

I am thinking I am going to delete those two scripts and start again…

Will try to do your images before I re do it…

You can make this alot easier on yourself if you lean into templates.

alias: Automation_LivingRoom_ZoozController
description: Zooz Controller for Living Room
trigger:
  - platform: event
    event_type: zwave_js_value_notification
    event_data:
      command_class_name: Central Scene
      device_id: dfa2f03da2ebe7fe45ed838e3282d127
variables:
  scene_id: "{{ trigger.event.data.label }}"
  attribute_id: "{{ trigger.event.data.value }}"
  script: "script.scenecontrol_livingroom_scene{{ scene_id.split(' ')[-1] }}"
action:
- service: "{{ script }}"
  data:
    attribute_id: "{{ attribute_id }}"

I’m going to give it a try…
Quick question… you have variables as top level whereas I have it under action. What is the difference?

trigger:
  - platform: event
    event_type: zwave_js_value_notification
    event_data:
      command_class_name: Central Scene
      device_id: dfa2f03da2ebe7fe45ed838e3282d127
condition: []
action:
  - variables:
      scene_id: "{{ trigger.event.data.label }}"
      attribute_id: "{{ trigger.event.data.value }}"
  - choose:
      - conditions:

When you have it at the root level, it runs before conditions but after the trigger. When you have it in the action section, it runs after conditions.

So this:

alias: Automation_LivingRoom_ZoozController
description: Zooz Controller for Living Room
trigger:
  - platform: event
    event_type: zwave_js_value_notification
    event_data:
      command_class_name: Central Scene
      device_id: dfa2f03da2ebe7fe45ed838e3282d127
condition: []
action:
  - variables:
      scene_id: "{{ trigger.event.data.label }}"
      attribute_id: "{{ trigger.event.data.value }}"
      script: script.scenecontrol_entryhall_scene{{ scene_id.split(' ')[-1] }}
  - service: "{{ script }}"
    data:
      attribute_id: "{{ attribute_id }}"
mode: single

And this:

alias: Automation_LivingRoom_ZoozController
description: Zooz Controller for Living Room
trigger:
  - platform: event
    event_type: zwave_js_value_notification
    event_data:
      command_class_name: Central Scene
      device_id: dfa2f03da2ebe7fe45ed838e3282d127
variables:
  scene_id: "{{ trigger.event.data.label }}"
  attribute_id: "{{ trigger.event.data.value }}"
  script: script.scenecontrol_entryhall_scene{{ scene_id.split(' ')[-1] }

action:
  - service: "{{ script }}"
    data:
      attribute_id: "{{ attribute_id }}"
mode: single

are equivalent only because the conditions are empty? But if I wanted to add a condition to the Automation and I need a variable for the condition, I would have to add it before… right?
I also assume that (if it is possible) if I add a variable in the condition, the variable will only be valid in the scope of the conditions?

Thanks a lot!

Yes and no. There’s subtle differences, but you don’t need to know about them for your current situation. In your case, that means yes.

Yes

You can’t add a variable inside the conditions. So this isn’t even possible. You can only add variables at the root level or inside actions. Variables inside the root level are available everywhere (except triggers). Variables inside actions are only available after that action runs.

Thanks so much!

In reality, the template you gave me is what I wanted to do in the first place, but I could not get the syntax correct for calling the script and I had to do it the clunky way…

Now I get this:
image

image

Which is what I want… Although for some reason it still calling the wrong script:

[Edit: I am restarting to see if there is any change]

Are you sure you don’t have something else running this script? There’s no way HA will run a script with a different name from the automation I posted. The results of it are as expected, and the entity_id has the proper name. So that script is not calling it. You can verify that from the original trace (on top of the changed variable image you showed)

I am puzzled… this is the trace:
image

image

See how it is calling the script 001 but on the trace it says 005?

Yesterday, I renamed the entities… Maybe that is disliked by HA? I have reloaded and restarted HA (but not reboot)

can you click the 3 dots and download the current trace and post it here?

Sure! Thanks for the help!
I am going to do two postings… the first one is the trace of the one above… the second is me pressing other button (different than 1 and 5)

{
  "trace": {
    "last_step": "action/1",
    "run_id": "3e2faf80901d1c24e8a5223ea1d4b2f4",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-03-04T15:28:56.867145+00:00",
      "finish": "2024-03-04T15:28:56.951727+00:00"
    },
    "domain": "automation",
    "item_id": "1693882855807",
    "trigger": "event 'zwave_js_value_notification'",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2024-03-04T15:28:56.867263+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.automation_livingroom_zoozcontroller",
              "state": "on",
              "attributes": {
                "id": "1693882855807",
                "last_triggered": "2024-03-04T15:28:54.939941+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Automation_LivingRoom_ZoozController"
              },
              "last_changed": "2024-03-04T15:28:25.345834+00:00",
              "last_updated": "2024-03-04T15:28:55.010142+00:00",
              "context": {
                "id": "01HR51A2MV8AARKK6958H9B49S",
                "parent_id": "01HR51A2MRRTMA8BMRK3KFHSX6",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "event",
              "event": {
                "event_type": "zwave_js_value_notification",
                "data": {
                  "domain": "zwave_js",
                  "node_id": 7,
                  "home_id": 3926188615,
                  "endpoint": 0,
                  "device_id": "dfa2f03da2ebe7fe45ed838e3282d127",
                  "command_class": 91,
                  "command_class_name": "Central Scene",
                  "label": "Scene 001",
                  "property": "scene",
                  "property_name": "scene",
                  "property_key": "001",
                  "property_key_name": "001",
                  "value": "KeyPressed",
                  "value_raw": 0
                },
                "origin": "LOCAL",
                "time_fired": "2024-03-04T15:28:56.863292+00:00",
                "context": {
                  "id": "01HR51A4GZXFFT8M8PFKBR2WBF",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "description": "event 'zwave_js_value_notification'"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2024-03-04T15:28:56.871633+00:00",
          "changed_variables": {
            "context": {
              "id": "01HR51A4H3358Z1WVN1XFM923F",
              "parent_id": "01HR51A4GZXFFT8M8PFKBR2WBF",
              "user_id": null
            },
            "scene_id": "Scene 001",
            "attribute_id": "KeyPressed",
            "script": "script.scenecontrol_livingroom_scene001"
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2024-03-04T15:28:56.872215+00:00",
          "child_id": {
            "domain": "script",
            "item_id": "scenecontrol_livingroom_scene001",
            "run_id": "7726a8d1899b072219f3188804b24c7e"
          },
          "result": {
            "params": {
              "domain": "script",
              "service": "scenecontrol_livingroom_scene001",
              "service_data": {
                "attribute_id": "KeyPressed"
              },
              "target": {}
            },
            "running_script": true
          }
        }
      ]
    },
    "config": {
      "id": "1693882855807",
      "alias": "Automation_LivingRoom_ZoozController",
      "description": "Zooz Controller for Living Room",
      "trigger": [
        {
          "platform": "event",
          "event_type": "zwave_js_value_notification",
          "event_data": {
            "command_class_name": "Central Scene",
            "device_id": "dfa2f03da2ebe7fe45ed838e3282d127"
          }
        }
      ],
      "condition": [],
      "action": [
        {
          "variables": {
            "scene_id": "{{ trigger.event.data.label }}",
            "attribute_id": "{{ trigger.event.data.value }}",
            "script": "script.scenecontrol_livingroom_scene{{ scene_id.split(' ')[-1] }}"
          }
        },
        {
          "service": "{{ script }}",
          "data": {
            "attribute_id": "{{ attribute_id }}"
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HR51A4H3358Z1WVN1XFM923F",
      "parent_id": "01HR51A4GZXFFT8M8PFKBR2WBF",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Automation_LivingRoom_ZoozController",
      "message": "triggered by event 'zwave_js_value_notification'",
      "source": "event 'zwave_js_value_notification'",
      "entity_id": "automation.automation_livingroom_zoozcontroller",
      "context_id": "01HR51A4H3358Z1WVN1XFM923F",
      "when": 1709566136.867395,
      "domain": "automation"
    },
    {
      "name": "SceneControl_LivingRoom_Scene005",
      "message": "started",
      "entity_id": "script.scenecontrol_livingroom_scene005",
      "context_id": "01HR51A4H3358Z1WVN1XFM923F",
      "when": 1709566136.873022,
      "domain": "script",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    },
    {
      "when": 1709566136.873271,
      "state": "on",
      "entity_id": "script.scenecontrol_livingroom_scene005",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    },
    {
      "when": 1709566136.947888,
      "state": "off",
      "entity_id": "script.scenecontrol_livingroom_scene005",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    },
    {
      "when": 1709566137.381157,
      "state": "on",
      "entity_id": "light.livingroomfan3",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    },
    {
      "when": 1709566137.382328,
      "state": "on",
      "entity_id": "light.livingroomfanlights",
      "icon": "mdi:ceiling-fan-light",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    },
    {
      "when": 1709566137.397431,
      "state": "on",
      "entity_id": "light.livingroomfan4",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    },
    {
      "when": 1709566137.405828,
      "state": "on",
      "entity_id": "light.livingroomfan2",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    },
    {
      "when": 1709566137.424223,
      "state": "on",
      "entity_id": "light.livingroomfan1",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    }
  ]
}

For button 3:

{
  "trace": {
    "last_step": "action/1",
    "run_id": "7044d69f3cb3174c250df51ece9fd419",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-03-04T15:37:03.294874+00:00",
      "finish": "2024-03-04T15:37:03.394310+00:00"
    },
    "domain": "automation",
    "item_id": "1693882855807",
    "trigger": "event 'zwave_js_value_notification'",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2024-03-04T15:37:03.295189+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.automation_livingroom_zoozcontroller",
              "state": "on",
              "attributes": {
                "id": "1693882855807",
                "last_triggered": "2024-03-04T15:28:56.867411+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Automation_LivingRoom_ZoozController"
              },
              "last_changed": "2024-03-04T15:28:25.345834+00:00",
              "last_updated": "2024-03-04T15:28:56.950006+00:00",
              "context": {
                "id": "01HR51A4H3358Z1WVN1XFM923F",
                "parent_id": "01HR51A4GZXFFT8M8PFKBR2WBF",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "event",
              "event": {
                "event_type": "zwave_js_value_notification",
                "data": {
                  "domain": "zwave_js",
                  "node_id": 7,
                  "home_id": 3926188615,
                  "endpoint": 0,
                  "device_id": "dfa2f03da2ebe7fe45ed838e3282d127",
                  "command_class": 91,
                  "command_class_name": "Central Scene",
                  "label": "Scene 003",
                  "property": "scene",
                  "property_name": "scene",
                  "property_key": "003",
                  "property_key_name": "003",
                  "value": "KeyPressed",
                  "value_raw": 0
                },
                "origin": "LOCAL",
                "time_fired": "2024-03-04T15:37:03.288878+00:00",
                "context": {
                  "id": "01HR51RZHRMXWMRACQQWHBTQAT",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "description": "event 'zwave_js_value_notification'"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2024-03-04T15:37:03.303500+00:00",
          "changed_variables": {
            "context": {
              "id": "01HR51RZHYJ8KPF33VNR46PSJ9",
              "parent_id": "01HR51RZHRMXWMRACQQWHBTQAT",
              "user_id": null
            },
            "scene_id": "Scene 003",
            "attribute_id": "KeyPressed",
            "script": "script.scenecontrol_livingroom_scene003"
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2024-03-04T15:37:03.305960+00:00",
          "child_id": {
            "domain": "script",
            "item_id": "scenecontrol_livingroom_scene003",
            "run_id": "56e8157bcd19d0a2823f7913a7c4f6b6"
          },
          "result": {
            "params": {
              "domain": "script",
              "service": "scenecontrol_livingroom_scene003",
              "service_data": {
                "attribute_id": "KeyPressed"
              },
              "target": {}
            },
            "running_script": true
          }
        }
      ]
    },
    "config": {
      "id": "1693882855807",
      "alias": "Automation_LivingRoom_ZoozController",
      "description": "Zooz Controller for Living Room",
      "trigger": [
        {
          "platform": "event",
          "event_type": "zwave_js_value_notification",
          "event_data": {
            "command_class_name": "Central Scene",
            "device_id": "dfa2f03da2ebe7fe45ed838e3282d127"
          }
        }
      ],
      "condition": [],
      "action": [
        {
          "variables": {
            "scene_id": "{{ trigger.event.data.label }}",
            "attribute_id": "{{ trigger.event.data.value }}",
            "script": "script.scenecontrol_livingroom_scene{{ scene_id.split(' ')[-1] }}"
          }
        },
        {
          "service": "{{ script }}",
          "data": {
            "attribute_id": "{{ attribute_id }}"
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HR51RZHYJ8KPF33VNR46PSJ9",
      "parent_id": "01HR51RZHRMXWMRACQQWHBTQAT",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Automation_LivingRoom_ZoozController",
      "message": "triggered by event 'zwave_js_value_notification'",
      "source": "event 'zwave_js_value_notification'",
      "entity_id": "automation.automation_livingroom_zoozcontroller",
      "context_id": "01HR51RZHYJ8KPF33VNR46PSJ9",
      "when": 1709566623.295436,
      "domain": "automation"
    },
    {
      "name": "SceneControl_LivingRoom_Scene003",
      "message": "started",
      "entity_id": "script.scenecontrol_livingroom_scene003",
      "context_id": "01HR51RZHYJ8KPF33VNR46PSJ9",
      "when": 1709566623.310077,
      "domain": "script",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    },
    {
      "when": 1709566623.310539,
      "state": "on",
      "entity_id": "script.scenecontrol_livingroom_scene003",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    },
    {
      "when": 1709566623.388696,
      "state": "off",
      "entity_id": "script.scenecontrol_livingroom_scene003",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Automation_LivingRoom_ZoozController",
      "context_message": "triggered by event 'zwave_js_value_notification'",
      "context_source": "event 'zwave_js_value_notification'",
      "context_entity_id": "automation.automation_livingroom_zoozcontroller"
    }
  ]
}