How to use input_select or input_text in automation service? (Error about malformed message)

Hi,

I"m trying to port the following ZHA template to Zigbee2MQTT:

One of the features in the script is that it uses a input_text to store the current light as a variable - which you can then dim using the Phillips Hue dial.

I’ve created an input_text helper, and I’m able to set this successfully to the current light using the input_text.set service.

(I also tested using an input_select, which also seems to working - I’m still not sure of the pros/cons of an input_text vs input_select. I assume it’s mainly around validating input, right?).

However, when I try to use the value in an automation, it doesn’t work.

Originally, I had:

    remote_dial_rotate_right_step:
      - service: light.turn_on
        data:
          brightness_step_pct: 5
        target:
          entity_id: {{ lights[states(input_text.hue_dial_1_input_text)] }}

which didn’t seem to do anything. I figured it was because it was trying to cal the literal string input_text.hue_dial_1_input_text.

I then tried:

entity_id: {{ lights[states(input_text.hue_dial_1_input_text)] }}

However, when I try to save this YAML in the Automation Editor, it gives me an error:

Message malformed: not a valid value for dictionary value @ data['action'][1]['choose'][16]['sequence'][0]['target']['entity_id']

Does anybody know the correct syntax to call the actual light stored in the input_select, and use it in a lights.turn_on service?

Also, should I be storing ligths.hallway_lights, or is there some way to store hallway_lights, and prepend lights. to the string?

Thanks,
Victor

target:
  entity_id: "{{ states('input_text.hue_dial_1_input_text') }}"

Thanks for the quick response - I’m not getting a syntax error message when saving now =).

However, turning the dial doesn’t actually seem to change the brightness - nothing appears to happen, and if I check the HA Logbook, I do see the events for the Hue dial turning - but nothing to do with light brightness.

Here is my full automation YAML with your changes, in case I’ve done something silly or mangled it:

alias: >-
  Zigbee2MQTT - Philips Hue Tap dial switch (8719514440937/8719514440999)
  actions
description: ""
use_blueprint:
  path: freakshock88/philips_hue_tap_dial_switch_zigbee2mqtt_actions_blueprint.yaml
  input:
    button_sensor: sensor.hue_tap_dial_1_action
    remote_button_1_single_press:
      - service: light.toggle
        data: {}
        target:
          area_id: hallway
      - service: input_select.select_option
        data:
          option: hallway
        target:
          entity_id: input_select.hue_dial_1_last_light
      - service: input_text.set_value
        data:
          value: lights.hallway_lights
        target:
          entity_id: input_text.hue_dial_1_input_text
    remote_button_2_single_press:
      - service: light.toggle
        data: {}
        target:
          area_id: kitchen
      - service: input_select.select_option
        data:
          option: kitchen
        target:
          entity_id: input_select.hue_dial_1_last_light
      - service: input_text.set_value
        data:
          value: lights.kitchen_lights
        target:
          entity_id: input_text.hue_dial_1_input_text
    remote_button_4_single_press:
      - service: light.toggle
        data: {}
        target:
          area_id: living_room
      - service: input_select.select_option
        data:
          option: living_room
        target:
          entity_id: input_select.hue_dial_1_last_light
      - service: input_text.set_value
        data:
          value: lights.living_room_lights
        target:
          entity_id: input_text.hue_dial_1_input_text
    remote_button_3_single_press:
      - service: light.toggle
        data: {}
        target:
          area_id: dining
      - service: input_select.select_option
        data:
          option: dining_room
        target:
          entity_id: input_select.hue_dial_1_last_light
      - service: input_text.set_value
        data:
          value: lights.dining_room_lights
        target:
          entity_id: input_text.hue_dial_1_input_text
    remote_dial_rotate_left_slow:
      - service: light.turn_on
        data:
          brightness_step_pct: -10
        target:
          entity_id: "{{ states('input_text.hue_dial_1_input_text') }}"
    remote_dial_rotate_left_step:
      - service: light.turn_on
        data:
          brightness_step_pct: -5
        target:
          entity_id: "{{ states('input_text.hue_dial_1_input_text') }}"
    remote_dial_rotate_right_step:
      - service: light.turn_on
        data:
          brightness_step_pct: 5
        target:
          entity_id: "{{ states('input_text.hue_dial_1_input_text') }}"
    remote_dial_rotate_left_fast:
      - service: light.turn_on
        data:
          brightness_step_pct: -20
        target:
          entity_id: "{{ states('input_text.hue_dial_1_input_text') }}"
    remote_dial_rotate_right_slow:
      - service: light.turn_on
        data:
          brightness_step_pct: 9
        target:
          entity_id: "{{ states('input_text.hue_dial_1_input_text') }}"
    remote_dial_rotate_right_fast:
      - service: light.turn_on
        data:
          brightness_step_pct: 20
        target:
          entity_id: "{{ states('input_text.hue_dial_1_input_text') }}"

(The blueprint it refers to is here - Here is the blueprint my automation refers to - philips_hue_tap_dial_switch_zigbee2mqtt_actions_blueprint · GitHub).

I have a helper, input_text.hue_dial_1_input_text, which has values like lights.dining_room_lights.

Do you have any idea why the light brightness part might not be working?

(If I hardcode it to a light string - e.g. lights.kitchen_lights, the brightness setting does work).

Thanks,
Victor

When using a template to populate a target, I’ve always skipped using entity_id and that has worked for me. So instead of

        target:
          entity_id: "{{ states('input_text.hue_dial_1_input_text') }}"

I would use

        target: "{{ states('input_text.hue_dial_1_input_text') }}"

Don’t know if that will work for you or not, but that’s what I’ve always done.