Formating issue - data template in automation

Hi all,

can someone tell me what is wrong with this format?

service: remote.send_command
data_template:
  entity_id: remote.nz8_improved
  command: |-
    {% if is_state('input_select.nz8_picturemode', 'FrameAdapt HDR 1') %}
      picture_mode,frame_adapt_hdr1
    {% if is_state('input_select.nz8_picturemode', 'Frame Adapt HDR (middle)') %}
      picture_mode,frame_adapt_hdr2
    {% elif is_state('input_select.nz8_picturemode', '2D SDR') %}
      picture_mode,natural
    {% elif is_state('input_select.nz8_picturemode', '3D') %}
      picture_mode,user1
    {% elif is_state('input_select.nz8_picturemode', 'MadVR SDR') %}
      picture_mode,user2
    {% elif is_state('input_select.nz8_picturemode', 'Game SDR') %}
      picture_mode,user3
    {% elif is_state('input_select.nz8_picturemode', 'Game Frame Adapt HDR
    (high)') %}
      picture_mode,frame_adapt_hdr3
    {% endif %}

This seems to be workin though:

    {% if is_state('input_select.nz8_picturemode', 'FrameAdapt HDR 1') %}
      picture_mode,frame_adapt_hdr1

BR and thanks very much!

Please describe what’s not working.

It does not even let me save the automation:

So i think its a formation issue with these parts: picture_mode,frame_adapt_hdr1

Thanks, yes, you’re in a unquie situation where a normal template will not work because it will asign that value to a list.

The only way to get around this is by templating the entire data field.


service: remote.send_command
data:
  {% set options = {
    'FrameAdapt HDR 1': 'frame_adapt_hdr1',
    'Frame Adapt HDR (middle)': 'frame_adapt_hdr2',
    'Game Frame Adapt HDR (high)': 'frame_adapt_hdr3',
    '2D SDR': 'natural',
    '3D': 'user1',
    'MadVR SDR': 'user2',
    'Game SDR': 'user3',
    } %}
  {{ {
        'entity_id': 'remote.nz8_improved',
        'command': 'picture_mode,' ~ options.get(states('input_select.nz8_picturemode'), 'picture_mode,frame_adapt_hdr1'
     } }}

Oh ok … i will check that out :slight_smile: Hope i can get that resolved. Thank you very much so far!

Seems it does not let me save the automation at all using this without any error…
Got one now:

Missing a close bracket on the 'command' value in the template.

Hm right but still the same…

Can you tell me what the last part of this is doing exactly as it looks static to me:

‘command’: ‘picture_mode,’ ~ options.get(states(‘input_select.nz8_picturemode’), ‘picture_mode,frame_adapt_hdr1’)

So options.get seems to be clear but this part

, ‘picture_mode,frame_adapt_hdr1’)

does seem to be static right ?

Got it working but funny is its working the way i was initially doing it, i recreated the automation and suddenly was able to save it and it works just fine (so no formating error or whatsoever):

alias: Kino - NZ8 Change Picture Mode (improved)
description: ""
trigger:
  - platform: state
    entity_id:
      - input_select.nz8_picturemode
condition:
  - condition: state
    entity_id: remote.nz8_improved
    state: "on"
action:
  - service: remote.send_command
    data_template:
      entity_id: remote.nz8_improved
      command: >-
        {% if is_state('input_select.nz8_picturemode', 'FrameAdapt HDR 1') %}
          picture_mode,frame_adapt_hdr
        {% elif is_state('input_select.nz8_picturemode', '2D SDR') %}
          picture_mode,natural
        {% elif is_state('input_select.nz8_picturemode', '3D') %}
          picture_mode,user1
        {% elif is_state('input_select.nz8_picturemode', 'MadVR SDR') %}
          picture_mode,user2
        {% elif is_state('input_select.nz8_picturemode', 'Game SDR') %}
          picture_mod,user3
        {% elif is_state('input_select.nz8_picturemode', 'Game Frame Adapt HDR
        (high)') %}
          picture_mode,frame_adapt_hdr3
        {% elif is_state('input_select.nz8_picturemode', 'Frame Adapt HDR
        (middle)') %}
          picture_mode,frame_adapt_hdr2
        {% endif %}
  - service: input_select.select_option
    data:
      option: Select Mode
    target:
      entity_id: input_select.nz8_picturemode
mode: single

Anyhow i would be interested in how the proposed solution would be working as it does look much more cleaner than mine :wink:

@petro’s solution uses the .get() method to look up a value from a dictionary with the option for a default value if the requested one is not found. Here it is in the Template Editor, following a quick and simple .get() example:

I’ve added the close bracket that was missing, and substituted '3D' for the input select state, as I don’t have that entity on my system.

The one remaining error is that the highlighted picture_mode, should be deleted, or an unknown value would return picture_mode,picture_mode,frame_adapt_hdr1.

I’ve no idea why it didn’t work for you: getting templates in via the UI is often tricky.

1 Like