Keep getting error ... using a simple IF in Script

I am struggling to get this simple script working. I keep getting an error message:

missed comma between flow collection entries at line 47, column 9:
{% if states('sensor.maverick_tem …

'grate_status':
  alias: 
  sequence:
  - service: notify.alexa_media_doug_office
    data_template:
       {% if states('sensor.maverick_temp1') | float > 0 %}
       message: 'grill temperature is {{ states(''sensor.maverick_temp1'')
        }}'
       {% else %}
       {% endif %}
      target: media_player.doug_office
      data:
        type: tts 

I may have indent errors, but the error message I’m getting is completely confusing…

Ultimately this will be a list of if’s…

Can anyone help…

That’s because you have the “if” in the wrong place. And you didn’t use the yaml “multi-line” indicator (>). And you have nothing in the “else” section.

Should be:

- service: notify.alexa_media_doug_office
  data_template:
    message: >
      {% if states('sensor.maverick_temp1') | float > 0 %}
        'grill temperature is {{ states(''sensor.maverick_temp1'') }}'
      {% else %}
        'Something else here'
      {% endif %}
    target: media_player.doug_office
    data:
      type: tts 

Unless you grill in the dead of winter, I’m trying to understand why you even need a test to confirm the grill temperature is greater than zero.

If it’s like my diy smoker sensor it will show 0 if the probe isn’t connected or if there is some other malfunction.

Does not work…

error msg:

Invalid config for [script]: invalid template (TemplateSyntaxError: expected token ',', got 'sensor') for dictionary value @ data['script']['grate_status']['sequence'][0]['data_template']['message']. Got "{% if states('sensor.maverick_temp1') | float > 0 %}\n  'grill temperature is {{ states(''sensor.maverick_temp1'') }}'\n{% else %}\n  'Something else here'\n{% endif %}\n". 

here is my script code…in case I made an error copying:

'grate_status':
  alias: speak maverick
  sequence:
  - service: notify.alexa_media_doug_office
    data_template:
      message: >
        {% if states('sensor.maverick_temp1') | float > 0 %}
          'grill temperature is {{ states(''sensor.maverick_temp1'') }}'
        {% else %}
          'Something else here'
        {% endif %}
      target: media_player.doug_office
      data:
        type: tts 

try removing all but the essential quotation marks:

grate_status:
  alias: speak maverick
  sequence:
    - service: notify.alexa_media_doug_office
      data_template:
        message: >
          {% if states('sensor.maverick_temp1') | float > 0 %}
            grill temperature is {{ states('sensor.maverick_temp1') }}
          {% else %}
            Something else here
          {% endif %}
        target: media_player.doug_office
        data:
          type: tts 

Success! Thank you!!!

1 Like