Intent Script Conditional Data Fields

I’m having trouble getting an intent script to work with both Lights and Switches because of the extra data fields that my lights have. I’m using Snips to run an intent script to turn on my lights; some of which are z-wave switches and some of which are z-wave lights and LIFX lights. The switches are just on/off devices, but the lights have brightness as an available parameter. Currently, my script looks like this:

ActivateLightColor:
  speech:
    text: Turning {{ objectLocation | replace(" ", "_") }} on
  card:
    type: simple
    title: Turn object off
    content: Ask Home Assistant to turn {{ objectLocation | replace(" ", "_") }} on
  action:
    service_template: >
      {%- if objectLocation.lower() in ['testing', 'main'] -%}
        light.turn_on
      {%- else -%}
        homeassistant.turn_on
      {%- endif -%}
    data_template:
      entity_id: >
        {%- if objectLocation.lower() in ['kitchen', 'main', 'testing'] -%}
          light.
        {%- elif objectLocation.lower() in ['living room'] -%}
          group.
        {%- elif objectLocation.lower() in ['entry', 'porch'] -%}
          switch.
        {%- endif -%}
        {%- if objectLocation.lower() in ['kitchen'] -%}
          kitchen_lights
        {%- elif objectLocation.lower() in ['entry'] -%}
          entry_way_switch
        {%- elif objectLocation.lower() in ['testing'] -%}
          lifx_1
        {%- elif objectLocation.lower() in ['main'] -%}
          ge_14294_inwall_smart_dimmer_level
        {%- endif -%}
      color_name: {{ objectColor }}

The service template is working correctly and is letting me use the two services, but I can’t pass the color_name parameter to a switch. I’m not sure what the best way to tackle this is. I’d rather not have to set up different intents because all of the entities are (in reality) lights, so requiring the word switch to differentiate them will be troublesome for guests who don’t know which are which. So I’m looking for a way to structure an intent_script such that it checks the objectLocation against a list, if it’s not in the list, call homeassistant.turn_on with objectLocation as the entity_id; if it is in the list, call light.turn_on with the entity_id as well as the color_name and brightness parameters.

Does anyone know if this is possible?

Hi this is interesting for me as well.

intent_script:
  lightsTurnUp:
    actions:
      - service: light.turn_on
        data_template:
          entity_id: 'light.{{ house_room | replace(" ","_") }}'
          brightness: '{{states.light.living_room.attributes.brightness + 25 }}'
  lightsTurnDown:
    actions:
      - service: light.turn_on
        data_template:
          entity_id: 'light.{{ house_room | replace(" ","_") }}'
          brightness: '{{states.light.living_room.attributes.brightness - 25 }}'

doesn’t set the brightness either

By the way what does speech: and card. do?

1 Like

I’ve put this part of my work with home-assistant on the back-burner while I wait for the Matrix Voice microphone array to be released. Once I have that, I’ll get back to working on voice integration; but, for the time being, I don’t have any updates on this.

Regarding the speech and card:
the speech is supposed to broadcast a message saying that the device is turning off. I believe the default is to play it on all available media devices, but you can also specify one. I haven’t played around with that feature much. I don’t know what the card does. I re-purposed this script from another user’s config, and I haven’t gotten it to work properly. It doesn’t seem to break anything, so I’ve just left it alone.

Hi! No luck with a conditional color_name field?