How do you pass Variables from Conversation Intent into A Script

hi i cant figure it out
so i have 6 Broadlink IR Remotes at moment in each room for a Satellite Receiver and TV

this is the current code i have


conversation:
  intents:
    cnn:
      - "cnn"

intent_script:
  cnn:
    description: "Change Channel To CNN."
    action:
      - service: script.cnn
        data: {}
    speech:
      text: "Done"

now it works for basiclly… i have issues with Voice assistant recongizing ,my voice and wake up words…

but i want it it to pass the variable of the remote.Broadlinkxxxxxx

so if your in master bedroom you just say “CNN”
if your in bedroom 2 Say CNN and it pass’s remote variable… so you dont have like 6 CNN Script files… x every channel you wanna save… with a name…

how can i pass variables for this

and my cnn script is

alias: "!!CNN"
sequence:
  - service: remote.send_command
    metadata: {}
    data:
      delay_secs: 0.4
      hold_secs: 0
      device: Satellite
      command: 1
      num_repeats: 1
    target:
      entity_id: remote.broadlink_rm4_pro_bedroom
  - service: remote.send_command
    metadata: {}
    data:
      delay_secs: 0.4
      hold_secs: 0
      command: 5
      device: Satellite
      num_repeats: 1
    target:
      entity_id: remote.broadlink_rm4_pro_bedroom
  - service: remote.send_command
    metadata: {}
    data:
      num_repeats: 1
      delay_secs: 0.4
      hold_secs: 0
      device: Satellite
      command: 7
    target:
      entity_id: remote.broadlink_rm4_pro_bedroom
  - service: remote.send_command
    metadata: {}
    data:
      num_repeats: 1
      delay_secs: 0.4
      hold_secs: 0
      device: Satellite
      command: 8
    target:
      entity_id: remote.broadlink_rm4_pro_bedroom
description: ""

if there is a better way to do this be great to learn too

I think that kind of thing is more suited to being set up as an automation rather than an intent script:

alias: "!!CNN"
trigger:
  - platform: conversation
    command:
      - cnn
    variables:
      channel_command: "{{ [1,5,7,8] }}"
condition: []
action:
  - variables:
      remote: |
        {{ states.remote 
        | selectattr('entity_id', 'in', area_entities(area_id(trigger.device_id)))
        | map(attribute='entity_id') | first  }}
  - repeat:
      for_each: "{{ channel_command }}" 
      sequence:
        - service: remote.send_command
          metadata: {}
          data:
            delay_secs: 0.4
            hold_secs: 0
            command: "{{ repeat.item }}"
            device: Satellite
            num_repeats: 1
          target:
            entity_id: "{{ remote }}"
mode: parallel

Obviously, if you have areas with multiple remotes, you will need to use a more specific template to get the value for remote

@Didgeridrew ok thats cool that seems to be working
ya i was trying to do like

remote.broadlinlixxxxx{{ area }}

to passthe area name and i was renaming the remotes to the area room

as i had another post i was trying to pass Variables in an entity card so i can just change 2 fields but no reply i guessing u cant do it… only seems button card template and i neeeded it to work for generic remote template… but doesnt seem to be a varibles function for enity

and then i struggling with this voice… making googling voices the default khumputer and fritz just doesnt 100% recongize i made posts buit no one replied … guessing no one new the answer… i still new at this voice stuff trying to get it to work
as id like to get it to say turn off light in each room but it keeps saying it doesnt know what to do
so least the cnn works lol baby steps (:

If you’ve standardized your naming convention like that, you could use something like the following to set the value for remote:

action:
  - variables:
      remote: |
        {% set area = (area_name(trigger.device_id))|slugify %}
        remote.broadlink_rm4_pro_{{area}}

Almost none of the core dashboard cards accept templates in any way. There are custom cards like Custom Button, Auto Entities, and Mushroom that allow templating.

@Didgeridrew ah ok… i was also trying to make the same script accept Button press’s

so i have custom-generic-remote card i think it is… but its not the custom button card…
question i have is
1… can you have 2 template cards custom-generic-remote but use the custom-button card variables…?
if not

2… how can i do the custom button card then
id like do
variable:
room: bedroom 1
room: bedroom 2
room: living room
as the examples

and here is what i tried with custom button it didnt work

type: custom:auto-entities
variables:
  areas: living room
card:
  type: entities
filter:
  include:
    - name: TV - FAVORITES*
  exclude: []

and here is what i tried to alter my script

alias: TV = Favorites - Test
description: ""
trigger:
  - platform: conversation
    command:
      - cnn
    variables:
      channel_command: "{{ [1,5,7,8] }}"
  - platform: state
    entity_id:
      - input_button.tv_favorites_cnn
    attribute: "{{ areas }}"
condition: []
action:
  - variables:
      remote: >
        {{ states.remote 

        | selectattr('entity_id', 'in',
        area_entities(area_id(trigger.device_id)))

        | map(attribute='entity_id') | first  }}
  - repeat:
      for_each: "{{ channel_command }}"
      sequence:
        - service: remote.send_command
          metadata: {}
          data:
            delay_secs: 0.4
            hold_secs: 0
            command: "{{ repeat.item }}"
            device: Satellite
            num_repeats: 1
          target:
            entity_id: "{{ remote }}"
        - service: remote.send_command
          metadata: {}
          data:
            delay_secs: 0.4
            hold_secs: 0
            command: "{{ repeat.item }}"
            device: TV_VIZIO
            num_repeats: 1
          target:
            entity_id: "{{ remote }}"
mode: parallel

i tried to do it in nodered too but got stuck so wasnt sure what to do

i also tried changing {{areas}} to {{ area_id}} but didnt work so i not sure how to make that work

Here’s how I would approach it…

  1. Take the Action block from the automation and use that as your script. If you want to use it with Dashboard buttons and Conversation triggers, it will require some modifications:
#script
alias: Room Aware Remote Commands 
fields:
  active_area:
    name: Area
    description: The area/room the command should be executed in.
    selector:
      area:
  channel_command:
    name: Channel Command
    description: A comma-separated list for Broadlink to control Satellite receiver's command variable.
    example: "1, 5, 7, 8"
    selector:
      text: 
sequence:
  - variables:
      remote: |
        {% set area = area_name(active_area) | slugify if active_area in areas() 
        else active_area | slugify %} 
        remote.broadlink_rm4_pro_{{area}}
  - repeat:
      for_each: |
        {{ channel_command if channel_command is list 
        else channel_command.split(",") | map('trim') | map('int') | list }} 
      sequence:
        - service: remote.send_command
          metadata: {}
          data:
            delay_secs: 0.4
            hold_secs: 0
            command: "{{ repeat.item }}"
            device: Satellite
            num_repeats: 1
          target:
            entity_id: "{{ remote }}"
mode: parallel
  1. Change the Conversation-based automation to pass the desired data to the script:
alias: "Conversation - Channel Commands"
trigger:
  - platform: conversation
    command:
      - cnn
    variables:
      channel_command: "{{ [1,5,7,8] }}"
condition: []
action:
  - service: script.room_aware_remote_commands
    data:
      active_area: "{{ area_id(trigger.device_id) }}"
      channel_command: "{{ channel_command }}"
mode: parallel
  1. Call the script from your card’s action. With the Generic remote control it would look something like:
buttons:
...
  button0:
    call: script.room_aware_remote_commands
    data:
      active_area: "bedroom1"
      channel_command: "1, 5, 7, 8"
....

@Didgeridrew sorry delay wasnt home to test
couple things
1… i dont have all Pro models 1 pro rest are mini’s
how can i change it
the active_area: back to

        {{ states.remote 
        | selectattr('entity_id', 'in', area_entities(area_id(trigger.device_id)))
        | map(attribute='entity_id') | first  }}

that worked for the converstation

this is what i did so far for Living room

Generic remote card i did

buttons:
  one:
    call: script.room_aware_remote_commands
    data:
      active_area: living room
      channel_command: 1, 5, 7, 8

the script i set it to urs i didnt modify it

alias: Room Aware Remote Commands
fields:
  active_area:
    name: Area
    description: The area/room the command should be executed in.
    selector:
      area: null
  channel_command:
    name: Channel Command
    description: >-
      A comma-separated list for Broadlink to control Satellite receiver's
      command variable.
    example: 1, 5, 7, 8
    selector:
      text: null
sequence:
  - variables:
      remote: >
        {% set area = area_name(active_area) | slugify if active_area in
        areas() 

        else active_area | slugify %} 

        remote.broadlink_rm4_pro_{{area}}
  - repeat:
      for_each: |
        {{ command_channel if command_channel is list 
        else command_channel.split(",") | map('trim') | map('int') | list }} 
      sequence:
        - service: remote.send_command
          metadata: {}
          data:
            delay_secs: 0.4
            hold_secs: 0
            command: "{{ repeat.item }}"
            device: Satellite
            num_repeats: 1
          target:
            entity_id: "{{ remote }}"
mode: parallel

and here is the automation i altered a bit


alias: "Conversation - Channel Commands - CNN"
trigger:
  - platform: conversation
    command:
      - cnn
    variables:
      channel_command: "{{ [1,5,7,8] }}"
condition: []
action:
  - service: script.room_aware_remote_commands
    data:
      active_area: "{{ area_id(trigger.device_id) }}"
      channel_command: "{{ channel_command }}"
mode: parallel

i only played with the area of the broadlink{{area}}

but since some
are broadlink_rm4_mini
and broadlink_rm4_pro
i wanted to try your orginal setup…

and i appreciate the help you given… i like that idea of the remote with the Area.

thats what i tried to get help with in another post but no one replied

as i wanted like 5 remotes and instead of find and replace the broadlink name was to pass a variable of the room it was in

The area_entities() function will accept both area names and area IDs, so you just have to drop the active_area variable into the original template instead of area_id(trigger.device_id):

#script
alias: Room Aware Remote Commands
fields:
  active_area:
    name: Area
    description: The area/room the command should be executed in.
    selector:
      area:
  channel_command:
    name: Channel Command
    description: >-
      A comma-separated list for Broadlink to control Satellite receiver's
      command variable.
    example: "1, 5, 7, 8"
    selector:
      text:
sequence:
  - variables:
      remote: |
        {{ states.remote | selectattr('entity_id', 'in', area_entities(active_area))
        | map(attribute='entity_id') | first  }}
  - repeat:
      for_each: |
        {{ channel_command if channel_command is list 
        else channel_command.split(",") | map('trim') | map('int') | list }} 
      sequence:
        - service: remote.send_command
          metadata: {}
          data:
            delay_secs: 0.4
            hold_secs: 0
            command: "{{ repeat.item }}"
            device: Satellite
            num_repeats: 1
          target:
            entity_id: "{{ remote }}"
mode: parallel

@Didgeridrew
so far i havent been able to get it to work for whatever reason i did change the script

{{ command_channel if command_channel is list 
        else command_channel.split(",") | map('trim') | map('int') | list }} 

to

{{ channel_command if channel_command is list 
        else channel_command.split(",") | map('trim') | map('int') | list }} 

also i notice nulls added where you didnt add…

is it possibly not sending from the genic remote card?

alias: Room Aware Remote Commands
fields:
  active_area:
    name: Area
    description: The area/room the command should be executed in.
    selector:
      area: null
  channel_command:
    name: Channel Command
    description: >-
      A comma-separated list for Broadlink to control Satellite receiver's
      command variable.
    example: 1, 5, 7, 8
    selector:
      text: null
sequence:
  - variables:
      remote: >
        {{ states.remote | selectattr('entity_id', 'in',
        area_entities(active_area))

        | map(attribute='entity_id') | first  }}
  - repeat:
      for_each: |
        {{ channel_command if channel_command is list 
        else channel_command.split(",") | map('trim') | map('int') | list }} 
      sequence:
        - service: remote.send_command
          metadata: {}
          data:
            delay_secs: 0.4
            hold_secs: 0
            command: "{{ repeat.item }}"
            device: Satellite
            num_repeats: 1
          target:
            entity_id: "{{ remote }}"
mode: parallel

i also made a new area called “Building Bedroom” to try a new room name
but i wondering maybe that generic remote card isnt sending the values? here is the remote

type: custom:generic-remote-control-card
name: Bedroom
remote_template: samsungtv
variables:
  #TV_name: TV_VIZIO
  #Remote: remote.broadlink_rm4_mini_bedroom
buttons:
  power:
    call: script.room_aware_remote_commands
    data:
      active_area: Building Bedroom
      channel_command: 1, 5, 7, 8
  one:
    call: script.room_aware_remote_commands
    data:
      active_area: Building Bedroom
      channel_command: 1, 5, 7, 8

and or can this be done

type: custom:generic-remote-control-card
name: Bedroom
remote_template: samsungtv
variables:
  #TV_name: TV_VIZIO
  #Remote: remote.broadlink_rm4_mini_bedroom
  active_area: Building Bedroom
buttons:
  power:
    call: script.room_aware_remote_commands
    data:
      channel_command: 1, 5, 7, 8
  one:
    call: script.room_aware_remote_commands
    data:
      channel_command: 1, 5, 7, 8

is there a way to see like Debug where it stops or what values not passing like a line by line debugger or thats outta scope of HA

im sure its probably Indent spacing too as i found if i didnt have the right spaces it causes issues