Script and Template Light Issue

I have this UFO-R11 infrared blaster which works fine, when I send a code directly in devices → manage zigbee device
cluster: “ZosungIRControl (Endpoint id: 1, Id: 0xe004, Type: in)”
commands: “IRSend (id: 0x0002)”
→ can control my 2 remote controlled ceiling lights at once

So I thought I create a script in config/scripts.yaml and a template light.

configuration.yaml content:

default_config:

frontend:
  themes: !include_dir_merge_named themes/

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
template: !include templates.yaml

scripts.yaml content:

ir_send_ufor11_0:
  alias: IR Send UFO-R11
  mode: single

  fields:
    code:

  sequence:
    - service: zha.issue_zigbee_cluster_command
      data:
        ieee: XX:XX:XX:XX:XX:XX:XX:XX (address like in the UI)
        endpoint_id: 1
        cluster_id: 57348
        cluster_type: in
        command: 2
        command_type: server
        params:
          - "{{ code }}"

Then I have a input boolean
input_boolean.wohnzimmer_deckenlampen_zustand (ceiling lights state)

templates.yaml content:

- light:
    - name: Wohnzimmer Deckenlampen
      unique_id: wohnzimmer_deckenlampen

      state: "{{ is_state('input_boolean.wohnzimmer_deckenlampen_zustand', 'on') }}"

      turn_on:
        - service: script.ir_send_ufor11_0
          data:
            code: "<on-command-string_confirmed-as-working>"
        - service: input_boolean.turn_on
          target:
            entity_id: input_boolean.wohnzimmer_deckenlampen_zustand

      turn_off:
        - service: script.ir_send_ufor11_0
          data:
            code: "<off-command-string_confirmed-as-working>"
        - service: input_boolean.turn_off
          target:
            entity_id: input_boolean.wohnzimmer_deckenlampen_zustand

I have reloaded all configurations in developer tools.

In developer tools → states I can see:
script.ir_send_ufor11_0
IR Send UFO-R11
With state “unknown” (is this ok?)

Now when I try to toggle the light in the area’s UI I get a message:
“Action light.turn_off uses action script.ir_send_ufor11_0 which was not found.”

What am I getting wrong?

verify the action name in settings → developer tools → actions is correct. Select the script action, then swap to yaml mode to see the name of the action.

1 Like

You should be seeing an error for that script since the code field is None…

At least give it a name… but since you haven’t provided a default in your template, you should really mark it as required as well.

ir_send_ufor11_0:
  alias: IR Send UFO-R11
  mode: single
  fields:
    code:
      name: Code
      required: true
  sequence:
    - service: zha.issue_zigbee_cluster_command
      data:
        ieee: XX:XX:XX:XX:XX:XX:XX:XX (address like in the UI)
        endpoint_id: 1
        cluster_id: 57348
        cluster_type: in
        command: 2
        command_type: server
        params:
          - "{{ code }}"
2 Likes

Ok, I am using your version now and when toggling the light I get:
Failed to perform the action light/turn_on. expected dict for dictionary value @ data[‘params’]

When I use

params:
          code: "{{ code }}"

just nothing happens.

Does params expect a dictionary or a list? Your first post showed a list, now you’re using a dictionary…

1 Like

Yes, the script is now there under “Actions” with the latest version I posted. But it doesn’t do anything. And I also can’t send anything there:

action: script.ir_send_ufor11_0
data:
  params:
    code: "mycode"

→ “This action requires field code, which must be provided under 'data:”

action: script.ir_send_ufor11_0
data:
  code: "mycode"

→ “Failed to perform the action script.ir_send_ufor11_0. expected dict for dictionary value @ data[‘params’]. Got None”

:smile:

I changed it to a dictionary because the error message when toggling was
Failed to perform the action light/turn_on. expected dict for dictionary value @ data[‘params’]

I’m not 100% sure what the script needs to look like, this is how I send codes successfully:

Based on what you have shared and what a few older posts show, it does look like it should be a dictionary. I thought it had been fixed, but I have a vague memory of there being an issue with using templates for sub-properties in action calls…

So, if the following doesn’t work:

service: zha.issue_zigbee_cluster_command
data:
  ieee: XX:XX:XX:XX:XX:XX:XX:XX (address like in the UI)
  endpoint_id: 1
  cluster_id: 57348
  cluster_type: in
  command: 2
  command_type: server
  params:
    code: "{{ code }}" 

Try templating params completely:

service: zha.issue_zigbee_cluster_command
data:
  ieee: XX:XX:XX:XX:XX:XX:XX:XX (address like in the UI)
  endpoint_id: 1
  cluster_id: 57348
  cluster_type: in
  command: 2
  command_type: server
  params: "{{ {'code': code} }}" 

Try the action directly in the Action tool without the templating so that you know what works in script syntax.

2 Likes

Perfect, this part solved it:

params: "{{ {'code': code} }}" 

Works like a charm now.
Thanks a lot. :slightly_smiling_face::+1: