Automation Service error

I continue to receive the following error and have no idea where the error is occurring.

Logger: homeassistant.config
Source: config.py:413
First occurred: 9:31:18 AM (8 occurrences)
Last logged: 11:00:33 AM

Invalid config for [automation]: must contain at least one of service, service_template. @ data[‘action’][0]. Got None. (See ?, line ?).

Below is the only automation I see that has a service template type…

- id: '1572100349280'
  alias: Sunrise
  trigger:
  - event: sunrise
    offset: +00:10:00
    platform: sun
  action:
  - service: >
      '{% if is_state ("weather.home", "sunny") %} light.turn_off {%endif%}'
    entity_id: light.living_room_shelf_lamp
  - service: light.lifx_set_state
    entity_id: light.office_desk_lamp
    data:
      brightness_pct: 100
  mode: single

It’s telling you that an automation is missing both service and service_template.

Ok. Shall I post my Automation.yaml herein, else I cannot figure out where I’m missing either.

The problem is caused by this template:

  - service: >
      '{% if is_state ("weather.home", "sunny") %} light.turn_off {%endif%}'

When the weather is sunny, the template produces “light.turn_off”. What happens if the weather is not sunny? The template produces nothing and that’s not an acceptable value for the service option.

Re-arrange the order of the two services and add a condition between them:

- id: '1572100349280'
  alias: Sunrise
  trigger:
  - event: sunrise
    offset: +00:10:00
    platform: sun
  action:
  - service: light.lifx_set_state
    entity_id: light.office_desk_lamp
    data:
      brightness_pct: 100
  - condition: state
    entity_id: weather.home
    state: 'sunny'
  - service: light.turn_off
    entity_id: light.living_room_shelf_lamp
  mode: single

At sunrise+10 minutes it will set the brightness of the desk lamp to 100% and then, only if it is sunny, it will also turn off the shelf lamp.

1 Like

Thank you for the rewrite, though I still receive that error.

You don’t find it odd that a redesigned automation produces the same error?

I changed the example’s entity names to match what I have in my home, triggered the automation manually, and it works perfectly (no error messages).

You need to double-check what you did because there’s nothing wrong with the revised automation.


EDIT

Is this the only automation you have that fails to provide service with a value or are there others?

1 Like

I removed automations one-by-one until I identified the culprit. What service/service_template may I be missing in this? This is weird as I’ve had this Automation for months.

- id: '1234567890'
  alias: IFTTT received
  trigger:
  - event_data:
      action: call_service
    event_type: ifttt_webhook_received
    platform: event
  action:
  - data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'
  - service: '{{ trigger.event.data.service }}'

This strikes me as being peculiar:

  action:
  - data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'
  - service: '{{ trigger.event.data.service }}'

See the two hyphens? That’s two separate actions. The first one has no service and the second one has no entity_id.

It should be a single action like this:

  action:
  - service_template: '{{ trigger.event.data.service }}'
    data_template:
      entity_id: '{{ trigger.event.data.entity_id }}'

EDIT

If you are using 0.116.X then you can leave out “_template” because it is no longer necessary.

  action:
  - service: '{{ trigger.event.data.service }}'
    data:
      entity_id: '{{ trigger.event.data.entity_id }}'

Perfect, thanks!!

1 Like