Set log level using an automation for more than 1 component and back to default again

Continuing the discussion from WTH can I not change log verbosity from the UI:

which was prematurely closed (why cant we further broaden our minds/suggestions, even if a supposed current technique provides a workaround for the original Post? this is WTH after all??

anyways:

please help me set this data_template right:

  - alias: Set Debug Level
    id: Set Debug Level
    trigger:
      platform: state
      entity_id: input_boolean.debug_level
    action:
      service: logger.set_level
      data_template: >
        {% if trigger.to_state.state == 'on' %}
          {'homeassistant.core': 'info',
           'homeassistant.components.script': 'debug',
           'homeassistant.components.automation': 'debug'}
        {% else %}
          {'homeassistant.core': 'error',
           'homeassistant.components.script': 'error',
           'homeassistant.components.automation': 'error'}
        {% endif %}

which now errors with

     Invalid config for [automation]: expected a dictionary for dictionary value @ data['action'][0]['data_template']. Got None. (See ?, line ?). 

thanks for having a look

Shouldn’t you be using an input_boolean instead of input_select helper?

ha, you’re right there. was a C&P error from my log selector. I’ve edited the first post. thanks

but that doesn’t help here, the template isnt correct.

this is what I want to do:

  - alias: Set Debug Level on
    id: Set Debug Level on
    trigger:
      platform: state
      entity_id: input_boolean.debug_level
      to: 'on'
    condition:
      condition: template
      value_template: >
        {{trigger.to_state is not none and
          trigger.from_state is not none and
          trigger.to_state.state != trigger.from_state.state}}
    action:
      service: logger.set_level
      data:
        homeassistant.core: info
        homeassistant.components.script: debug
        homeassistant.components.automation: debug

  - alias: Set Debug Level off
    id: Set Debug Level 0ff
    trigger:
      platform: state
      entity_id: input_boolean.debug_level
      to: 'off'
    condition:
      condition: template
      value_template: >
        {{trigger.to_state is not none and
          trigger.from_state is not none and
          trigger.to_state.state != trigger.from_state.state}}
    action:
      service: logger.set_level
      data:
        homeassistant.core: error
        homeassistant.components.script: error
        homeassistant.components.automation: error

but then in 1 automation based on the {{trigger.to_state.state}}