Error on loading automations.yaml

template value should be a string for dictionary value @ data[‘action’][0][‘data_template’]. Got None.

I don’t know if Home Assistant got more particular about its automation structure after upgrading or what the deal is but this afternoon I changed an action from input_boolean.turn_on to input_boolean.turn_off and I’m now getting an error per the above whenever I reload automations.yaml. This happens when I comment out the revised automation as well. The error is not particularly useful since I have no idea which automations are causing it to give me an error - it references row 211 in my configuration.yaml, which seems to be the !include automations.yaml line. I also did make updates to one automation yesterday to follow best practices per a moderator’s suggestions and to fix a separate problem, but again, when I comment out that code I still get this error.

How can I troubleshoot and fix this issue? My automations.yaml is fairly lengthy (1800 lines or so).

Then the error is elsewhere.

From the little part of the error you supplied, it is the first action of one of your automations. The action is expecting a string result from a template but did not get one.

OK, thank you. Here’s the full error:

Logger: homeassistant.config
First occurred: February 10, 2022, 9:12:42 PM (11 occurrences)
Last logged: 4:52:06 PM

Invalid config for [automation]: template value should be a string for dictionary value @ data[‘action’][0][‘data_template’]. Got None. (See /config/configuration.yaml, line 211).

I guess from ‘first occurred’ that this actually started happening last night and I just didn’t notice the notification. I did go through and add paragraphs between all my automations since when I migrated to a new system it removed all the whitespace, and I think I tweaked one automation when I did that, but I can’t remember which one and what edit I made. Is there any way to make the logging more verbose so I know which automation causes the issue? Or maybe block comment in the file editor? Takes quite a while to add a # before every row of an automation, save, reload automations, then undo if that didn’t fix the problem. :slight_smile:

Have a look in your logbook (not system error log) and see what was happening around this time:

First occurred: February 10, 2022, 9:12:42 PM (11 occurrences)
Last logged: 4:52:06 PM

Which automation triggered?

Thanks - I remembered which one it was after digging through all the automations with data_template in them, commented out that code and turns out that was the culprit. I changed the line breaking behavior I think, but when I put the if/then statement on one line it’s still not working. I think I have a backup of the automations.yaml where I can find what my code was before, but in case you’re curious and feel compelled to correct my sloppy coding here’s the automation that’s giving me the problem:

- id: media_light_on
  alias: Turn the media room lights on when door opens
  - platform: state
    entity_id: binary_sensor.media_room_door_sensor_22
    to: 'on'
    condition: and
    - condition: state
      entity_id: light.media_room_light_94
      state: 'off'
  - service: light.turn_on
      entity_id: light.media_room_light_94
      brightness_pct: "{% if is_state(''input_select.media_room'', ''Occupied'') %} 10 {% else %} 100 {% endif %}"
  - service: light.turn_on
    entity_id: light.floor_led_3

No need to escape single quotes (with single quotes) if using double quotes outside the template. Also try it like this:

brightness_pct: "{{ 10 if is_state('input_select.media_room', 'Occupied') else 100 }}"

Fantastic, thanks! I saw in my old automation I was using single quotes instead of double quotes but with some weird line spacing, and for some reason last night I decided to make them double quotes when cleaning up the line spacing. But your solution is better, didn’t know you could write it that way. Interesting that it requires an else in an if statement but endif I guess must be optional then.

2022.2 introduced an immediate if format too (even shorter, but less easy to understand).

iif(condition, if_true, if_false, if_none)
brightness_pct: "{{ iif(is_state('input_select.media_room', 'Occupied'), 10, 100) }}"