#Call script with variables from frontend

1 messages · Page 1 of 1 (latest)

rocky holly
#

relevent frontend config:

entities:
  - entities:
      - entity: script.lights_mood
        icon_height: 20px
        name: Cozy lights
        show_icon: false
        show_name: true
        tap_action:
          action: call-service
          service: script.lights_mood
          service_data:
            mood: cozy
            target_room: livingroom

lights_mood script

alias: Lights Moods (Cozy/White)
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ (target_room == \"masterbed\") and (mood == \"cozy\") }}"
        sequence:
          - data:
              entity_id: light.group_masterbed
              hs_color:
                - 268.267
                - 88.235
            service: light.turn_on
      - conditions:
          - condition: template
            value_template: "{{ (target_room == \"masterbed\") and (mood == \"white\") }}"
        sequence:
          - data:
              color_temp: 366
              entity_id:
                - light.group_masterbed
            service: light.turn_on
      - conditions:
          - condition: template
            value_template: "{{ (target_room == 'livingroom') and (mood == 'cozy') }}"
        sequence:
          - data:
              entity_id: light.group_livingroom
              hs_color:
                - 268.267
                - 88.235
            service: light.turn_on
      - conditions:
          - condition: template
            value_template: "{{ (target_room == 'livingroom') and (mood == 'white') }}"
        sequence:
          - service: light.turn_on
            data:
              color_temp: 223
            target:
              entity_id:
                - light.group_livingroom
mode: parallel
fields:
  mood:
    description: Type of light mood
    example: cozy
    required: true
  target_room:
    description: Physical space to apply the effect
    example: masterbed
    required: true
max: 10
raw hornet
#
          service: script.lights_mood
          service_data:
            mood: cozy
            target_room: livingroom

I believe the proper key is data and not service_data ?

rocky holly
#

changed service_data: to data:, this is what's returned from traces (same as every other attempt)

this:
  entity_id: script.lights_mood
  state: 'off'
  attributes:
    last_triggered: '2024-02-15T00:35:11.281645+00:00'
    mode: parallel
    current: 0
    max: 10
    friendly_name: Lights Moods (Cozy/White)
  last_changed: '2024-02-15T00:35:11.283613+00:00'
  last_updated: '2024-02-15T00:35:11.283613+00:00'
  context:
    id: 01HPN30NSH2WWCHCRGY9BEZQ2B
    parent_id: null
    user_id: f7c6046225fa4620b80f37c1d0dd17f9
context:
  id: 01HPN30PNZD112ZJDW3MK170VY
  parent_id: null
  user_id: f7c6046225fa4620b80f37c1d0dd17f9

I think I should be seeing the two variables mood and target_room, if they were passed successfully from the frontend

#

Forums say
In tap_action, replace: data: with service_data: From the documentation: service_data string (Optional, default: none) Service data to include (e.g., entity_id: media_player.bedroom) when action defined as call-service

raw hornet
#

What else does the trace show? No conditions of the choose were satisfied?

rocky holly
#

Correct, just bypassed all the options

raw hornet
#

so your tap action looks fine to me. I just tried and its working fine.

this:
  entity_id: script.lights_mood
  state: 'off'
  attributes:
    last_triggered: null
    mode: parallel
    current: 0
    max: 10
    friendly_name: Lights Moods (Cozy/White)
  last_changed: '2024-02-15T01:40:08.188103+00:00'
  last_updated: '2024-02-15T01:40:08.188103+00:00'
  context:
    id: 01HPN6QKBWJHEYSGAYZEYXETK5
    parent_id: null
    user_id: null
mood: cozy
target_room: livingroom
context:
  id: 01HPN6SNVC2AE929CHW2A2AYK5
  parent_id: null
  user_id: f4e7321cdf6145c9b7a2e615a5487d1a
#

I don't understand your full lovelace though.

rocky holly
#

I can paste the entire card, if that helps

raw hornet
#

what is entities under entities: ?

#

I did this with a button card and it works:

type: button
icon_height: 20px
name: Cozy lights
show_icon: false
show_name: true
tap_action:
  action: call-service
  service: script.1707961110263
  service_data:
    mood: cozy
    target_room: livingroom
rocky holly
#

ahh, so I guess it's the 'entities' card that doesnt pass the variables

raw hornet
#

your code doesn't look like an entities card either

rocky holly
raw hornet
#
entities:
  - entities:

this is not a valid thing

#
type: entities
entities:
  - entity: sensor.random_d20
    tap_action:
      action: call-service
      service: script.1707961110263
      service_data:
        mood: cozy
        target_room: livingroom

This is what an entities card should look like

#

and this works fine for service_data as well

raw hornet
#

ok all this custom/decluttering stuff I'm not going to comment on. if you just used a regular button or entities card it would work. I can't comment on whatever that custom stuff is doing.

rocky holly
#

Roger, understood. I'll have to either use a normal card or do some reading up on custom cards